tauri-apps / global-hotkey Goto Github PK
View Code? Open in Web Editor NEWGlobal hotkeys for Desktop Applications.
License: Apache License 2.0
Global hotkeys for Desktop Applications.
License: Apache License 2.0
I initiated a tauri project using create-tauri
and wanted to integrate the global-hotkey
library to listen for hotkeys. However, after including the global-hotkey
library, without making any changes to the code, running cargo tauri dev
results in errors. The error messages are as follows:
error[E0432]: unresolved import `self::platform`
--> C:\Users\aa\.cargo\registry\src\mirrors.sjtug.sjtu.edu.cn-be2141875385cea5\global-hotkey-0.4.1\src\platform_impl\mod.rs:15:22
|
15 | pub(crate) use self::platform::*;
| ^^^^^^^^ could not find `platform` in `self`
error[E0433]: failed to resolve: could not find `GlobalHotKeyManager` in `platform_impl`
--> C:\Users\aa\.cargo\registry\src\mirrors.sjtug.sjtu.edu.cn-be2141875385cea5\global-hotkey-0.4.1\src\lib.rs:140:43
|
140 | platform_impl: platform_impl::GlobalHotKeyManager::new()?,
| ^^^^^^^^^^^^^^^^^^^ could not find `GlobalHotKeyManager` in `platform_impl`
error[E0412]: cannot find type `GlobalHotKeyManager` in module `platform_impl`
--> C:\Users\aa\.cargo\registry\src\mirrors.sjtug.sjtu.edu.cn-be2141875385cea5\global-hotkey-0.4.1\src\lib.rs:134:35
|
134 | platform_impl: platform_impl::GlobalHotKeyManager,
| ^^^^^^^^^^^^^^^^^^^ not found in `platform_impl`
I'm looking for assistance to resolve these errors. Thank you in advance for your help!
HotKeyCode's Shift, Control, Alt, Meta (all Left and Right), as well as Pause (as in PauseBreak) fail to register on windows.
FailedToRegister("Unable to register hotkey (unknown VKCode for this key: ShiftLeft).")
It appears they are not supported as direct bindings via in key_to_vk
Tried to work around this by adding a hotkey with the corresponding modifier code using Unidentified as the vk_code, but that didnt not successfully register either.
Global Shortcut on Linux only works on x11 because wayland-protocols hasn't define anything yet.
There's a RFC about this.
While we can use some workaround or implement one our own, it won't be supported by all DEs.
We'll have to wait wayland decide to add this.
Even though this crate doesn't work on Android/iOS/etc, that doesn't mean the types of this crate can't be exposed on those platforms.
I don't see why any of the types in lib.rs couldn't work across all the platforms, even if functionality didn't work. Having to work around this is a bit of a nuisance since it needs we need to wrap the type or stub it out - neither of which are great.
How can i listen for media keys like Play/Pause / Next etc.
Is this even possible and if not will this be implemented in the future?
I'd like to grab a hotkey only when the Tauri window is focused and within the window, not globally. But seems there's no way to implement it.
If I register Ctrl + S
as a global hotkey, then it will fail everywhere I want to use hotkey Ctrl + S
to save something.
Technically, registering a hotkey using JavaScript
can restrict the hotkey within the Tauri WebView window, but what if I want to register hotkeys like Ctrl + S
and F5
? This will be an invalid way.
I'd like to have a choice to choose whether a hotkey should be GLOBALLY or WINDOW FOCUSED ONLY caught. Thanks :)
Hello. We're seeing segfaults originating from global-hotkey in our logs. Here is a stacktrace:
OS Version: Linux 6.2.0 (39-generic)
Report Version: 104
Crashed Thread: 3499986
Application Specific Information:
Fatal Error: SIGSEGV / SI_KERNEL / 0x0
Thread 3499986 Crashed:
0 libc.so.6 0x7f562b63eab3 __run_exit_handlers (exit.c:72)
1 libc.so.6 0x7f562b6e1c7f __libc_pause (pause.c:29)
2 libc.so.6 0x7f562b63eccf exit (exit.c:141)
3 libX11.so.6 0x7f562a2622a2 _XDefaultIOError (XlibInt.c:1317)
4 libX11.so.6 0x7f562a26221f [inlined] _XAllocID (xcb_io.c:626)
5 libX11.so.6 0x7f562a26221f _XAllocID (xcb_io.c:623)
6 libX11.so.6 0x7f562a264c02 _XIOError (XlibInt.c:1548)
7 libX11.so.6 0x7f562a267b74 _XEventsQueued (xcb_io.c:444)
8 libX11.so.6 0x7f562a25a706 XPending (Pending.c:55)
9 libc.so.6 0x7f562b6e1c7f __libc_pause (pause.c:29)
10 warp 0x56166297bac9 global_hotkey::platform_impl::platform::events_processor
11 warp 0x561662980c85 std::sys_common::backtrace::__rust_begin_short_backtrace::<T>
12 warp 0x56166297e65f std::thread::Builder::spawn_unchecked_<T>::{closure#1}::call_once::{shim:vtable#0}
13 warp 0x5616631be274 std::sys::unix::thread::Thread::new::thread_start
14 libc.so.6 0x7f562b68f6b9 start_thread (pthread_create.c:444)
15 libc.so.6 0x7f562b68f3cf [inlined] create_thread (pthread_create.c:240)
16 libc.so.6 0x7f562b68f3cf create_thread (pthread_create.c:240)
17 libc.so.6 0x7f562b71e11f clone3 (clone3.S:81)
Unfortunately, that's all the info we have on the issue currently. We're not sure how to reproduce this.
The following text is generated by automatic translation:
Duplicate names cause multiple hotkey monitors to fail to coexist.
tray-icon crate has the same problem.
I think we should set the incoming parameters.
impl GlobalHotKeyManager {
pub fn new() -> crate::Result<Self> {
let class_name = encode_wide("tray_icon_app");
Is this possible to do? I've seen this in Swift before.
Here it is implemented for macOS: https://medium.com/@avaidyam/building-a-better-registereventhotkey-900afd68f11f but seems to be a lot more than that lol.
I got the library to work, but am only getting the Released
event, but never the Pressed
event first.
Hey folks, hope you're doing well.
At present, if a user holds down a global hotkey, this library emits a single event with state Pressed
, and when the user releases the key, a single event with 'Released' is emitted. Tested on Windows 11 Pro.
However, in many cases, users may hold down a hotkey and expect it to continue firing at the rate set by the OS. Would it be possible to at least have a way to enable this behaviour please?
Thanks heaps
Fotis
In the example egui, when I press a hotkey outside the window, the application does not immediately print the GlobalHotKeyEvent. When I return to the application window, it will print all events simultaneously.
Here is my code:
use global_hotkey::{
hotkey::{Code, HotKey, Modifiers},
GlobalHotKeyEvent, GlobalHotKeyManager,
};
fn main() {
// initialize the hotkeys manager
let manager = GlobalHotKeyManager::new().unwrap();
// construct the hotkey
let hotkey = HotKey::new(Some(Modifiers::SHIFT | Modifiers::CONTROL), Code::KeyV);
// register it
manager.register(hotkey).unwrap();
let received = GlobalHotKeyEvent::receiver().recv().unwrap();
println!("{:?}, {:?}", received.id, hotkey.id());
}
run it and nothing happend
OS version: 12.1
Sorry if this is not a fitting place to ask questions like these.
I'm working on a WM, and i've been using this crate, which is working amazingly well, but it forces me to use winit, which I'd rather not have so that I can reduce my build times in CI. Is it possible to use this crate with tokio? And if so, do you guys have a Minimal working example for that?
I'm not sure if this is problem of this crate or X11, but it seems the order in which keys of a shortcut are released does matter right now. Here is a simple snippet detecting Alt+C hotkey and printing when it's pressed and released.
Pressed
Released
Pressed
Released
Pressed
Released
Pressed
Released
Pressed
Released
Pressed
Released
There are basically two problems here, pressing sequence 2 prints "Pressed" but not "Released", repeating the same sequence (sequence 3) won't do anything (because the internal hotkey state is likely stuck), and sequence 4 won't produce the pressed event but only the released event.
use global_hotkey::{
GlobalHotKeyManager, GlobalHotKeyEvent,
hotkey::{HotKey, Modifiers, Code}
};
fn main() {
let manager=GlobalHotKeyManager::new().unwrap();
let hotkey=HotKey::new(Some(Modifiers::ALT), Code::KeyC, );
manager.register(hotkey).unwrap();
for event in GlobalHotKeyEvent::receiver() {
println!("{:?}", event.state());
}
}
global-hotkey 0.4.0, Ubuntu Mate 22.04 64-bit
xml-rs is Unmaintained
Details | |
---|---|
Status | unmaintained |
Package | xml-rs |
Version | 0.8.4 |
URL | https://github.com/netvl/xml-rs/issues |
Date | 2022-01-26 |
xml-rs is a XML parser has open issues around parsing including integer
overflows / panics that may or may not be an issue with untrusted data.
Together with these open issues with Unmaintained status xml-rs
may or may not be suited to parse untrusted data.
See advisory page for additional details.
Hi,
I'm trying to debug the proper keycode for the key at the left of the 1
in the top row of an azerty keyboard.
I tried Backslash
(this is mapped to ><
), Backquote
(this is mapped to the proper backquote on azerty), and a few others that failed to register altogether.
Is there a way to register all supported keycodes in order to debug that?
Thanks for the lib really useful and it also integrates well with slint-ui
I was hoping to make a pr for an iced example, and I have a working example for version 0.2.4, but when I try to upgrade it into the latest version, it fails to detect inputs. The change log between these versions appears to contain nothing that would affect this.
So below is the working 0.2.4 example:
// 0.2.4 imports
use global_hotkey::hotkey::{Code, HotKey, Modifiers};
use global_hotkey::{GlobalHotKeyEvent, GlobalHotKeyManager};
use iced::futures::SinkExt;
use iced::widget::{container, row, text};
use iced::{executor, Application, Command, Element, Subscription, Theme};
struct Example {
last_pressed: String,
}
#[derive(Debug, Clone)]
enum ProgramCommands {
Received(String),
}
impl Application for Example {
type Executor = executor::Default;
type Message = ProgramCommands;
type Theme = Theme;
type Flags = ();
fn new(_flags: Self::Flags) -> (Example, iced::Command<Self::Message>) {
// you can also put the manager inside of the `Example` struct, and create an interface to rebind
let manager = GlobalHotKeyManager::new().unwrap();
let hotkey_1 = HotKey::new(Some(Modifiers::CONTROL), Code::ArrowRight);
let hotkey_2 = HotKey::new(None, Code::ArrowUp);
manager.register(hotkey_2).unwrap();
manager.register(hotkey_1).unwrap();
(
Example {
last_pressed: "".to_string(),
},
Command::none(),
)
}
fn title(&self) -> String {
String::from("Iced example!")
}
fn theme(&self) -> Self::Theme {
Theme::Dark // dark theme :D
}
fn update(&mut self, msg: Self::Message) -> iced::Command<ProgramCommands> {
match msg {
Self::Message::Received(code) => {
self.last_pressed = code.to_string();
Command::none()
}
}
}
fn view(&self) -> Element<'_, Self::Message> {
container(row![text("You pressed: "), text(self.last_pressed.clone())]).into()
}
fn subscription(&self) -> Subscription<Self::Message> {
// if you want to have multiple subscriptions, do it like this:
// iced::Subscription::batch(vec![self.hotkey_sub(), self.test_sub()])
self.hotkey_sub()
}
}
fn main() -> iced::Result {
Example::run(iced::Settings::default())
}
impl Example {
pub fn hotkey_sub(&self) -> Subscription<ProgramCommands> {
iced::subscription::channel(4, 32, |mut sender| async move {
let receiver = GlobalHotKeyEvent::receiver();
loop {
match receiver.try_recv() {
Err(_e) => {
// nothing, this happens when nothing happens
}
Ok(t) => {
// if you want to differenciate between the different codes, you can match them:
// match t {
// GlobalHotKeyEvent { id: 267073199 } => { // this is for up arrow, no modifiers
// do whatever
// }
// }
sender
.send(ProgramCommands::Received(format!("{:?}", t)))
.await
.unwrap()
}
}
// so this will occur infinitely, i would really recommend using the `async_std` crate to put a sleep here
async_std::task::sleep(std::time::Duration::from_millis(50)).await;
}
})
}
}
(Requires iced = "0.12.1"
& async-std = "1.12"
)
I would like to create HotKey with SHIFT + Left Mouse Click
. This is currently not supported as far as I can see. It would be perfect if it was also possible to get the position of the mouse click from this event.
The documentation doesn't indicate that registering events consumes the input, but listening for hotkeys does just that. I'd love the ability to specify that the hotkey manager should never consume input for my use-case.
Could you provide an example with eframe? It has an event loop running internally. Also could you explain why it needs to be running in an event loop? Based on the examples in the readme, this sort of snippet should work.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.