Skip to content
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

"Global" keyboard listening #2220

Open
George3d6 opened this issue Oct 14, 2024 · 1 comment
Open

"Global" keyboard listening #2220

George3d6 opened this issue Oct 14, 2024 · 1 comment

Comments

@George3d6
Copy link

Reading through #966 and https://github.com/microsoft/react-native-macos/issues/823

It seemed that the recommended way to get global keyboard listeners was using onKeyDown on a top-level View

This seems not to work however I found:

onKeyPress={(e)=> {
        console.log(e.nativeEvent.key)
    }}

Works just fine (even though the type of View doesn't specify it ... however it only works after I e.g. click a specific TextInput (even if I move it out of focus later).

Is there an updated workaround to getting global keyboard listening to work (thus allowing things like hotkeys/shortcuts) ?

@Saadnajmi
Copy link
Collaborator

onKeyPress is a TextInput only prop / event which I suppose bubbled up without us realizing.. I wouldn't rely on that. We inherit that prop from React Native on mobile, and it doesn't really fit into the desktop keyboard API.

For global keyboard listening, since React Native is mostly only Root view and down, I think you still have to rely on implementing that natively with something like https://github.com/sindresorhus/KeyboardShortcuts unfortunately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants