Duplicate names cause multiple hotkey monitors to fail to coexist
Closed this issue · 6 comments
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");
This issue should only occur on Windows.
I can use multiple hotkey managers without a problem, please explain a bit more or provide a minimal reproduction.
I can use multiple hotkey managers without a problem, please explain a bit more or provide a minimal reproduction.
I tried to reproduce the problem and found that this problem occurs only when the tray_icon is registered first and the global_hotkey is registered later.
First register global_hotkey can receive hotkey events.
example
My system is Windows 10 LTSC 21H2, internal version :19044.3693,Windows Feature Experience Pack 1000.19053.1000.0
I see, thanks for the example, I can reproduce it now and will work on a fix soon.
I see, thanks for the example, I can reproduce it now and will work on a fix soon.
There was a mistake in the previous description so let me redescribe it.
I was misinformed,multiple process monitoring hotkeys will not have errors.
let icon =tray_icon::Icon::from_path("assets/icons/favicon.ico",None).unwrap();
let tray_icon = tray_icon::TrayIconBuilder::new()
.with_tooltip("system-tray - tray icon library!")
.with_icon(icon)
.build()
.unwrap();
TrayIconEvent::set_event_handler(Some(|event:TrayIconEvent|{
println!("tray event: {event:?}");
}));
let manager = GlobalHotKeyManager::new().unwrap();
let hotkey = HotKey::new(Some(Modifiers::SHIFT), Code::KeyF);
let result=manager.register(hotkey);
println!("{:?}register: {:?}",hotkey,result);
GlobalHotKeyEvent::set_event_handler(Some(|event|{
println!("hotkey event: {event:?}");
}));
If you register tray_icon first like this, you will not receive hotkey event, tray event can be received normally.
Modify the code as follows
global-hotkey\src\platform_impl\windows\mod
impl GlobalHotKeyManager {
pub fn new(name:&str) -> crate::Result<Self> {
let class_name = encode_wide("GlobalHotKey");
The hotkey event can be received successfully.
Thank you, a fix is being released now.