keydown

Multiple keys with WPF KeyDown event

僤鯓⒐⒋嵵緔 提交于 2021-02-19 04:16:06
问题 I'm working with WPF KeyDown event (KeyEventArgs from Windows.Input). I need to recognize when user pressed F1 alone and Ctrl+F1. private void Window_KeyDown(object sender, KeyEventArgs e) { if (e.Key==Key.F1 && Keyboard.IsKeyDown(Key.LeftCtrl)) { MessageBox.Show("ctrlF1"); } if (e.Key == Key.F1 && !Keyboard.IsKeyDown(Key.LeftCtrl)) { MessageBox.Show("F1"); } } My problem is that when I press Ctrl+F1 plain F1 messagebox would fire too. I tried to add e.Handled to Ctrl+F1 case, but it doesn't

Multiple keys with WPF KeyDown event

对着背影说爱祢 提交于 2021-02-19 04:12:20
问题 I'm working with WPF KeyDown event (KeyEventArgs from Windows.Input). I need to recognize when user pressed F1 alone and Ctrl+F1. private void Window_KeyDown(object sender, KeyEventArgs e) { if (e.Key==Key.F1 && Keyboard.IsKeyDown(Key.LeftCtrl)) { MessageBox.Show("ctrlF1"); } if (e.Key == Key.F1 && !Keyboard.IsKeyDown(Key.LeftCtrl)) { MessageBox.Show("F1"); } } My problem is that when I press Ctrl+F1 plain F1 messagebox would fire too. I tried to add e.Handled to Ctrl+F1 case, but it doesn't

How do I prevent a leading space from being entered in a textbox?

徘徊边缘 提交于 2021-02-07 10:48:13
问题 I'm using jQuery 2. How do I prevent a space being entered in a textbox if it is a leading space (e.g. at the beginning of the string)? I thought this would do it $(document).on("keyup","#s" ,function(evt){ var firstChar = $("#s").val() if(evt.keyCode == 32 && firstChar){ $("#s").val( $("#s").val().trim() ) console.log(" called ") return false; } }) And basically it does but it is a little sloppy. You can see the space being entered and then removed and I was looking for something slightly

Adding a global monitor with NSEventMaskKeyDown mask does not trigger

旧城冷巷雨未停 提交于 2021-02-07 04:31:47
问题 I'm working on a MacOS menu bar app which needs to track some global shortcuts in order to facilitate adjusting display brightness on external monitors. However, I cannot get it to fire a handler on any keyboard related events (mouse events work just fine). I'm checking Accessibility with the following code NSDictionary *options = @{CFBridgingRelease(kAXTrustedCheckOptionPrompt): @YES}; BOOL accessibilityEnabled = AXIsProcessTrustedWithOptions((CFDictionaryRef)options); Then, I'm adding a

Adding a global monitor with NSEventMaskKeyDown mask does not trigger

别来无恙 提交于 2021-02-07 04:31:19
问题 I'm working on a MacOS menu bar app which needs to track some global shortcuts in order to facilitate adjusting display brightness on external monitors. However, I cannot get it to fire a handler on any keyboard related events (mouse events work just fine). I'm checking Accessibility with the following code NSDictionary *options = @{CFBridgingRelease(kAXTrustedCheckOptionPrompt): @YES}; BOOL accessibilityEnabled = AXIsProcessTrustedWithOptions((CFDictionaryRef)options); Then, I'm adding a

How can my form detect KeyDown events when another control has the focus?

与世无争的帅哥 提交于 2021-02-04 15:43:08
问题 procedure TMainForm.KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if (GetKeyState(Ord('Q'))<0) and (GetKeyState(Ord('W'))<0) and (GetKeyState(Ord('E'))<0) then ShowMessage('You pressed it'); end; the above event only work if the Focus set to the Main Form. if i run the application and keep pressing Tab and changing the Focus to any control on the Form it will disable this event until we change the Focus again to the main form ? the Question is how i can detect the three

Cannot read property 'keyCode' 'character' Assertion failure when detect modifier key + numeric key

試著忘記壹切 提交于 2021-01-16 03:51:42
问题 class func addGlobalMonitorForEvents(matching mask: NSEvent.EventTypeMask, handler block: @escaping (NSEvent) -> Void) -> Any?{ print("this inside addGlobalMonitorForEvents") } NSEvent.addGlobalMonitorForEvents(matching: .flagsChanged) { switch $0.modifierFlags.intersection(.deviceIndependentFlagsMask) { case [.shift]: print("shift key is pressed") print("key code is \($0.keyCode))") case [.control] where $0.characters == "1": print("control key is pressed") print("characters is \($0

listen to 'CTRL+N' with javascript

旧巷老猫 提交于 2021-01-05 07:14:49
问题 I am trying to bind the 'CTRL+N' key combination, like this: var ctrlPressed = false; var nCode = 78; var ctrlCode = 224; var cmdCode = 17; document.addEventListener ("keydown", function(e){ if( e.keyCode == ctrlCode || e.keyCode == cmdCode){ ctrlPressed = true; }else{ ctrlPressed = false; } console.log(e.keyCode); }); document.addEventListener ("keyup", function(e){ if(ctrlPressed && e.keyCode == nCode){ e.preventDefault(); nou_element(parent); return; } }); Please note: jQuery isn't

How should a modal dialog's key event handler be used using ReactJS?

孤人 提交于 2020-06-17 13:22:29
问题 I can understand we would use <input onKeyDown={ ... } /> but what if it is <Modal onKeyDown={ ... } /> because in a way, the keydown event handler code is inside of the Modal class (or function). If the modal is taking the left and right arrow key to perform some specific functions, then I wonder how we would bind the event handler in React, as the key event somehow is related to the modal as a whole, but not to particular input element inside the modal. P.S. I tried outer div and outer

keypress being deprecated, how to get the characters typed by a user?

眉间皱痕 提交于 2020-05-29 10:38:46
问题 The javascript keypress event is deprecated: https://developer.mozilla.org/en-US/docs/Web/API/Document/keypress_event Some people advise to rely exclusively on the keydown event, eg.: Keydown is the only keyboard event we need https://www.mutuallyhuman.com/blog/2018/03/27/keydown-is-the-only-keyboard-event-we-need/ The problem is that keydown and keypress are not synonymous. Critically, they do not return the same character in many/most cases. Keydown represents which key on the keyboard was