Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes, I realize this is a tad late, but this thread helped me, so I though I would pass it back up stream.</p> <p>I've expanded GWLlosa code a bit... I've also tried to comment generously. This lets you build your key sequence in code. For Narven, the sequence would be.</p> <pre><code> private static List&lt;List&lt;Keys&gt;&gt; command = new List&lt;List&lt;Keys&gt;&gt;{ new List&lt;Keys&gt;{Keys.Control | Keys.M}, new List&lt;Keys&gt;{Keys.M} }; </code></pre> <p>or</p> <pre><code> private static List&lt;List&lt;Keys&gt;&gt; command = new List&lt;List&lt;Keys&gt;&gt;{ new List&lt;Keys&gt;{Keys.Control | Keys.M}, new List&lt;Keys&gt;{Keys.Control | Keys.M} }; </code></pre> <p>depending on what he is trying to do.</p> <p>Full Code below.</p> <pre><code> // This defines the command sequence. In this case, "ctrl-m, ctrl-m, 1 or 2 or 3 or 4, A" private static List&lt;List&lt;Keys&gt;&gt; command = new List&lt;List&lt;Keys&gt;&gt;{ new List&lt;Keys&gt;{Keys.Control | Keys.M}, new List&lt;Keys&gt;{Keys.Control | Keys.M}, new List&lt;Keys&gt;{Keys.D1, Keys.D2, Keys.D3, Keys.D4 }, new List&lt;Keys&gt;{Keys.A} }; private static List&lt;Keys&gt; currentKeyStack = new List&lt;Keys&gt;(); private static DateTime lastUpdate = DateTime.Now; // See if key pressed within 750ms (0.75 sec) private static TimeSpan lengthOfTimeForChordStroke = new TimeSpan(0, 0, 0, 0, 750); protected static void ProcessCmdKey(Keys keyData) { // Merge Modifiers (Ctrl, Alt, etc.) and key (A, B, 1, 2, etc.) Keys keySequence = (Control.ModifierKeys | keyData); if ((TimeSpan)(DateTime.Now - lastUpdate) &gt; lengthOfTimeForChordStroke) { Console.WriteLine("Clear"); currentKeyStack.Clear(); } int index = currentKeyStack.Count(); Console.WriteLine("Index: " + index); Console.Write("Command: "); foreach (List&lt;Keys&gt; key in command) { foreach (Keys k in key) { Console.Write(" | " + k.ToString() + " (" + (int)k + ")"); } } Console.WriteLine(); Console.Write("Stack: "); foreach (Keys key in currentKeyStack) { Console.Write(" | " + key.ToString() + " (" + (int)key + ")"); } Console.WriteLine(); Console.WriteLine("Diff: " + (TimeSpan)(DateTime.Now - lastUpdate) + " length: " + lengthOfTimeForChordStroke); Console.WriteLine("#: " + index + "KeySeq: " + keySequence + " Int: " + (int)keySequence + " Key: " + keyData + " KeyInt: " + (int)keyData); // .Contains allows variable input, e.g Ctrl-M, Ctrl-M, 1 or 2 or 3 or 4 if (command[index].Contains(keySequence)) { Console.WriteLine("Added to Stack!"); currentKeyStack.Add(keySequence); } else { // Clear stack since input didn't match Console.WriteLine("Clear"); currentKeyStack.Clear(); } // When command sequence has been met if (currentKeyStack.Count == command.Count()) { // Do your thing here... Console.WriteLine("CAPTURED: " + currentKeyStack[2]); } // Reset LastUpdate Console.WriteLine("Reset LastUpdate"); lastUpdate = DateTime.Now; Console.WriteLine("\n"); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload