public void PressKey(string key) { //--Třída si stisk zpracuje-- //Notifikace pozorovatelů OnKeyPress?.Invoke(this, new KeyboardScanner_EventArguments(key)); }
static public void InvokeOnKeyPress(OpenTK.KeyPressEventArgs e) { if (OnKeyPress != null) { OnKeyPress.Invoke(null, e); } }
public override void InputStateReceived(InputState inputState) { if (inputState.Is <KeyboardState>()) { OnKeyPress?.Invoke(this, new KeyPressEventArgs((KeyboardState)inputState.State)); } base.InputStateReceived(inputState); }
public bool ProcessKey(ConsoleKeyInfo key) { switch (key.Key) { case ConsoleKey.Backspace: Backspace(); break; case ConsoleKey.End: End(); break; case ConsoleKey.Home: Home(); break; case ConsoleKey.LeftArrow: Left(); break; case ConsoleKey.UpArrow: break; case ConsoleKey.RightArrow: Right(); break; case ConsoleKey.DownArrow: break; case ConsoleKey.Insert: break; case ConsoleKey.Delete: Delete(); break; case ConsoleKey.Tab: break; case ConsoleKey.Enter: break; case ConsoleKey.Spacebar: default: if (key.KeyChar != '\0') { AddText(key.KeyChar.ToString()); } break; } OnKeyPress?.Invoke(this, key); // allow the key event to bubble back up return(false); }
private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam) { if ((nCode >= 0) && (wParam == (IntPtr)NativeMethods.WM_KEYDOWN) && ((Keys)Marshal.ReadInt32(lParam) == Keys.F4)) { OnKeyPress?.Invoke(); } return(NativeMethods.CallNextHookEx(hookID, nCode, wParam, lParam)); }
private static void OnPlatformKeyDown(Keys key) { if (m_last_pressed_key != key) { m_last_pressed_key = key; OnKeyPress?.Invoke(key); } }
private static Task StartInputLoop() { while (true) { var keyPress = Console.ReadKey(); if (keyPress != null) { OnKeyPress?.Invoke(keyPress); } } }
public void StartListenKeyPress() { Task.Run(() => { while (true) { var key = Console.ReadKey().KeyChar; OnKeyPress?.Invoke(key); } }); }
private static IntPtr Callback(int nCode, IntPtr wParam, IntPtr lParam) { if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN) { if (OnKeyPress != null) { OnKeyPress.Invoke(Marshal.ReadInt32(lParam)); } } return(CallNextHookEx(hookId, nCode, wParam, lParam)); }
private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam) { if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN) { int vkCode = Marshal.ReadInt32(lParam); Key key = KeyInterop.KeyFromVirtualKey(vkCode); OnKeyPress?.Invoke(key); } return(CallNextHookEx(_hookID, nCode, wParam, lParam)); }
private void KeyDown(object sender, KeyEventArgs e) { if (!m_isPressed) { m_isPressed = true; if (sender is T) { OnKeyPress?.Invoke((T)sender, e); } } e.Handled = true; }
internal static void DWindowOnKeyDown(object sender, KeyboardKeyEventArgs e) { DKey key = (DKey)e.Key; DModifiers modifiers = new DModifiers(e.Shift, e.Control, e.Alt); if (!e.IsRepeat) { rootCanvas.OnKeyPressed(key, modifiers); OnKeyPress?.Invoke(key, modifiers); } rootCanvas.OnKeyDown(key, modifiers); OnKeyDown?.Invoke(key, modifiers); }
public void Update() { var currState = Keyboard.GetState(); var pressedKeys = currState.GetPressedKeys().ToList(); var lastPressedKeys = state.GetPressedKeys().ToList(); pressedKeys.ForEach((k) => { if (!lastPressedKeys.Contains(k)) { OnKeyPress?.Invoke(this, new KeyPressEvent { key = k }); } }); state = currState; }
public static void Start() { if (!IsRunning) { IsRunning = true; var t = Task.Run(() => { while (IsRunning) { var key = Console.ReadKey(true); OnKeyPress?.Invoke(new ConsoleKeyPressEventArgs(key)); } }); } }
private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam) { if (nCode >= 0) { switch ((KeyboardMessage)wParam) { case KeyboardMessage.WM_KEYDOWN: KeyEventsArgs = new KeyEventsArgs { KeyCode = Marshal.ReadInt32(lParam), KeyState = KeyState.KeyDown }; switch (KeyEventsArgs.Key) { case Keys.C: OnCPress?.Invoke(null, KeyEventsArgs); break; case Keys.Escape: OnEscapePress?.Invoke(null, KeyEventsArgs); break; case Keys.Space: OnSpacePress?.Invoke(null, KeyEventsArgs); break; case Keys.V: OnVPress?.Invoke(null, KeyEventsArgs); break; case Keys.B: OnBPress?.Invoke(null, KeyEventsArgs); break; } OnKeyPress?.Invoke(null, KeyEventsArgs); break; case KeyboardMessage.WM_KEYUP: break; } } return(NativeMethods.CallNextHookEx(HookId, nCode, wParam, lParam)); }
public JoystickViewModel() { Up = new BaseCommand(() => OnKeyPress?.Invoke(this, new JoystickEventArg(JoystickKey.Up))); SmallUp = new BaseCommand(() => OnKeyPress?.Invoke(this, new JoystickEventArg(JoystickKey.SmallUp))); Down = new BaseCommand(() => OnKeyPress?.Invoke(this, new JoystickEventArg(JoystickKey.Down))); Left = new BaseCommand(() => OnKeyPress?.Invoke(this, new JoystickEventArg(JoystickKey.Left))); SmallLeft = new BaseCommand(() => OnKeyPress?.Invoke(this, new JoystickEventArg(JoystickKey.SmallLeft))); Right = new BaseCommand(() => OnKeyPress?.Invoke(this, new JoystickEventArg(JoystickKey.Right))); SmallRight = new BaseCommand(() => OnKeyPress?.Invoke(this, new JoystickEventArg(JoystickKey.SmallRight))); Bridge = new BaseCommand(() => OnKeyPress?.Invoke(this, new JoystickEventArg(JoystickKey.Bridge))); Previous = new BaseCommand(() => OnKeyPress?.Invoke(this, new JoystickEventArg(JoystickKey.Previous))); LargePrev = new BaseCommand(() => OnKeyPress?.Invoke(this, new JoystickEventArg(JoystickKey.LargePrev))); Next = new BaseCommand(() => OnKeyPress?.Invoke(this, new JoystickEventArg(JoystickKey.Next))); LargeNext = new BaseCommand(() => OnKeyPress?.Invoke(this, new JoystickEventArg(JoystickKey.LargeNext))); ChangeCursor = new BaseCommand(() => OnKeyPress?.Invoke(this, new JoystickEventArg(JoystickKey.ChangeCursor))); SyncCursor = new BaseCommand(() => OnKeyPress?.Invoke(this, new JoystickEventArg(JoystickKey.SyncCursor))); SwapCursor = new BaseCommand(() => OnKeyPress?.Invoke(this, new JoystickEventArg(JoystickKey.SwapCursor))); }
/// <summary> /// 默认键盘钩子回调函数 /// </summary> /// <param name="nCode"></param> /// <param name="wParam"></param> /// <param name="lParam"></param> /// <returns></returns> private int DefaultKeyBoardHookProc(int nCode, int wParam, IntPtr lParam) { KBDLLHOOKSTRUCT kbhs = (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(KBDLLHOOKSTRUCT)); if (wParam == (int)MsgType.WM_KEYDOWN && OnKeyDown != null) { OnKeyDown.Invoke(this, new KeyEventArgs((Keys)kbhs.vkCode)); } else { if (wParam == (int)MsgType.WM_KEYUP && OnKeyUp != null) { OnKeyUp.Invoke(this, new KeyEventArgs((Keys)kbhs.vkCode)); } if (wParam == (int)MsgType.WM_KEYUP && OnKeyPress != null) { OnKeyPress.Invoke(this, new KeyEventArgs((Keys)kbhs.vkCode)); } } return(CallNextHookEx(kbhHook, nCode, wParam, lParam)); }
public async Task StartMainLoopAsync(CancellationToken cancel, char?haltOn = ' ') { mainLoopRunning = true; var examineConsole = true; char?lastKeyPress = null; while (!cancel.IsCancellationRequested && mainLoopRunning && (haltOn == null || lastKeyPress != haltOn)) { await Task.Delay(100); try { if (examineConsole) { lastKeyPress = Console.KeyAvailable ? Console.ReadKey().KeyChar : (char?)null; if (lastKeyPress.HasValue) { OnKeyPress?.Invoke(lastKeyPress.Value); await OfferKeypressToBehavioursAsync(lastKeyPress.Value); } } } catch (InvalidOperationException e) { await ReportAsync(VectorBehaviourPlusReport.FromException(e)); examineConsole = false; } if (AnyBehavioursNeedCameraProcessing) { ProcessCameraFrame(); } if (AnyBehavioursNeedPermanentObjectMonitoring) { UpdateObjectMonitoring(); } } }
/// <summary> /// Performs an OnKeyPress event /// </summary> /// <param name="kInfo">The key info</param> public void PerformKeyPress(ConsoleKeyInfo kInfo) { OnKeyPress?.Invoke(kInfo); }
/// <summary> /// Update cursor and keyboard events /// </summary> private void UpdateCursorAndKeyboardEvents() { if (!Visible) { return; } MouseEvent mouseState = MouseHandler.GetState(); KeyboardState kbState = KeyboardHandler.GetState(); var mouseSize = new Vector2(5); var mouseRect = new Rectangle((int)mouseState.X, (int)mouseState.Y, (int)mouseSize.X, (int)mouseSize.Y); var thisRect = new Rectangle((int)Position.X, (int)Position.Y, (int)Size.X, (int)Size.Y); //First check position if (mouseRect.Intersects(thisRect)) { //Second, check buttons //Left if (LastMouseCheck.LeftButton == ButtonState.Released && mouseState.LeftButton == ButtonState.Pressed) { OnMouseDown?.Invoke(this, mouseState.Position, MouseButtons.Left); } if (LastMouseCheck.LeftButton == ButtonState.Pressed && mouseState.LeftButton == ButtonState.Released) { OnMouseUp?.Invoke(this, mouseState.Position, MouseButtons.Left); OnMouseClick?.Invoke(this, mouseState.Position, MouseButtons.Left); } //Right if (LastMouseCheck.RightButton == ButtonState.Released && mouseState.RightButton == ButtonState.Pressed) { OnMouseDown?.Invoke(this, mouseState.Position, MouseButtons.Right); } if (LastMouseCheck.RightButton == ButtonState.Pressed && mouseState.RightButton == ButtonState.Released) { OnMouseUp?.Invoke(this, mouseState.Position, MouseButtons.Right); OnMouseClick?.Invoke(this, mouseState.Position, MouseButtons.Right); } //Middle if (LastMouseCheck.MiddleButton == ButtonState.Released && mouseState.MiddleButton == ButtonState.Pressed) { OnMouseDown?.Invoke(this, mouseState.Position, MouseButtons.Middle); } if (LastMouseCheck.MiddleButton == ButtonState.Pressed && mouseState.MiddleButton == ButtonState.Released) { OnMouseUp?.Invoke(this, mouseState.Position, MouseButtons.Middle); OnMouseClick?.Invoke(this, mouseState.Position, MouseButtons.Middle); } //Check move if (LastMouseCheck.Position != mouseState.Position) { OnMouseMove?.Invoke(this, mouseState.Position, MouseButtons.None); } //Hook Keyboard if (kbState.GetPressedKeys().Count() > 0 && LastKeyboardState.GetPressedKeys().Count() > 0) { //check pressed keys List <Keys> pressedKeys = kbState.GetPressedKeys().Except(LastKeyboardState.GetPressedKeys()).ToList(); foreach (Keys p in pressedKeys) { OnKeyPress?.Invoke(this, p, kbState); } //check released keys List <Keys> releasedKeys = LastKeyboardState.GetPressedKeys().Except(kbState.GetPressedKeys()).ToList(); foreach (Keys r in releasedKeys) { OnKeyUp?.Invoke(this, r, kbState); OnKeyPress?.Invoke(this, r, kbState); } } } else { // Leave == Release //Left } LastMouseCheck = mouseState; LastKeyboardState = kbState; }
public void LB_Key_Down(object sender, KeyEventArgs e) { string text = _combo.SelectedIndex < 0 ? "" : _combo.Items[_combo.SelectedIndex].ToString(); OnKeyPress?.Invoke(_combo.SelectedIndex, text, e.KeyData); }
public void KeyPress(Letter key) { OnKeyPress?.Invoke(key); }
internal void TriggerOnKeyPress(Keys key) { OnKeyPress?.Invoke(key); }
public void NotifyKeyPress(Event eventArgs) => OnKeyPress?.Invoke(this, eventArgs);
public void Component_OnKeyPress(char keyChar) => OnKeyPress?.Invoke(this, keyChar);
/// <summary> /// Invokes the OnKeyPress event. /// </summary> protected void InvokeKeyPress(BeatsKey key) => OnKeyPress?.Invoke(key);
public void InvokeKeyPress(object sender, JoystickEventArg e) { OnKeyPress?.Invoke(sender, e); }
internal void DispatchEvent(Map map, HtmlMarkerJsEventArgs eventArgs) { if (eventArgs.Options != null) { var popupOptions = Options.Popup; Options = eventArgs.Options; Options.Popup = popupOptions; } switch (eventArgs.Type) { case "click": OnClick?.Invoke(new HtmlMarkerEventArgs(map, eventArgs.Type, this)); break; case "contextmenu": OnContextMenu?.Invoke(new HtmlMarkerEventArgs(map, eventArgs.Type, this)); break; case "dblclick": OnDblClick?.Invoke(new HtmlMarkerEventArgs(map, eventArgs.Type, this)); break; case "drag": OnDrag?.Invoke(new HtmlMarkerEventArgs(map, eventArgs.Type, this)); break; case "dragend": OnDragEnd?.Invoke(new HtmlMarkerEventArgs(map, eventArgs.Type, this)); break; case "dragstart": OnDragStart?.Invoke(new HtmlMarkerEventArgs(map, eventArgs.Type, this)); break; case "keydown": OnKeyDown?.Invoke(new HtmlMarkerEventArgs(map, eventArgs.Type, this)); break; case "keypress": OnKeyPress?.Invoke(new HtmlMarkerEventArgs(map, eventArgs.Type, this)); break; case "keyup": OnKeyUp?.Invoke(new HtmlMarkerEventArgs(map, eventArgs.Type, this)); break; case "mousedown": OnMouseDown?.Invoke(new HtmlMarkerEventArgs(map, eventArgs.Type, this)); break; case "mouseenter": OnMouseEnter?.Invoke(new HtmlMarkerEventArgs(map, eventArgs.Type, this)); break; case "mouseleave": OnMouseLeave?.Invoke(new HtmlMarkerEventArgs(map, eventArgs.Type, this)); break; case "mousemove": OnMouseMove?.Invoke(new HtmlMarkerEventArgs(map, eventArgs.Type, this)); break; case "mouseout": OnMouseOut?.Invoke(new HtmlMarkerEventArgs(map, eventArgs.Type, this)); break; case "mouseover": OnMouseOver?.Invoke(new HtmlMarkerEventArgs(map, eventArgs.Type, this)); break; case "mouseup": OnMouseUp?.Invoke(new HtmlMarkerEventArgs(map, eventArgs.Type, this)); break; } }
private void InputThread() { // if there is no console available, no need to display anything. if (_screenLogBuilder == null) { return; } // get pointer to the console var hWnd = GetStdHandle(STD_INPUT_HANDLE); // disable quick edit mode as it steals mouse input var wasQuickEditModeEnabled = IsQuickEditModeEnabled(hWnd); if (wasQuickEditModeEnabled) { DisableQuickEditMode(hWnd); } EnableConsoleInputs(hWnd); // read initial key state CapsLockEnabled = GetKeyState(VirtualKeyStates.VK_CAPITAL) == 1; NumLockEnabled = GetKeyState(VirtualKeyStates.VK_NUMLOCK) == 1; ScrollLockEnabled = GetKeyState(VirtualKeyStates.VK_SCROLL) == 1; while (!_isRunning.WaitOne(100)) { var buffer = new INPUT_RECORD[128]; var eventsRead = 0U; var success = GetNumberOfConsoleInputEvents(hWnd, out eventsRead); if (eventsRead > 0) { var keyRead = ReadConsoleInput(hWnd, buffer, (uint)buffer.Length, out eventsRead); if (keyRead) { for (var z = 0; z < eventsRead; z++) { switch (buffer[z].EventType) { case KEYBOARD_EVENT: var keyEvent = buffer[z].KeyEvent; var key = (ConsoleKey)keyEvent.wVirtualKeyCode; CapsLockEnabled = keyEvent.dwControlKeyState.HasFlag(ControlKeyState.CAPSLOCK_ON); ScrollLockEnabled = keyEvent.dwControlKeyState.HasFlag(ControlKeyState.SCROLLLOCK_ON); NumLockEnabled = keyEvent.dwControlKeyState.HasFlag(ControlKeyState.NUMLOCK_ON); if (Options.InputOptions == InputOptions.UseBuiltInKeyOperations) { // internal keyboard handling events if (_isSearchEnabled && keyEvent.bKeyDown && !keyEvent.dwControlKeyState.HasFlag(ControlKeyState.LEFT_CTRL_PRESSED) && !keyEvent.dwControlKeyState.HasFlag(ControlKeyState.RIGHT_CTRL_PRESSED) && !keyEvent.dwControlKeyState.HasFlag(ControlKeyState.LEFT_ALT_PRESSED) && !keyEvent.dwControlKeyState.HasFlag(ControlKeyState.RIGHT_ALT_PRESSED) ) { AddSearchString(keyEvent.UnicodeChar); } if (keyEvent.bKeyDown) { switch (key) { case ConsoleKey.H: if (!_isSearchEnabled) { ToggleHelp(); } break; case ConsoleKey.Home: // scroll to start _bufferYCursor = Configuration.MaxHistoryLines; _hasLogUpdates = true; break; case ConsoleKey.Escape: case ConsoleKey.End: // scroll to end _bufferYCursor = 0; _searchLineIndex = -1; _hasLogUpdates = true; SetSearch(false); break; case ConsoleKey.PageUp: if (Options.InputOptions == InputOptions.UseBuiltInKeyOperations) { _hasLogUpdates = true; if (_bufferYCursor < _fullLogHistory.Count - LogDisplayHeight) { _bufferYCursor += LogDisplayHeight; } else { _bufferYCursor = _fullLogHistory.Count; } } break; case ConsoleKey.PageDown: if (Options.InputOptions == InputOptions.UseBuiltInKeyOperations) { _hasLogUpdates = true; if (_bufferYCursor - LogDisplayHeight > 0) { _bufferYCursor -= LogDisplayHeight; } else { _bufferYCursor = 0; } } break; case ConsoleKey.Enter: if (_isSearchEnabled) { FindNext(); } break; case ConsoleKey.S: // find/search if (keyEvent.dwControlKeyState.HasFlag(ControlKeyState.LEFT_CTRL_PRESSED)) { ToggleSearch(); } break; case ConsoleKey.F3: // find/search control keys if (keyEvent.dwControlKeyState.HasFlag(ControlKeyState.SHIFT_PRESSED)) { FindPrevious(); } else { FindNext(); } break; case ConsoleKey.Q: // quit if (!_isSearchEnabled) { System.Diagnostics.Debug.WriteLine("Quitting...."); Close(); Dispose(); } break; } } } OnKeyPress?.Invoke(new KeyPressEventArgs(key, keyEvent.dwControlKeyState)); break; case MOUSE_EVENT: var mouseEvent = buffer[z].MouseEvent; if (mouseEvent.dwEventFlags == MOUSE_MOVED) { // mouse move OnMouseMove?.Invoke(new MouseMoveEventArgs(mouseEvent.dwMousePosition.x, mouseEvent.dwMousePosition.y)); } else if (mouseEvent.dwEventFlags == MOUSE_BUTTON) { // mouse button press OnMousePress?.Invoke(new MousePressEventArgs((MouseButtonState)mouseEvent.dwButtonState, mouseEvent.dwControlKeyState)); } else if (mouseEvent.dwEventFlags == MOUSE_WHEELED) { // mouse wheel scroll var isWheelUp = mouseEvent.dwButtonState == MOUSE_WHEELUP; var isWheelDown = mouseEvent.dwButtonState == MOUSE_WHEELDOWN; if (isWheelUp) { if (Options.InputOptions == InputOptions.UseBuiltInKeyOperations) { _hasLogUpdates = true; if (_bufferYCursor > 0) { _bufferYCursor--; } } OnMouseScroll?.Invoke(new MouseScrollEventArgs(MouseScrollDirection.Up)); } if (isWheelDown) { if (Options.InputOptions == InputOptions.UseBuiltInKeyOperations) { _hasLogUpdates = true; if (_bufferYCursor < _fullLogHistory.Count - LogDisplayHeight) { _bufferYCursor++; } } OnMouseScroll?.Invoke(new MouseScrollEventArgs(MouseScrollDirection.Down)); } } break; } } } } } if (wasQuickEditModeEnabled) { EnableQuickEditMode(hWnd); } }