private void FireKeyboardEvents() { // Check through each key in the key list foreach (Keys key in KeyList) { // Is the key currently down? if (CurrentKeyboardState.IsKeyDown(key)) { // Fire the OnKeyDown event OnKeyDown?.Invoke(this, new KeyboardEventArgs(key, CurrentKeyboardState, PrevKeyboardState)); } // Has the key been released? (Was down and is now up) if (PrevKeyboardState.IsKeyDown(key) && CurrentKeyboardState.IsKeyUp(key)) { OnKeyUp?.Invoke(this, new KeyboardEventArgs(key, CurrentKeyboardState, PrevKeyboardState)); } // Has the key been pressed? (Was up and is now down) if (PrevKeyboardState.IsKeyUp(key) && CurrentKeyboardState.IsKeyDown(key)) { OnKeyPressed?.Invoke(this, new KeyboardEventArgs(key, CurrentKeyboardState, PrevKeyboardState)); } } }
public override void OnInputEvent(DeviceInputEventArgs e) { if (e.DeviceType != Type) { return; } var inputEvent = e as KeyboardInputEventArgs; if (inputEvent.KeyboardEvent.KeyState == KeyState.Press) { if (!mThePressKeys.Contains(inputEvent.KeyboardEvent.KeyCode)) { mThePressKeys.Add(inputEvent.KeyboardEvent.KeyCode); mKeysStateDic[inputEvent.KeyboardEvent.KeyCode] = KeyState.Press; TriggerActionMapping((int)inputEvent.KeyboardEvent.KeyCode, KeyState.Press); OnKeyDown?.Invoke(this, inputEvent.KeyboardEvent); } } else { mKeysStateDic[inputEvent.KeyboardEvent.KeyCode] = KeyState.Release; mThePressKeys.Remove(inputEvent.KeyboardEvent.KeyCode); PulseEndAxisMapping((int)inputEvent.KeyboardEvent.KeyCode); TriggerActionMapping((int)inputEvent.KeyboardEvent.KeyCode, KeyState.Release); OnKeyUp?.Invoke(this, inputEvent.KeyboardEvent); } }
static public void InvokeOnKeyUp(OpenTK.Input.KeyboardKeyEventArgs e) { if (OnKeyUp != null) { OnKeyUp.Invoke(null, e); } }
private void Update() { if (!IsTracking) { return; } bool isKey = Input.GetKey(key); bool isKeyDown = Input.GetKeyDown(key); bool isKeyUp = Input.GetKeyUp(key); if (isKey) { OnKey?.Invoke(); } if (isKeyDown) { OnKeyDown?.Invoke(); } if (isKeyUp) { OnKeyUp?.Invoke(); } }
// Update is called once per frame void Update() { if (Input.anyKey) { foreach (KeyCode keyCode in Enum.GetValues(typeof(KeyCode))) { if (Input.GetKey(keyCode)) { OnKey?.Invoke(keyCode); break; } } } if (Input.anyKeyDown) { foreach (KeyCode keyCode in Enum.GetValues(typeof(KeyCode))) { if (Input.GetKey(keyCode)) { codes.Add(keyCode); OnKeyDown?.Invoke(keyCode); break; } } } foreach (KeyCode keyCode in codes) { if (Input.GetKeyUp(keyCode)) { OnKeyUp?.Invoke(keyCode); break; } } }
public Window(WindowConfig config) { _config = config; var opts = WindowOptions.DefaultVulkan; opts.WindowBorder = WindowBorder.Resizable; opts.Size = new Silk.NET.Maths.Vector2D <int>((int)config.Width, (int)config.Height); opts.Title = config.Title; opts.WindowState = config.Fullscreen ? WindowState.Fullscreen : WindowState.Normal; _window = Silk.NET.Windowing.Window.Create(opts); _window.Render += (time) => DrawFrame?.Invoke(time); _window.Initialize(); _input = _window.CreateInput(); var primaryKeyboard = _input.Keyboards.FirstOrDefault(); if (primaryKeyboard != null) { primaryKeyboard.KeyDown += (keyboard, key, code) => OnKeyDown?.Invoke(key); primaryKeyboard.KeyUp += (keyboard, key, code) => OnKeyUp?.Invoke(key); } for (int i = 0; i < _input.Mice.Count; i++) { _input.Mice[i].Cursor.CursorMode = config.CursorDisabled ? CursorMode.Disabled : CursorMode.Normal; _input.Mice[i].MouseMove += (mouse, pos) => OnCursorPosition?.Invoke(pos.X, pos.Y); _input.Mice[i].Scroll += (mouse, wheel) => OnScroll?.Invoke(wheel.X, wheel.Y); _input.Mice[i].MouseDown += (mouse, button) => OnMouseDown?.Invoke(button); _input.Mice[i].MouseUp += (mouse, button) => OnMouseUp?.Invoke(button); } }
/// <summary> /// keyhook callback happens. /// </summary> /// <param name="nCode">not sure</param> /// <param name="wParam">event</param> /// <param name="lParam">the key being pressed</param> /// <returns></returns> private IntPtr KbHookCallback(int nCode, IntPtr wParam, IntPtr lParam) { if (nCode < 0) { return(CallNextHookEx(_kbHookID, nCode, wParam, lParam)); } int vkCode = Marshal.ReadInt32(lParam); switch ((int)wParam) { case WM_KEYDOWN: case WM_SYSKEYDOWN: if (!_currentlyPressed.Contains(vkCode)) { _currentlyPressed.Add(vkCode); OnKeyDown?.Invoke(this, new KeyEventArgs(vkCode)); } break; case WM_KEYUP: case WM_SYSKEYUP: if (_currentlyPressed.Contains(vkCode)) { _currentlyPressed.Remove(vkCode); } OnKeyUp?.Invoke(this, new KeyEventArgs(vkCode)); break; } _hookTimeoutTimer.Stop(); _hookTimeoutTimer.Start(); return(CallNextHookEx(_kbHookID, nCode, wParam, lParam)); }
private IntPtr _Hook(int code, IntPtr wParam, IntPtr lParam) { if (code >= 0) { var kb = (NativeStructs.KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(NativeStructs.KBDLLHOOKSTRUCT)); if (kb.flags == NativeEnums.KBDLLHOOKSTRUCTFlags.LLKHF_DOWN || kb.flags == NativeEnums.KBDLLHOOKSTRUCTFlags.LLKHF_ALTDOWN || kb.flags == NativeEnums.KBDLLHOOKSTRUCTFlags.LLKHF_EXTENDED) { bool throwInput = false; OnKeyDown?.Invoke(this, (Keys)kb.vkCode, ref throwInput); if (throwInput) { //return new IntPtr(1); } } else { OnKeyUp?.Invoke(this, (Keys)kb.vkCode); } } return(NativeMethods.CallNextHookEx(mHookPtr, code, wParam, lParam)); }
public override void Tick() { for (int i = 0; i < mThePressKeys.Count; ++i) { //正常情况下用该用IsPlatformKeyDown 但是android的IsPlatformKeyDown 没有找到接口 if (!IsKeyDown(mThePressKeys[i])) { mTheReleaseKeys.Add(mThePressKeys[i]); } //else //{ // PulseAxisMapping((int)mThePressKeys[i]); //} } for (int i = 0; i < mTheReleaseKeys.Count; ++i) { mThePressKeys.Remove(mTheReleaseKeys[i]); mKeysStateDic[mTheReleaseKeys[i]] = KeyState.Release; var keyEvent = new KeyboardEventArgs(); keyEvent.KeyCode = mTheReleaseKeys[i]; keyEvent.KeyValue = (int)mTheReleaseKeys[i]; keyEvent.KeyState = KeyState.Release; keyEvent.Alt = IsPlatformKeyDown(Keys.Menu); keyEvent.Shift = IsPlatformKeyDown(Keys.ShiftKey); keyEvent.Control = IsPlatformKeyDown(Keys.ControlKey); //PulseEndAxisMapping((int)mTheReleaseKeys[i]); TriggerActionMapping((int)mTheReleaseKeys[i], KeyState.Release); OnKeyUp?.Invoke(this, keyEvent); } mTheReleaseKeys.Clear(); PulseAxisMapping(); }
private void InvokeEvents() { foreach (var key in Enum.GetValues(typeof(Keys)).Cast <Keys>()) { if (IsKeyDown(key)) { OnKeyDown?.Invoke(key); if (IsKeyPressed(key)) { OnKeyPressed?.Invoke(key); } if (IsKeyClicked(key)) { OnKeyClicked?.Invoke(key); } } else { OnKeyUp?.Invoke(key); if (IsKeyReleased(key)) { OnKeyReleased?.Invoke(key); } } } }
private void HookKeyboardCallback(HookData hookData) { KeyEventInformation info = KeyEventInformation.Get(hookData); Keys key = info.KeyCode | (info.Control ? Keys.Control : Keys.None) | (info.Shift ? Keys.Shift : Keys.None) | (info.Alt ? Keys.Alt : Keys.None); if (info.IsKeyDown) { m_KeyState[info.KeyCode] = true; OnKeyCombo?.Invoke(key); OnKeyDown?.Invoke(key); m_KeyboardDownHandlers.TryInvoke(key); } if (info.IsKeyUp) { m_KeyState[info.KeyCode] = false; OnKeyUp?.Invoke(key); m_KeyboardUpHandlers.TryInvoke(key); } }
internal static void DWindowOnKeyUp(object sender, KeyboardKeyEventArgs e) { DKey key = (DKey)e.Key; DModifiers modifiers = new DModifiers(e.Shift, e.Control, e.Alt); rootCanvas.OnKeyUp(key, modifiers); OnKeyUp?.Invoke(key, modifiers); }
private static void HandleKeyUp(RawKey key) { pressedKeys.Remove(key); if (OnKeyUp != null) { OnKeyUp.Invoke(key); } }
/// <summary> /// Occurs when a key is released. /// </summary> /// <param name="key">Key that was released</param> internal static void KeyUp(Key key) { while (Keys.Contains(key)) // Suboptimal { Keys.Remove(key); } OnKeyUp?.Invoke(key); }
private void _inputListener_OnKeyUp(object sender, KeyboardEventArgs e) { if (_keyUpCommands.ContainsKey(e.Key)) { _keyUpCommands[e.Key](e.GameTime); } // There is also a generic Key Up delegate mainly for detecting idleness OnKeyUp?.Invoke(sender, e); }
internal override void GHook_KeyUp(object sender, KeyEventArgs e) { if (!Loaded) { return; } OnKeyUp?.Invoke(sender, e); }
internal void InitKeyboardHandlers() { _keyboardHandler = new KeyboardHandler(); _keyboardHandler.OnKeyDown += (key) => OnKeyDown?.Invoke(key); _keyboardHandler.OnKeyUp += (key) => OnKeyUp?.Invoke(key); _keyboardHandler.OnKeyPressed += (key) => OnKeyPressed?.Invoke(key); _keyboardHandler.OnKeyClicked += (key) => OnKeyClicked?.Invoke(key); _keyboardHandler.OnKeyReleased += (key) => OnKeyReleased?.Invoke(key); }
private static unsafe void KeyCallback(WindowHandle *_, Keys key, int __, InputAction action, KeyModifiers ___) { if (action == InputAction.Press) { OnKeyDown?.Invoke(key); } else if (action == InputAction.Release) { OnKeyUp?.Invoke(key); } }
public static void InvokeKeyUp(object args) { string[] a = args.ToString().Replace("[", null).Replace("]", null).Split(","); bool ctrl = bool.Parse(a[1]); bool shift = bool.Parse(a[2]); bool alt = bool.Parse(a[3]); ConsoleKey consoleKey = (ConsoleKey)Enum.Parse(typeof(ConsoleKey), a[0]); keyboardState = new BWHKeyboardState(consoleKey, ctrl, shift, alt, false); OnKeyUp?.Invoke(keyboardState); }
private IntPtr HookCallback(int nCode, WindowsMessages wParam, KBDLLHOOKSTRUCT lParam) { if (nCode >= 0 && wParam == WindowsMessages.WM_KEYDOWN || wParam == WindowsMessages.WM_SYSKEYDOWN) { OnKeyDown.Invoke(this, ((Keys)lParam.vkCode)); } else if (nCode >= 0 && wParam == WindowsMessages.WM_KEYUP || wParam == WindowsMessages.WM_SYSKEYUP) { OnKeyUp.Invoke(this, ((Keys)lParam.vkCode)); } return(User.CallNextHookEx(_hookID, nCode, wParam, lParam)); }
private IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam) { if (nCode >= 0) { int vkCode = Marshal.ReadInt32(lParam); // keep track of pressed keys so we don't intercept hotkeys if (wParam == (IntPtr)NativeMethods.WM.KEYDOWN || wParam == (IntPtr)NativeMethods.WM.SYSKEYDOWN) { if (!keysPressed.Contains(vkCode)) { keysPressed.Add(vkCode); } var kpa = new KeyEventArgs(KeyInterop.KeyFromVirtualKey(vkCode)); OnKeyDown?.Invoke(this, kpa); if (kpa.Handled) { return(new IntPtr(1)); } } // act only when key is raised if (wParam == (IntPtr)NativeMethods.WM.KEYUP || wParam == (IntPtr)NativeMethods.WM.SYSKEYUP) { // if more than one key was pressed before a key was raised, user attempted hotkey if (keysPressed.Count == 1 && OnKeyPressed != null) { var kpaPressed = new KeyEventArgs(KeyInterop.KeyFromVirtualKey(vkCode)); OnKeyPressed?.Invoke(this, kpaPressed); if (kpaPressed.Handled) { return(new IntPtr(1)); } } // reset pressed keys keysPressed.Clear(); var kpaUp = new KeyEventArgs(KeyInterop.KeyFromVirtualKey(vkCode)); OnKeyUp?.Invoke(this, kpaUp); if (kpaUp.Handled) { return(new IntPtr(1)); } } } return(CallNextHookEx(_hookID, nCode, wParam, lParam)); }
protected override void Hook(ref Message m) { switch (m.msg) { case Wm.KeyDown: { long tick = DateTime.Now.Ticks; Keys key = GetKey(m.wparam); OnKeyDown?.Invoke(key); #if WINDOWS_XNA if (form.CanFocus) { _TranslateMessage(ref m); } #endif } break; case Wm.KeyUp: { long tick = DateTime.Now.Ticks; Keys key = GetKey(m.wparam); OnKeyUp?.Invoke(key); } break; case Wm.Char: { char c = (char)m.wparam; if (c < (char)0x20 && c != '\n' && c != '\r' //&& c != '\t'//tab //uncomment to accept tab && c != '\b') //backspace { break; } OnCharacter?.Invoke(c); } break; } }
void sendEvent(KeyCode keycode, KeyboardEventType evType) { if (evType == KeyboardEventType.keyDown) { OnKey.Invoke(keycode); } if (evType == KeyboardEventType.KeyUp) { OnKeyUp.Invoke(keycode); } if (evType == KeyboardEventType.down) { OnKeyDown.Invoke(keycode); } }
private void FireKeyboardEvents(GameTime gameTime) { foreach (var key in _keyList) { if (CurrentKeyboardState.IsKeyDown(key)) { OnKeyDown?.Invoke(this, new KeyboardEventArgs(key, CurrentKeyboardState, PrevKeyboardState, gameTime)); } if (PrevKeyboardState.IsKeyDown(key) && CurrentKeyboardState.IsKeyUp(key)) { OnKeyUp?.Invoke(this, new KeyboardEventArgs(key, CurrentKeyboardState, PrevKeyboardState, gameTime)); } } }
public static int HookProc(int code, int wParam, ref KeyboardHookStruct lParam) { if (code >= 0) { if ((wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN)) { OnKeyDown?.Invoke(null, lParam.vkCode); } else if ((wParam == WM_KEYUP || wParam == WM_SYSKEYUP)) { OnKeyUp?.Invoke(null, lParam.vkCode); } } return(CallNextHookEx(hhook, code, wParam, ref lParam)); }
private static void InputEventHandler(InputEventArgs e) { switch (e.Type) { case InputEventType.KeyUp: OnKeyUp.Invoke(e); break; case InputEventType.KeyDown: OnKeyDown.Invoke(e); break; case InputEventType.MouseUp: OnMouseUp.Invoke(e); break; case InputEventType.MouseDown: OnMouseDown.Invoke(e); break; case InputEventType.MouseMove: OnMouseMove.Invoke(e); break; } }
public override int HookProcEvent(int nCode, Int32 wParam, IntPtr lParam) { //如果正常运行并且用户要监听键盘的消息 if (nCode >= 0) { int vkCode = Marshal.ReadInt32(lParam); KeyEventArgs keyEventArgs = new KeyEventArgs(vkCode.ToString().ToEnum <Keys>()); switch (wParam) { case Const.WM_HOTKEY: // log.Add("WM_HOTKEY:" + vkCode.ToString().ToEnum<Keys>().ToString()); break; case Const.WM_KEYDOWN: case Const.WM_SYSKEYDOWN: // OnKeyDown?.Invoke(this, keyEventArgs); if (!iskeydown || keyEventArgs.KeyCode != lastkeydownKeys) { OnKeyDown?.Invoke(this, keyEventArgs); } else { if (iskeydown && keyEventArgs.KeyCode == lastkeydownKeys) { Keys[] keys = { Keys.LControlKey, Keys.RControlKey, Keys.ControlKey, Keys.LShiftKey, Keys.RShiftKey, Keys.ShiftKey, Keys.LMenu, Keys.RMenu, Keys.Alt, }; if (!keys.ToList().Contains(keyEventArgs.KeyCode)) { OnKeyDown?.Invoke(this, keyEventArgs); } } } iskeydown = true; lastkeydownKeys = keyEventArgs.KeyCode; break; case Const.WM_KEYUP: case Const.WM_SYSKEYUP: OnKeyUp?.Invoke(this, keyEventArgs); iskeydown = false; lastkeydownKeys = Keys.None; break; } } return(CallNextHookEx(hwndHook, nCode, wParam, lParam)); }
private KeyLogg() { Application.ThreadExit += (source, e) => { tokenSrc.Cancel(); }; Task.Run(() => { hookID = SetHook((nCode, wParam, lParam) => { if (nCode >= 0) { var eventType = (int)wParam; var eventData = new KeyboardEventArgs() { Key = ((KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(KBDLLHOOKSTRUCT))).vkCode, ModifierKeys = Control.ModifierKeys }; switch (eventType) { case WM_KEYDOWN: OnKeyDown?.Invoke(this, eventData); break; case WM_KEYUP: OnKeyUp?.Invoke(this, eventData); break; case WM_SYSKEYDOWN: OnSysKeyDown?.Invoke(this, eventData); break; case WM_SYSKEYUP: OnSysKeyUp?.Invoke(this, eventData); break; } } return(CallNextHookEx(hookID, nCode, wParam, lParam)); }); Application.Run(); Application.ApplicationExit += (src, e) => { UnhookWindowsHookEx(hookID); }; }, tokenSrc.Token); }
private IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam) { if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN || wParam == (IntPtr)WM_SYSKEYDOWN) { int vkCode = Marshal.ReadInt32(lParam); OnKeyDown?.Invoke(this, new KeyDownArgs(KeyInterop.KeyFromVirtualKey(vkCode))); } else if (nCode >= 0 && wParam == (IntPtr)WM_KEYUP || wParam == (IntPtr)WM_SYSKEYDOWN) { int vkCode = Marshal.ReadInt32(lParam); OnKeyUp?.Invoke(this, new KeyUpArgs(KeyInterop.KeyFromVirtualKey(vkCode))); } return(CallNextHookEx(_hookID, nCode, wParam, lParam)); }
//////////////////////////////////////////////////////////////////////////////////////////////////// private IntPtr KeyboardHookProc(int nCode, IntPtr wParam, IntPtr lParam) { if (nCode >= 0) { KeyboardHookStruct kbStruct = (KeyboardHookStruct)Marshal.PtrToStructure(lParam, typeof(KeyboardHookStruct)); if (wParam == (IntPtr)WM_KEYDOWN) { OnKeyDown?.Invoke(null, new KeyEventArgs((Keys)kbStruct.VirtualKeyCode)); } else if (wParam == (IntPtr)WM_KEYUP) { OnKeyUp?.Invoke(null, new KeyEventArgs((Keys)kbStruct.VirtualKeyCode)); } } return(CallNextHookEx(_hookHandle, nCode, wParam, lParam)); }