static Random rand = new Random(); //reuse this if you are generating many private bool _keyUp(Hooker.KeyboardHookStruct arg) { int vk = arg.VirtualKeyCode; bool passKey = _processKeyUp(vk, arg.IsInjected); if (!arg.IsInjected && vk == lastVk) { lastVk = -1; prevMacroVk = -1; } if (passKey) { RegisterKeyUp(vk); // Prevent impossibly fast keystrokes! if (lastEvt.ElapsedMilliseconds <= 3) { //System.Diagnostics.Debug.WriteLine("delay key up for " + Macro.GetKeyString(vk, ModifierKey.None) + ": " + passKey.ToString().ToUpper()); // Now, this used to be an issue when events would be stacked up due to being blocked. Now it's not the case... AccurateTimer.AccurateSleep(5); } lastEvt.Restart(); } //System.Diagnostics.Debug.WriteLine("pass key up for " + Macro.GetKeyString(vk, ModifierKey.None) + ": " + passKey.ToString().ToUpper()); return(passKey); }
void DispInfo(Hooker.KeyboardHookStruct arg) { int vk = arg.VirtualKeyCode; label1.Text = "Virtual key code: " + vk + " [" + ((Keys)vk).ToString() + "]\r\n" + "Scan code: " + arg.ScanCode + " (" + InputBuilder.MapVirtualKey((uint)arg.VirtualKeyCode, InputBuilder.MapVirtualKeyMapTypes.MAPVK_VK_TO_VSC).ToString() + ")\r\n" + "Flags: " + Convert.ToString(arg.Flags, 2).PadLeft(8, '0') + "\r\n" + " Extended Key: " + arg.IsExtendedKey.ToString() + "\r\n" + " Lower Injected: " + arg.IsLowerInjected.ToString() + "\r\n" + " Injected: " + arg.IsInjected.ToString() + "\r\n" + " Alt Down: " + arg.IsAltDown.ToString() + "\r\n" + " Key Up: " + arg.IsKeyUp.ToString() + "\r\n" + "Extra Info: " + Convert.ToString(arg.ExtraInfo, 2) + "\r\n"; //int pick = (int)Math.Min(Math.Floor(Math.Abs(GaussRandom(0, 1))), 2); //listView1.Items.Add(((Keys)vk).ToString() + " " +( arg.IsKeyUp? "up":"down") + " " + //pick + " " + GaussRandom(sleeps[pick][0],sleeps[pick][1])); // DEBUG }
private bool _keyDown(Hooker.KeyboardHookStruct arg) { int vk = arg.VirtualKeyCode; bool passKey = _processKeyDown(vk, arg.IsInjected, vk == lastVk); if (!arg.IsInjected && vk != lastVk) { lastVk = vk; } /* * BeginInvoke((MethodInvoker)delegate * { * Text = "last repeat : " + (lastVk == -1 ? "(none)" : Macro.GetKeyString(lastVk, ModifierKey.None)); * });*/ if (passKey) { RegisterKeyDown(vk); //In general, macro keys should clear the previously repeating key? // Prevent impossibly fast keystrokes! if (lastEvt.ElapsedMilliseconds <= 3) { //System.Diagnostics.Debug.WriteLine("delay key down for " + Macro.GetKeyString(vk, ModifierKey.None) + ": " + passKey.ToString().ToUpper()); AccurateTimer.AccurateSleep(4); } // If the keystroke was passed through, we restart the timer. lastEvt.Restart(); } //System.Diagnostics.Debug.WriteLine("pass key down for " + Macro.GetKeyString(vk, ModifierKey.None) + ": " + passKey.ToString().ToUpper()); return(passKey); }