-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
onKey events not firing in 0.63.37 #823
Comments
You only get the key events you explicitly set as valid. From your example can you add the delimiter of what keys you want to listen to? Something like this works for me in the test app and allows the RCTView to listen to key events for
|
I tried with Same issue here: #930 |
Did you try it on a |
I actually tried on |
@BafS I'm seeing this work correctly for me in the RNTester so trying to figure out what's different on your setup. Did you try the example in RNTester? If so and it's still not working for you, can you post your sample project code so I can repro it and look at what's happening? |
same issue here I follow the way that adds Environment
|
After playing around it seems a |
Try following the steps under |
@Saadnajmi I don't think its necessary, because other native apps can use keyboard Focus and receive keyboard events without extra settings either |
Well that is true... I think React Native macOS specifically checks for this setting and I want to confirm that is indeed where the bug is coming from. |
That sorta seems to be working but now that I think about this, this is not at all what I want, I don't want to have to focus the view in order to receive keyboard events... I want a global keyDown listener I'm trying to make this work, but no event is being captured: https://stackoverflow.com/questions/32446978/swift-capture-keydown-from-nsviewcontroller any tips? Also, even though I enabled the settings and the focus ring was there, it seems I could not tab outside the parent component of the currently focused view, so even with the setting enabled, it is still not working properly |
ok, I figured it out, for those of you out there who actually want to add keyboard shortcuts/events to your app, on NSEvent.addLocalMonitorForEvents(matching: .keyDown) {
self.keyDown(with: $0)
return $0
} an example handler inside the same func keyDown(with event: NSEvent) {
print("MARKER pressed \(event.characters ?? "NO_CHAR")")
} Then it is only a matter of sending the event keyCode to the javascript context, I'm still not sure if there is any way to prevent bubbling up (e.g. if a TextInput is focused), but this is better than nothing |
What are you trying to prevent from bubbling? If it's a JS event, you could call e.stopPropogation() but I suspect you're talking about something else. Sounds like the setting I mentioned was the culprit, so I'll close this bug. |
I wouldn't close this issue, this doesn't solve the actual problem: how do you add global keyboard shortcuts to a react-native-macos app? on web you would do: window.addEventListener("keyDown", handler, options) there you can do |
The original bug was about just onKey events, not a global keyboard handler. For that, I would open a separate bug. I have a few thoughts on it, but I'd like to keep discussion focused per topic. |
Re: this thread. I think it's pretty annoying that we need that system preference for keyboard events, so I filed #1007 to track removing the need for that preference. |
Environment
react-native -v
: 0.63.4npm ls react-native-macos
: 0.63.37node -v
: 15.14.0npm -v
: 7.7.8yarn --version
: -xcodebuild -version
: 12.2Issue
onKey (onKeyUp, onKeyDown etc) events on do not fire.
Steps to Reproduce
Expected Behavior
onKey events to fire
Actual Behavior
No events fired
The text was updated successfully, but these errors were encountered: