protected override bool Callback(CallbackData data) { var SW = System.Diagnostics.Stopwatch.StartNew(); var NewData = data.ToGlobalKeyboardEventSourceCallbackData(); //This call is required to work around a bug in Window's 'Get Keyboard State' API. When the bug occurs, it always returns the same keyboard state. KeyboardState.GetKeyState(KeyCode.None); var e = GetInputEventArgs(NewData.Message, NewData); var Input = e.Data; var Wait = new Wait(e.Timestamp - State.LastInputDate); State.LastInputDate = e.Timestamp; var KeyDown = Input.Status == KeyStatus.Pressed ? new KeyDown(e.Data.Key, e.Data.Extended) : null ; var KeyUp = Input.Status == KeyStatus.Released ? new KeyUp(e.Data.Key, e.Data.Extended) : null ; var TextClick = GetTextClick(NewData.Message, NewData); var KeyEvent = new KeyboardEvent(Wait, KeyDown, TextClick, KeyUp); var ret = InvokeMany(KeyEvent, NewData, e.Timestamp); Console.WriteLine(SW.Elapsed); return ret.Next_Hook_Enabled; }
/// <summary> /// Gets currently pressed modifier keys: left control, left shift, left alt or none /// </summary> /// <returns>Bit field of pressed keys</returns> private static ModifierKeys GetModifierKeys() { var modifierKeys = ModifierKeys.None; if (KeyboardState.GetKeyState(KeyCode.LShift).HasFlag(KeyboardKeyState.KeyDown)) { modifierKeys |= ModifierKeys.Shift; } else if (KeyboardState.GetKeyState(KeyCode.LControl).HasFlag(KeyboardKeyState.KeyDown)) { modifierKeys |= ModifierKeys.Control; } else if (KeyboardState.GetKeyState(KeyCode.LAlt).HasFlag(KeyboardKeyState.KeyDown)) { modifierKeys |= ModifierKeys.Alt; } return(modifierKeys); }