fyne
fyne copied to clipboard
add feature to hook global key bindings into (desktop?) OS
add Handle Key Presses in App
hi! I want to listen for shortcuts in the background and then do some tasks
I looked at the documentation and didn't find the API
Please use the templates (the feature request template in this case) when opening issues in the future.
There is already support for this. You should be able to pass a function to the .SetOnTypedKey()
method on the window canvas (https://pkg.go.dev/fyne.io/fyne/v2#Canvas). That should be your window .Canvas().SetOnTypedKey()
.
I'm sorry I wrote a new one .Canvas().SetOnTypedKey() This function is inconsistent
Is your feature request related to a problem? Please describe:
yes I need to achieve a quick screenshot through the keyboard Minimize background running .Canvas() .Canvas().SetOnTypedKey() .Canvas().SetOnTypedKey() .Canvas() .AddShortcut(shortcut Shortcut, handler func(shortcut Shortcut)) Only when the program is running in the foreground can it take effect Only when the current work window takes effect
Is it possible to construct a solution with the existing API?
no
Canvas() .Canvas().SetOnTypedKey() .Canvas().SetOnTypedKey()
.Canvas() .AddShortcut()
Only when the current work window takes effect
Describe the solution you'd like to see:
I need an API
API similar to .Canvas() .AddShortcut()
background running
Non current work window takes effect
The function is not inconsistent, it is simply not supposed to take inputs other than when the canvas is focused. Most operating systems, as far as I know, don't exactly send key presses to applications when they are not focused. That usually requires some kind of deeper hook into the key handling in the desktop environment and that is going to be very platform specific. I think that it most likely is outside the scope of Fyne, but that is just my understanding of the matter.
If I understand your use case correctly, I think the most sensible solution in this case would be to overwrite a shortcut in your operating system and make that to run your application instead.
I think there is something wrong with my description, which makes you understand it wrong
For example
I'm playing a game
I use the keyboard shortcut of OBS Studio software to record video in the game
fyne cannot be performed in inactive window
My active window is the game interface
Fyne lacks API to implement function
These hotkeys can be run in inactive windows
Almost many applications have the function of receiving shortcut keys in inactive windows
OBS discord ....
The implementation is not inconsistent, it simply lacks the feature you desire - OS global Keys must be registered separately and have complications such as needing to be globally unique. I have updated the title accordingly.
thank you
Reopening to track the feature addition.
@Jacalz thank your quick response! Is there any plan to deliver this feature?
The plan is currently to target this feature for the next big release after the one we are working on now (codename "Cragganmore"). Things might change, especially since someone actually needs to picks this up and work on it, but that's the rough plan.
Many thanks!
I would very much like to see the ability to register global hotkeys as well. I would like to develop a 'hotkeys' type application to run in the background with other windows in focus. I'll keep an eye on this thread.
Seems like this feature is coming to GLFW https://github.com/glfw/glfw/issues/1204
Is that now possible?
No. The GLFW issue has not been resolved yet and this issue is also open still.
I managed to work around it using https://github.com/golang-design/hotkey
This might be doable on Linux (including Wayland) for supported desktops using the XDG Desktop Portal interface for GlobalShortcuts
: https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.GlobalShortcuts.html