tauri icon indicating copy to clipboard operation
tauri copied to clipboard

[feat] Allow listening for the release of a global shortcut's key combination

Open anoadragon453 opened this issue 2 years ago • 5 comments

Describe the problem

I would like to implement global push-to-talk functionality for voice calls in my app. I've seen the globalShortcut module which allows one to register a callback for when a key combination is pressed, even if the app is not in focus.

However, for effective push-to-talk, I would like to listen both for when the key combination is pressed, and when it is released. At the moment, the API only allows the former.

Describe the solution you'd like

I would like to be able to pass two callbacks to globalShortcut.register. The first would be called when the shortcut was pressed, and the second would be called when the shortcut was released.

Alternatives considered

An alternative is to have a single callback which is passed a boolean parameter, indicating whether the shortcut was pressed or released.

Additional context

No response

anoadragon453 avatar Jun 16 '22 11:06 anoadragon453

`pub fn register_shortcuts(_app: &mut App<Wry>) { _app.global_shortcut_manager().register("Alt+D", my_custom_sys).expect("快捷键注册失败"); }

fn my_custom_sys() { println!("global_shortcut:Alt+D"); }` 我想知道快捷键的回调如何获取app

DL-NEST avatar Jul 01 '22 20:07 DL-NEST

I would also like to see this implemented in tauri, atm we have to do this on our own with f.e. https://docs.rs/device_query/0.1.3/device_query/index.html

skyslide22 avatar Jul 08 '22 00:07 skyslide22

/upstream tauri-apps/tao

lucasfernog avatar Jul 08 '22 03:07 lucasfernog

Upstream issue at https://github.com/tauri-apps/tao/issues/467 has been closed.

tauri-apps[bot] avatar Jul 08 '22 03:07 tauri-apps[bot]

The implementation of globalShortcut at least on Windows doesn't allow that (limitation of the used win32 API).

For this use-case, global keyboard events should be used with manual track of modifiers and key combos but for now global keyboard events doessn't work on Wayland (limitation of Wayland, they still wouldn't provide a protocol for it, even though many developers requested it) and flaky on X11?.

amrbashir avatar Jul 08 '22 03:07 amrbashir

@amrbashir hotkey库使用的winapi可以监听到keydown和keyup事件,如果想要监听按键释放还要自己稍微改动下代码; 我在自己的程序中实现了监听按键按下和松开的功能,它可以在失去焦点时正常运行但是如果我把我的程序集成到tauri中时就会出问题;当tauri获取焦点时监听无效,当其他任何程序获得焦点时都可以正常监听到按键事件,我不知道tauri内部做了什么 image

felix307253927 avatar Apr 09 '23 10:04 felix307253927

@felix307253927 Tauri v1.3 will have a method to disable the filter: https://github.com/tauri-apps/tauri/pull/5562 - if you can't wait for that release, you can also use the dev branch as described here: https://tauri.app/v1/guides/faq#how-can-i-use-unpublished-tauri-changes

FabianLars avatar Apr 09 '23 14:04 FabianLars