-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
[feat] Expose WindowEvent::KeyboardInput
in Rust
#11671
Comments
similar to the other issue, your problem may just be solved by our global shortcut plugin, https://tauri.app/plugin/global-shortcut/ |
i disagree, app-local shortcuts and/or an equivalent to js key events in rust are a regularly requested features (i was sure there was one on github already before this but i can't find it...) |
not sure what you mean by this, please explain more |
basically key events that only work when the app is in focus. for example, let's say you want to listen to ctrl-s to save data. in your app most of the data is hosted on the rust side though so listening to the ctrl-s event on the rust side would be the easiest solution. All current "solutions" have drawbacks:
i'm not exactly sure how it behaves on macos but at least on windows tao's i realize i said mostly the same as OP but idk what else to say |
I also often get asked how to have global-shortcuts not be global because a shortcut like api is easier (for shortcuts) than listening to key events but that would just be an extra imo |
You keep calling it app-local, app-level where but I assume you mean window-level keyboard input but in Rust which is just forwarding taos' |
yes |
WindowEvent::KeyboardInput
in Rust
Yes, and no. In any case, I'd already be very happy if we could receive Tao's keyboard events in Rust Tauri by forwarding them. There is a difference between app- and window-level key events, but only on macOS. Mac apps can launch without having any window open, and can stay active when your last window closes. This is also why the menu resides at the top of your screen, and isn't tied to any specific window. A hotkey like Cmd + N to create a new "project" should be triggerable even without having any window open. To Windows and Linux users that seems exotic, but a lot of macOS apps work this way, including all Apple apps that come with the OS itself (Finder, for example). Technically this works, because key events are received by But to reiterate, at this stage I'm already happy if I can just receive window events forwarded from Tao.
Yeah, so receiving window events directly alleviates the accessibility permission, because apps have access to their own keyboard events by default. For something like the And, for macOS users, JS keydown events also don't fix this entirely, because you can't listen to non-window keydown events. :/ In any case, thank you for taking this request seriously. I know more people have been requesting this, and although it's not a waterproof argument, this is something most other app frameworks also support out-of-the-box. I'm happy to work with you and send in a PR, especially because the amount of macOS devs is probably low, but I would need some guidance/mentorship on where to look in the code. |
macOS is weird tbh. |
Thanks for the offer, we appreciate this.
|
Agree, app-level hot key is necessary |
Been a while, but I've started work on this. @amrbashir I've got two questions:
|
@stijnfrishert Let's start by just exposing As for the JS event, that sounds good too. |
@amrbashir I'm not sure what you're suggesting here. The keyboard types used in I can pass along Or are you suggesting to re-export and use |
Yes I meant the latter, and tao doesn't use it because it was a fork of winit, but nonetheless a wrapper in tauri ensures there is no breaking changes from tao would creep in. |
@amrbashir I've pushed some work and created a draft PR. There's a question about non-exhaustive enums in there. Can I ask you to take a look and review? I don't know what the workflow is for Tauri here. |
Describe the problem
I want to be able to react to key events coming from the application event loop.
I am building a shortcut system for my Desktop app, on macOS. I would like to be able to trigger hotkeys, even if the application doesn't have any windows open. This rules out any js key listener solutions, because they are tied to windows. Plus, this feels like something that should be done over in Rust-land, anyway.
The current recommended solution is to use rdev. This works up to a point (see #11670), but requires my app to ask for full access to all OS-level keyboard inputs (Accessibility), which is a permission I would rather not depend on.
In reality, this is something that should be solvable by propagating events from the event loop. I scoured through
Tao
a bit and found key event types, so this seems to be within the realm of possibility?Describe the solution you'd like
I want to be able to register a key event handler on my app. I envision this would look something like this, but that's of course up for debate:
I can imagine plug-ins might want to do this too, so maybe we should have a system to register (and unregister) multiple handlers.
Alternatives considered
Binding to key event listeners in js, but this can only be done on windows. Besides, imho this is something to be solved on the Rust side, using the application event loop.
Using
rdev
, but this requires my app to ask for full keyboard monitoring on an OS-level, which is not a permission I want to ask for, really.In addition, people have to twiddle with device_event_filter, which is neither intuitive nor easy to find.
Additional context
I've searched through the Discord and issue list, and it seems more people have been requesting this.
The text was updated successfully, but these errors were encountered: