golang-design / hotkey

⌨️ cross-platform hotkey package
https://golang.design/x/hotkey
MIT License
215 stars 10 forks source link

Question: Can other keys be used apart from the ones that hardcoded in library? #20

Closed OlegGulevskyy closed 1 year ago

OlegGulevskyy commented 1 year ago

As subject goes, can we use other keys to listen for - for example, Alt (Linux / Windows) and Space ? I tried to pass the key code myself instead of key.KeyS for example, but got an error about integer overflow, which is expected. For example, when tried to use Alt from the keysymdef.h file

#define XK_Alt_L                         0xffe9  /* Left alt */

and passing it down to hotkey.New(), you get the error about int overflow image because

type Key uint8

What is the reason for this limitation and would it be possible to workaround / change it?

Thanks for the library!

changkun commented 1 year ago

I think this is resolved on main branch. Can you try to use the latest commit from the main branch?

OlegGulevskyy commented 1 year ago

ah nice! thanks, I will give it a go and let you know

changkun commented 1 year ago

If this works, I'll release a new version so that you can use a tagged version.

OlegGulevskyy commented 1 year ago

Great stuff, this works nicely, you can do a tagged version release I guess :)

Is there an out of the box way to listen for keyboard events in a sequence, rather than combo? Like double press on Alt, for example - this is not a blocking point, just curious Thanks!

changkun commented 1 year ago

I just released v0.4.0: https://github.com/golang-design/hotkey/releases/tag/v0.4.0

If you are developing a GUI application, I think most GUI frameworks offer the ability to listen to keystroke events, which seems a bit necessary to provide a standalone package. You may want to check these projects: fyne.io, gioui.org, ebiten.org

OlegGulevskyy commented 1 year ago

Thank you for the release, much appreciated! I am working wails.io app, there no global listeners yet, but we can work it out :) Thanks again!