protected override IntPtr CustomHookProc(IntPtr wParam, IntPtr lParam) { KBDLLHOOKSTRUCT kbd = (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(KBDLLHOOKSTRUCT)); bool injected = (kbd.flags & (uint)LLKHF.INJECTED) != 0; switch ((WM)wParam) { case WM.KEYDOWN: case WM.SYSKEYDOWN: if (GetAsyncKeyState((int)kbd.vkCode) >= 0 && KeyDownEvent?.Invoke(this, kbd.vkCode, injected) == true) { return((IntPtr)(-1)); } if (KeyPressEvent?.Invoke(this, kbd.vkCode, injected) == true) { return((IntPtr)(-1)); } break; case WM.KEYUP: case WM.SYSKEYUP: if (KeyUpEvent?.Invoke(this, kbd.vkCode, injected) == true) { return((IntPtr)(-1)); } break; } return(IntPtr.Zero); }
void RaiseKeyPress(Alt.GUI.KeyPressEventArgs e) { OnKeyPress(e); if (KeyPress != null) { KeyPress(this, e); } m_onKeyPress.Invoke(e); }
public void RegisterDesktopKeyboardInput(object window) { Game game = (Game)window; game.Window.TextInput += (s, a) => { if (a.Character == '\t') { return; } KeyPressEvent.Invoke(a.Character, EventArgs.Empty); }; }
/// <summary> /// Starts an infinite loop to listen for key presses. /// </summary> public void ListenForKeyPress() { while (true) { if (Console.KeyAvailable && !_uiContainer.IsUIUpdating) { ConsoleKeyInfo keyInfo = Console.ReadKey(true); KeyPressEvent?.Invoke(this, new KeyPressedEventArgs() { PressedKey = keyInfo }); ClearInputBuffer(); } } }
// 地图控件键盘按键事件 private void mapControl_KeyPress(object sender, KeyPressEventArgs e) { if (MapFrame.GMap.Common.Utils.bPublishEvent == false) { return; } MFKeyPressEventArgs args = new MFKeyPressEventArgs(); args.KeyPressEventArgs = e; if (KeyPressEvent != null) { KeyPressEvent.Invoke(this, args); } }
internal static void InvokeKeyPressEvent(Player player, KeyCode key) { if (KeyPressEvent == null) { return; } var ev = new KeyPressEvent() { Player = player, Key = key }; KeyPressEvent.Invoke(ev); }
private void View_KeyPress(object sender, View.KeyEventArgs e) { if (e.KeyCode == Keycode.Back && e.Event.Action == KeyEventActions.Up) { View.KeyPress -= View_KeyPress; } if (e.Event.IsCapsLockOn || e.Event.IsShiftPressed) { capitalizedLetters = true; } else { capitalizedLetters = false; } string input = GetInput(e.KeyCode, capitalizedLetters); input = SpecialCharacters(input, e.Event.UnicodeChar); if (e.KeyCode == Keycode.Del && e.Event.Action == KeyEventActions.Up) { KeyPressEvent.Invoke("DELETE", EventArgs.Empty); } else { if (e.KeyCode == Keycode.Space && e.Event.Action == KeyEventActions.Up) { KeyPressEvent.Invoke(' ', EventArgs.Empty); } else { if (input != "-1" && e.Event.Action == KeyEventActions.Up) { KeyPressEvent.Invoke(Convert.ToChar(input), EventArgs.Empty); } else { if (e.Event.Characters != null) { KeyPressEvent.Invoke(Convert.ToChar(e.Event.Characters), EventArgs.Empty); } } } } }
public static void Init(UpdateService updateService) { InputManager.updateService = updateService; InputWatcherTask = new Task(new Action(() => { while (true) { if (Console.KeyAvailable) { KeyPressEvent?.Invoke(new KeyPressEventArgs() { KeyInfo = Console.ReadKey(true) }); } } })); InputWatcherTask.Start(); }
public void CreateAndSave(Trolley trolley) { Product newProduct = new Product() { Name = SetInformation.SetProductName(), Price = SetInformation.SetProductPrice(), Quantity = SetInformation.SetProductQuantity() }; Console.WriteLine("Нажмите Ctrl + S чтобы добавить продукт"); ConsoleKeyInfo keyInfo = Console.ReadKey(true); if (keyInfo.Modifiers == ConsoleModifiers.Control && keyInfo.Key == ConsoleKey.S) { trolley.Products.Add(newProduct); KeyPressEvent.Invoke(trolley, newProduct); } else { Console.WriteLine("Продукт не был добавлен"); } }
private void Update() { if (!paused) { if (Input.GetKeyDown(interactKey)) { OnInteractKeyPressed.Invoke(this); } else if (Input.GetKey(interactKey)) { OnInteractKeyHeld.Invoke(this); } if (Input.GetKey(crouchKey)) { crouching = true; if (Input.GetKeyDown(jumpKey)) { Drop(); } } else if (Input.GetKeyDown(jumpKey)) { OnJumpKeyPressed.Invoke(this); } if (Input.GetKeyDown(nextWeaponKey)) { OnNextWeaponKeyPressed.Invoke(this); } else if (Input.GetKeyDown(previousWeaponKey)) { OnPreviousWeaponKeyPressed.Invoke(this); } if (Input.GetKeyUp(crouchKey)) { crouching = false; AfterDrop(); } m_HorizontalAxis = Input.GetAxisRaw("Horizontal"); m_MoveSpeed = CalculateMoveSpeed(); Move(); } if (Input.GetKeyDown(resetKey)) { if (endGamePanel) { if (!endGamePanel.activeSelf) { GameController.TogglePause(); if (pausePanel) { GameController.TogglePanels(pausePanel); } OnResetKeyPressed.Invoke(this); } } else { GameController.TogglePause(); if (pausePanel) { GameController.TogglePanels(pausePanel); } OnResetKeyPressed.Invoke(this); } } }