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); } }
// attach event to a key press public static void AttachKeyPressEvent(OnKeyPress onKeyPress) { foreach (char c in Input.inputString) { onKeyPress(c); } }
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 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 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 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 static void Start() { if (!IsRunning) { IsRunning = true; var t = Task.Run(() => { while (IsRunning) { var key = Console.ReadKey(true); OnKeyPress?.Invoke(new ConsoleKeyPressEventArgs(key)); } }); } }
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 string OnKeyPress() { string value = ""; OnKeyPress oo = new OnKeyPress(this.s, this.header); Type t = oo.GetType(); MethodInfo mi = t.GetMethod(this.reference(0)); try { object o = mi.Invoke(oo, null); value = (string)o; } catch (NullReferenceException) { } return(value); }
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))); }
public void AddListenerKeyPress(KeyCode key, OnKeyPress action) { if (dicListenerKeyPress == null) { dicListenerKeyPress = new Dictionary <KeyCode, OnKeyPress>(); } if (dicListenerKeyPress.ContainsKey(key)) { if (dicListenerKeyPress[key] == null) { dicListenerKeyPress[key] = action; } dicListenerKeyPress[key] += action; } else { dicListenerKeyPress.Add(key, action); } }
/// <summary> /// Overrides KeyDown event, intercepts Arrow Up/Down and uses them to add/substract the value manually by the step value. /// Relying on the browser mean the steps are each integer multiple from <see cref="Min"/> up until <see cref="Max"/>. /// This align the behaviour with the spinner buttons. /// </summary> /// <remarks>https://try.mudblazor.com/snippet/QamlkdvmBtrsuEtb</remarks> protected async Task InterceptArrowKey(KeyboardEventArgs obj) { if (obj.Type == "keydown")//KeyDown or repeat, blazor never fire InvokeKeyPress { if (obj.Key == "ArrowUp") { await Increment(); return; } else if (obj.Key == "ArrowDown") { await Decrement(); return; } } _keyDownPreventDefault = KeyDownPreventDefault; OnKeyPress.InvokeAsync(obj).AndForget(); }
/// <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(); } } }
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; } }
/// <summary> /// Performs an OnKeyPress event /// </summary> /// <param name="kInfo">The key info</param> public void PerformKeyPress(ConsoleKeyInfo kInfo) { OnKeyPress?.Invoke(kInfo); }
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 NotifyKeyPress(Event eventArgs) => OnKeyPress?.Invoke(this, eventArgs);
/// <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; }
private void ProcessKeyPress(RawInputKeyPressEventArgs args) { Console.WriteLine($"{args.Device.Name} {args.Device.ID} {args.CorrectedKey} {args.KeyPressState}"); if (args.Device.Handle == IntPtr.Zero) { EnqueueDecision(args.VKey, args.KeyPressState, false, IntPtr.Zero); return; } Delegate[] handlers; if (!Enabled) { handlers = HookDisabledOnKeyPress?.GetInvocationList(); if (handlers != null) { foreach (RawInputKeyPressEvent handler in handlers) { handler.Invoke(this, args); if (args.Handled) { break; } } } EnqueueDecision(args.VKey, args.KeyPressState, args.Handled, args.Device.Handle); return; } handlers = OnKeyPress?.GetInvocationList(); if (handlers != null) { foreach (RawInputKeyPressEvent handler in handlers) { handler.Invoke(this, args); if (args.Handled) { break; } } } EnqueueDecision(args.VKey, args.KeyPressState, args.Handled, args.Device.Handle); if (args.Handled && (handlers = HandledKeyPress?.GetInvocationList()) != null) { args.Handled = false; new Thread(() => { foreach (RawInputKeyPressEvent handler in handlers) { handler.Invoke(this, args); if (args.Handled) { break; } } }) { IsBackground = true, Name = "HandledKeyPress thread" }.Start(); } }
/// <summary> Adds the events for this html element directly to the text writer output </summary> /// <param name="Output"> Output to write directly to </param> public void Add_Events_HTML(TextWriter Output) { if (!String.IsNullOrWhiteSpace(OnClick)) { Output.Write("onclick=\"" + OnClick.Replace("\"", "'") + "\" "); } if (!String.IsNullOrWhiteSpace(OnContextMenu)) { Output.Write("oncontextmenu=\"" + OnContextMenu.Replace("\"", "'") + "\" "); } if (!String.IsNullOrWhiteSpace(OnDblClick)) { Output.Write("ondblclick=\"" + OnDblClick.Replace("\"", "'") + "\" "); } if (!String.IsNullOrWhiteSpace(OnMouseDown)) { Output.Write("onmousedown=\"" + OnMouseDown.Replace("\"", "'") + "\" "); } if (!String.IsNullOrWhiteSpace(OnMouseEnter)) { Output.Write("onmouseenter=\"" + OnMouseEnter.Replace("\"", "'") + "\" "); } if (!String.IsNullOrWhiteSpace(OnMouseLeave)) { Output.Write("onmouseleave=\"" + OnMouseLeave.Replace("\"", "'") + "\" "); } if (!String.IsNullOrWhiteSpace(OnMouseMove)) { Output.Write("onmousemove=\"" + OnMouseMove.Replace("\"", "'") + "\" "); } if (!String.IsNullOrWhiteSpace(OnMouseOver)) { Output.Write("onmouseover=\"" + OnMouseOver.Replace("\"", "'") + "\" "); } if (!String.IsNullOrWhiteSpace(OnMouseOut)) { Output.Write("onmouseout=\"" + OnMouseOut.Replace("\"", "'") + "\" "); } if (!String.IsNullOrWhiteSpace(OnMouseUp)) { Output.Write("onmouseup=\"" + OnMouseUp.Replace("\"", "'") + "\" "); } if (!String.IsNullOrWhiteSpace(OnKeyDown)) { Output.Write("onkeydown=\"" + OnKeyDown.Replace("\"", "'") + "\" "); } if (!String.IsNullOrWhiteSpace(OnKeyPress)) { Output.Write("onkeypress=\"" + OnKeyPress.Replace("\"", "'") + "\" "); } if (!String.IsNullOrWhiteSpace(OnKeyUp)) { Output.Write("onkeyup=\"" + OnKeyUp.Replace("\"", "'") + "\" "); } if (!String.IsNullOrWhiteSpace(OnLoad)) { Output.Write("onload=\"" + OnLoad.Replace("\"", "'") + "\" "); } if (!String.IsNullOrWhiteSpace(OnSelect)) { Output.Write("onselect=\"" + OnSelect.Replace("\"", "'") + "\" "); } if (!String.IsNullOrWhiteSpace(OnChange)) { Output.Write("onchange=\"" + OnChange.Replace("\"", "'") + "\" "); } if (!String.IsNullOrWhiteSpace(OnWheel)) { Output.Write("onwheel=\"" + OnWheel.Replace("\"", "'") + "\" "); } }