protected void OnKeyPressed(int pinNumber) { if (KeyPressed != null) { KeyPressed.Invoke(pinNumber, new EventArgs()); } }
/// <summary> /// Get user input. /// IOleCommandTarget.Exec() function /// </summary> public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut) { int hr = VSConstants.S_OK; var x = new[] { 1, 4 }; if ((new[] { 4, // tab 7, // left arrow 11, // up arrow 9, // right arrow 13, // down arrow 103, // escape }).Contains((int)nCmdID)) { // send '\0' so we can abort KeyPressed?.Invoke(this, new KeyPressEventArgs('\0')); return(hr); } char typedChar; if (TryGetTypedChar(pguidCmdGroup, nCmdID, pvaIn, out typedChar)) { KeyPressed?.Invoke(this, new KeyPressEventArgs(typedChar)); return(hr); } hr = nextCommandHandler.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut); return(hr); }
public KeyboardHook() { _window.KeyPressed += delegate(object sender, KeyPressedEventArgs args) { KeyPressed?.Invoke(this, args); }; }
private void Key_0_Click(object sender, RoutedEventArgs e) { Button button = (Button)sender; string content = button.Content as string; if (this.Text == null) { this.Text = ""; } string key = content; if (key == "Delete") { if (this.Text.Length > 0) { this.Text = this.Text.Substring(0, this.Text.Length - 1); // 删除最后一位 } } else if (key == "Enter") { key = "\r"; } else { this.Text += key; } KeyPressed?.Invoke(this, new KeyPressedEventArgs { Key = key[0] }); }
public void StartDetector() { if (!IsKeyThreadRunning) { IsKeyThreadRunning = true; new Thread(() => { while (true) { for (int i = 0; i < KeysCodesToHandle.Count; i++) { VirtualKeyCode key = KeysCodesToHandle[i]; if (input.InputDeviceState.IsKeyDown(key)) { Task.Run(() => KeyDown?.Invoke(key)); } if (IsKeyPressed(input.InputDeviceState, key)) { Task.Run(() => KeyPressed?.Invoke(key)); } } Thread.Sleep(8); } }).Start(); } }
public override void PressesBegan(NSSet <UIPress> presses, UIPressesEvent evt) { base.PressesBegan(presses, evt); var pressesList = presses.ToArray().ToList(); var firstPress = pressesList.FirstOrDefault(); if (firstPress != null) { var keyCode = KeyCode.Unknown; switch (firstPress.Key.KeyCode) { case UIKeyboardHidUsage.KeyboardUpArrow: keyCode = KeyCode.UpArrow; break; case UIKeyboardHidUsage.KeyboardDownArrow: keyCode = KeyCode.DownArrow; break; } if (keyCode != KeyCode.Unknown) { KeyPressed?.Invoke(this, new KeyPressEventArgs(keyCode, firstPress.Key.Characters)); } } }
private void OnKeyPressed(object sender, Key key) { // add to our table of key pressed this frame keysPressed.Add(key); KeyPressed?.Invoke(sender, key); }
private KeyboardHook() { _callbacks = new Dictionary <HotKey, Action>(); _window = new Window(); // register the event of the inner native window. _window.KeyPressed += (key) => KeyPressed?.Invoke(key); }
/// <summary> /// Adds the specified mouse keycode to the list of pressed keys. /// </summary> /// <param name="keyCode">The keycode to add.</param> /// <param name="hold">The minimum time to hold keys.</param> public static void AddPressedElement(int keyCode, int hold) { lock (pressedKeys) { EnsureStopwatchRunning(); var time = keyHoldStopwatch.ElapsedMilliseconds; // Invoke the key pressed event asynchronously, since we don't want any slow subscribers to delay // updating the state. Task.Run(() => KeyPressed?.Invoke(keyCode, time)); TryToggleStateKey(keyCode, hold); if (pressedKeys.TryGetValue(keyCode, out var pressed)) { pressed.startTime = time; pressed.removed = false; pressedKeys[keyCode] = pressed; } else { pressedKeys.Add( keyCode, new KeyPress { startTime = keyHoldStopwatch.ElapsedMilliseconds, removed = false }); updated = true; } } }
/// <summary> /// Blocking function that should be called in a while loop. /// </summary> public void HandleEventLoop() { var character = Console.ReadKey(); var ev = new KeyPressEvent { Key = character, State = MakeApplicationState() }; KeyPressed?.Invoke(this, ev); if (ev.Cancel) { return; } ActiveComponent.HandleKeyPress(this, ev); if (ev.State.ActiveComponent != ActiveComponent) { ev.Rerender = Focus(ev.State.ActiveComponent) || ev.Rerender; } if (ev.Rerender) { Render(); } }
private void OnKeyDown(object sender, IKeyboardHookEventArgs e) { if (IsKeyPressed(e.Key)) { return; } var isModifier = false; if (_leftModifierMappings.TryGetValue(e.Key, out var modifier)) { _leftModifiers = _leftModifiers | modifier; Modifiers = Modifiers | _leftModifiers; isModifier = true; } else if (_rightModifierMappings.TryGetValue(e.Key, out modifier)) { _rightModifiers = _rightModifiers | modifier; Modifiers = Modifiers | _rightModifiers; isModifier = true; } _pressed.Add(e.Key); var args = new KeyTrackerEventArgs { Handled = e.Handled, Key = e.Key, IsModifier = isModifier }; KeyPressed?.Invoke(this, args); e.Handled = args.Handled; }
protected override void WndProc(ref Message m) { base.WndProc(ref m); if (m.Msg != WM_HOTKEY) { return; } Keys key = (Keys)(((int)m.LParam >> 16) & 0xFFFF); ModifierKeys modifier = (ModifierKeys)((int)m.LParam & 0xFFFF); if ((modifier & ModifierKeys.Alt) == ModifierKeys.Alt) { key = key | Keys.Alt; } if ((modifier & ModifierKeys.Control) == ModifierKeys.Control) { key = key | Keys.Control; } if ((modifier & ModifierKeys.Shift) == ModifierKeys.Shift) { key = key | Keys.Shift; } KeyPressed?.Invoke(this, new KeyPressedEventArgs(key)); }
private void KeyboardHookListener_KeyPress(object sender, KeyPressEventArgs e) { if (IsFocused) { KeyPressed?.Invoke(sender, e); } }
IEnumerator PressKey() { pressing = true; material.EnableKeyword("_EMISSION"); float timer = pressTime; Vector3 defaultPosition = transform.localPosition; while (timer > 0) { timer -= Time.deltaTime; transform.localPosition = Vector3.Lerp(pressedPosition, defaultPosition, timer / pressTime); // these are backwards on purpose yield return(null); } timer = pressTime; while (timer > 0) { timer -= Time.deltaTime; transform.localPosition = Vector3.Lerp(defaultPosition, pressedPosition, timer / pressTime); yield return(null); } pressing = false; material.DisableKeyword("_EMISSION"); KeyPressed?.Invoke(key); }
private void InvokeKeyPressed(Keys key) { if (KeyPressed != null) { KeyPressed.Invoke(this, new KeyPressedEventArgs(key)); } }
public void CheckInput() { if (Console.KeyAvailable) { ConsoleKeyInfo k = Console.ReadKey(true); if (k.Key == ConsoleKey.UpArrow) { KeyPressed?.Invoke(this, new KeyEventArgs(KeyEventArgs.Keys.RotateL)); } else if (k.Key == ConsoleKey.DownArrow) { KeyPressed?.Invoke(this, new KeyEventArgs(KeyEventArgs.Keys.Down)); } else if (k.Key == ConsoleKey.LeftArrow) { KeyPressed?.Invoke(this, new KeyEventArgs(KeyEventArgs.Keys.Left)); } else if (k.Key == ConsoleKey.RightArrow) { KeyPressed?.Invoke(this, new KeyEventArgs(KeyEventArgs.Keys.Right)); } else if (k.Key == ConsoleKey.Escape) { KeyPressed?.Invoke(this, new KeyEventArgs(KeyEventArgs.Keys.Exit)); } } }
/// <summary> /// Fire a key pressed event. /// </summary> internal void fireKeyPressed(KeyboardButtonCode keyCode, uint keyChar) { if (!keysDown[(int)keyCode]) { keysDown[(int)keyCode] = true; switch (keyCode) { case KeyboardButtonCode.KC_LSHIFT: shiftDown = true; break; case KeyboardButtonCode.KC_LMENU: altDown = true; break; case KeyboardButtonCode.KC_LCONTROL: ctrlDown = true; break; } if (KeyPressed != null) { KeyPressed.Invoke(keyCode, keyChar); } } }
public void CheckInput() { if (DateTimeOffset.Now.ToUnixTimeMilliseconds() - millis > DELAY) { Key?key = null; dispatcher.Invoke(DispatcherPriority.Normal, (Action) delegate { if (Keyboard.IsKeyDown(Key.Up)) { key = Key.Up; } else if (Keyboard.IsKeyDown(Key.Down)) { key = Key.Down; } else if (Keyboard.IsKeyDown(Key.Left)) { key = Key.Left; } else if (Keyboard.IsKeyDown(Key.Right)) { key = Key.Right; } else if (Keyboard.IsKeyDown(Key.Escape)) { key = Key.Escape; } }); if (key != null) { millis = DateTimeOffset.Now.ToUnixTimeMilliseconds(); KeyPressed?.Invoke(this, new Tetris.Data.KeyEventArgs(keyMap[(Key)key])); } } }
private void RaisePressedEvents(GameTime gameTime, KeyboardState currentState) { if (!currentState.IsKeyDown(Key.AltLeft) && !currentState.IsKeyDown(Key.AltRight)) { var pressedKeys = Enum.GetValues(typeof(Key)) .Cast <Key>() .Where(key => currentState.IsKeyDown(key) && _previousState.IsKeyUp(key)); foreach (var key in pressedKeys) { var args = new KeyboardEventArgs(key, currentState); KeyPressed?.Invoke(this, args); if (args.Character.HasValue) { KeyTyped?.Invoke(this, args); } _previousKey = key; _lastPressTime = gameTime.TotalGameTime; _isInitial = true; } } }
private HotkeyHook() { _window.KeyPressed += delegate(object sender, KeyPressedEventArgs args) { KeyPressed?.Invoke(this, args); }; }
public void Poll() { foreach (var keyPair in RegisteredKeys.ToList()) { var key = keyPair.Key; var modifiersDown = true; var modifiers = Keys.None; if (key.HasFlag(Keys.Shift)) { modifiersDown &= IsKeyDown(Keys.ShiftKey); modifiers |= Keys.Shift; } if (key.HasFlag(Keys.Control)) { modifiersDown &= IsKeyDown(Keys.ControlKey); modifiers |= Keys.Control; } if (key.HasFlag(Keys.Alt)) { modifiersDown &= IsKeyDown(Keys.Menu); modifiers |= Keys.Alt; } var keyWithoutModifiers = key & ~modifiers; var result = GetAsyncKeyState(keyWithoutModifiers); var isPressed = ((result >> 15) & 1) == 1; var wasPressedBefore = keyPair.Value; RegisteredKeys[key] = isPressed; if (modifiersDown && isPressed && !wasPressedBefore) { KeyPressed?.Invoke(this, new KeyEventArgs(key)); } } }
/// <summary> /// Constructor for the keyboard shortcuts class. /// </summary> public HotKeyMap() { _window.KeyPressed += delegate(object sender, KeyPressedEventArgs args) { KeyPressed?.Invoke(this, args); }; }
public bool OnKeyPressed(ConsoleKeyInfo cki) { KeyEventArgs e = new KeyEventArgs(cki); KeyPressed?.Invoke(this, e); return(!e.Cancel); }
/// <summary> /// Get user input. /// IOleCommandTarget.Exec() function /// </summary> public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut) { Debug.WriteLine($"InputListener.Exec( {pguidCmdGroup} {nCmdID} {nCmdexecopt} {pvaIn} {pvaOut} )"); ThreadHelper.ThrowIfNotOnUIThread(); int hr = VSConstants.S_OK; if ((new[] { 4, // tab 7, // left arrow 11, // up arrow 9, // right arrow 13, // down arrow 103, // escape 32, // space }).Contains((int)nCmdID)) { // send '\0' so we can abort KeyPressed?.Invoke(this, new KeyPressEventArgs('\0')); return(hr); } char typedChar; if (TryGetTypedChar(pguidCmdGroup, nCmdID, pvaIn, out typedChar)) { KeyPressed?.Invoke(this, new KeyPressEventArgs(typedChar)); return(hr); } ThreadHelper.ThrowIfNotOnUIThread(); hr = nextCommandHandler.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut); return(hr); }
private void RaiseKeyPressed(FormulaKeyEventArgs e) { if (KeyPressed != null) { KeyPressed.Invoke(e); } }
public KeyboardHook() { // register the event of the inner native window. window.KeyPressed += delegate(object sender, KeyPressedEventArgs args) { KeyPressed?.Invoke(this, args); }; }
private void ReadThreadProc() { try { byte[] lastKeyStates = new byte[NumKeys + 1]; while (!_cancellationTokenSource.IsCancellationRequested) { try { var keyStates = ReadKeyStates(); if (keyStates != null && keyStates.Length > 0) { for (int keyIdx = 1; keyIdx <= NumKeys; keyIdx++) { if (keyStates[keyIdx] != lastKeyStates[keyIdx]) { KeyPressed?.Invoke(this, new StreamDeckKeyChangedEventArgs(ConvertKeyIndex(keyIdx - 1), keyStates[keyIdx] > 0)); } } lastKeyStates = keyStates; } } catch (Exception ex) { Trace.TraceError($"ReadThreadProc had failure: {ex}"); } } } catch (Exception ex) { Trace.TraceInformation($"ReadThreadProc exiting due to FAILURE: {ex}"); } }
public void ProcessRawInput(IntPtr hdevice) { //Debug.WriteLine("__________________________________________"); //Debug.WriteLine(_rawBuffer.data.keyboard.ToString()); //Debug.WriteLine(_rawBuffer.data.hid.ToString()); //Debug.WriteLine(_rawBuffer.header.ToString()); //Debug.WriteLine("__________________________________________"); if (_deviceList.Count == 0) { return; } var dwSize = 0; Win32.GetRawInputData(hdevice, DataCommand.RID_INPUT, IntPtr.Zero, ref dwSize, Marshal.SizeOf(typeof(Rawinputheader))); if (dwSize != Win32.GetRawInputData(hdevice, DataCommand.RID_INPUT, out _rawBuffer, ref dwSize, Marshal.SizeOf(typeof(Rawinputheader)))) { Debug.WriteLine("Error getting the rawinput buffer"); return; } int virtualKey = _rawBuffer.data.keyboard.VKey; int makeCode = _rawBuffer.data.keyboard.Makecode; int flags = _rawBuffer.data.keyboard.Flags; if (virtualKey == Win32.KEYBOARD_OVERRUN_MAKE_CODE) { return; } var isE0BitSet = ((flags & Win32.RI_KEY_E0) != 0); KeyPressEvent keyPressEvent; if (_deviceList.ContainsKey(_rawBuffer.header.hDevice)) { lock (_padLock) { keyPressEvent = _deviceList[_rawBuffer.header.hDevice]; } } else { Debug.WriteLine("Handle: {0} was not in the device list.", _rawBuffer.header.hDevice); return; } var isBreakBitSet = ((flags & Win32.RI_KEY_BREAK) != 0); keyPressEvent.KeyPressState = isBreakBitSet ? "BREAK" : "MAKE"; keyPressEvent.Message = _rawBuffer.data.keyboard.Message; keyPressEvent.VKeyName = KeyMapper.GetKeyName(VirtualKeyCorrection(virtualKey, isE0BitSet, makeCode)).ToUpper(); keyPressEvent.VKey = virtualKey; KeyPressed?.Invoke(this, new RawInputEventArg(keyPressEvent)); }
protected override void WndProc(ref Message m) { base.WndProc(ref m); if (m.Msg == WM_HOTKEY) { KeyPressed?.Invoke(this, new KeyPressedEventArgs((Keys)(((int)m.LParam >> 16) & 0xFFFF), (ModifierKeys)((int)m.LParam & 0xFFFF))); } }
public KeyboardHook() { _hookWindow = new HookWindow(); _hookWindow.KeyPressed += (object sender, KeyPressedEventArgs e) => { KeyPressed?.Invoke(this, e); }; }