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 void handler(IHTMLEventObj e) { if (!OnKeyUp.IsNull()) { OnKeyUp(this, new IControlHtmlKeyDownEventArgs(e, spanElement)); } }
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); } } } }
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); } }
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(); }
static public void InvokeOnKeyUp(OpenTK.Input.KeyboardKeyEventArgs e) { if (OnKeyUp != null) { OnKeyUp.Invoke(null, e); } }
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); } }
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)); } } }
// 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; } } }
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(); } }
/// <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)); }
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); } }
protected void InterceptKeyUp(KeyboardEventArgs obj) { if (Disabled || ReadOnly) { return; } switch (obj.Key) { case "ArrowUp": if (RuntimeLocation.IsServerSide) { _elementReference?.ForceRender(forceTextUpdate: true); } break; case "ArrowDown": if (RuntimeLocation.IsServerSide) { _elementReference?.ForceRender(forceTextUpdate: true); } break; } _keyDownPreventDefault = false; StateHasChanged(); OnKeyUp.InvokeAsync(obj).AndForget(); }
/// <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 static void HandleKeyUp(RawKey key) { pressedKeys.Remove(key); if (OnKeyUp != null) { OnKeyUp.Invoke(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); }
protected Task HandleKeyUp(KeyboardEventArgs obj) { if (Disabled || ReadOnly) { return(Task.CompletedTask); } OnKeyUp.InvokeAsync(obj).AndForget(); return(Task.CompletedTask); }
public static void SetHook(OnKeyDown handleKeyDown, OnKeyUp handleKeyUp) { EventKeyDown = handleKeyDown; EventKeyUp = handleKeyUp; IntPtr hInstance = LoadLibrary("User32"); hhook = SetWindowsHookEx(WH_KEYBOARD_LL, _proc, hInstance, 0); }
/// <summary> /// Adds a handler for mouse button input. /// </summary> public static void AddInputHandler( DeviceType dt, MouseButton mouseButton, OnKeyDown onDown, OnKeyHeld onHeld, OnKeyUp onUp) { keyInfos.Add(new KeyInfo(dt, mouseButton, onDown, onHeld, onUp)); }
/// <summary> /// Adds a handler for joystick axis input. /// </summary> public static void AddInputHandler( DeviceType dt, OVRGamepadController.Axis axis, OnKeyDown onDown, OnKeyHeld onHeld, OnKeyUp onUp) { keyInfos.Add(new KeyInfo(dt, axis, onDown, onHeld, onUp)); }
/// <summary> /// Adds a handler for key input /// </summary> public static void AddInputHandler( DeviceType dt, string keyName, OnKeyDown onDown, OnKeyHeld onHeld, OnKeyUp onUp) { keyInfos.Add(new KeyInfo(dt, keyName, onDown, onHeld, onUp)); }
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); }
internal override void GHook_KeyUp(object sender, KeyEventArgs e) { if (!Loaded) { return; } OnKeyUp?.Invoke(sender, e); }
//====================== // AddInputHandler // Adds a hander for key input //====================== public static void AddInputHandler(eDeviceType dt, string keyName, OnKeyDown onDown, OnKeyHeld onHeld, OnKeyUp onUp, int joystickNum = 0, bool exc = false) { KeyInfo k = new KeyInfo(dt, keyName, onDown, onHeld, onUp); k.WasDown = Input.GetKey(keyName); k.exclusive = exc; InputMap[joystickNum].KeyInfos.Add(k); }
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); }
//====================== // AddInputHandler // Adds a hander for mouse button input //====================== public static void AddInputHandler(eDeviceType dt, eMouseButton mouseButton, OnKeyDown onDown, OnKeyHeld onHeld, OnKeyUp onUp, int joystickNum = 0, bool exc = false) { KeyInfo k = new KeyInfo(dt, mouseButton, onDown, onHeld, onUp); k.WasDown = GetMouseButton(mouseButton); k.exclusive = exc; InputMap[joystickNum].KeyInfos.Add(k); }
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); } }
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)); }
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); }
/// <summary> /// Overrides KeyUp event, if needed reset <see cref="_keyDownPreventDefault"/> set by <see cref="InterceptArrowKey(KeyboardEventArgs)"/>. /// </summary> protected void InterceptKeyUp(KeyboardEventArgs obj) { if (Disabled || ReadOnly) { return; } if (_keyDownPreventDefault != KeyDownPreventDefault) { _keyDownPreventDefault = KeyDownPreventDefault; StateHasChanged(); } OnKeyUp.InvokeAsync(obj).AndForget(); }
// key constructor public KeyInfo( eDeviceType inDeviceType, string inKeyName, OnKeyDown inDownHandler, OnKeyHeld inHeldHandler, OnKeyUp inUpHandler ) { DeviceType = inDeviceType; KeyName = inKeyName; MouseButton = eMouseButton.None; JoystickButton = OVRGamepadController.Button.None; JoystickAxis = OVRGamepadController.Axis.None; Threshold = 1000.0f; WasDown = false; DownHandler = inDownHandler; HeldHandler = inHeldHandler; UpHandler = inUpHandler; }
/// <summary> /// Joystick axis constructor. /// </summary> public KeyInfo( DeviceType inDeviceType, OVRGamepadController.Axis inJoystickAxis, OnKeyDown inDownHandler, OnKeyHeld inHeldHandler, OnKeyUp inUpHandler) { deviceType = inDeviceType; keyName = OVRGamepadController.AxisNames[(int)inJoystickAxis]; mouseButton = MouseButton.None; joystickButton = OVRGamepadController.Button.None; joystickAxis = inJoystickAxis; threshold = 0.5f; wasDown = false; downHandler = inDownHandler; heldHandler = inHeldHandler; upHandler = inUpHandler; }
/// <summary> /// Mouse button constructor. /// </summary> public KeyInfo( DeviceType inDeviceType, MouseButton inMouseButton, OnKeyDown inDownHandler, OnKeyHeld inHeldHandler, OnKeyUp inUpHandler) { deviceType = inDeviceType; keyName = "Mouse Button " + (int)inMouseButton; mouseButton = inMouseButton; joystickButton = OVRGamepadController.Button.None; joystickAxis = OVRGamepadController.Axis.None; threshold = 1000.0f; wasDown = false; downHandler = inDownHandler; heldHandler = inHeldHandler; upHandler = inUpHandler; }
//====================== // AddInputHandler // Adds a hander for joystick button input //====================== public static void AddInputHandler( eDeviceType dt, OVRGamepadController.Button joystickButton, OnKeyDown onDown, OnKeyHeld onHeld, OnKeyUp onUp ) { KeyInfos.Add( new KeyInfo( dt, joystickButton, onDown, onHeld, onUp ) ); }
// joystick axis constructor public KeyInfo( eDeviceType inDeviceType, OVRGamepadController.Axis inJoystickAxis, OnKeyDown inDownHandler, OnKeyHeld inHeldHandler, OnKeyUp inUpHandler ) { DeviceType = inDeviceType; KeyName = OVRGamepadController.AxisNames[(int)inJoystickAxis]; MouseButton = eMouseButton.None; JoystickButton = OVRGamepadController.Button.None; JoystickAxis = inJoystickAxis; Threshold = 0.5f; WasDown = false; DownHandler = inDownHandler; HeldHandler = inHeldHandler; UpHandler = inUpHandler; }