Closed wsy998 closed 1 year ago
I guess the support for Linux OS was not well enough. If the registered hotkey conflicts with an existing hotkey, it won't have any effect.
Generally you can run this example and see if it works on your system:
I checked that my hotkeys (including SYSTEM, INPUT METHOD, IDE) are not conflicting. The sample also failed to run successfully.
It might be useful if you could find a second device to test the environment.
@wsy998 OK. Now I recall the issue on Linux systems.
In general, Ubuntu maps multiple Mod keys to represent a single mod key. To be able to correctly register the key combination, you need figure out what is the correct underlying keycode combination for the platform. For example, a regular Ctrl+Alt+S should be registered as: Ctrl+Mod2+Mod4+S.
This example works on my Ubuntu 20.04 (Ctrl+Alt+S):
package main
import (
"fmt"
"golang.design/x/hotkey"
"golang.design/x/hotkey/mainthread"
)
func main() { mainthread.Init(fn) }
func fn() {
hk := hotkey.New([]hotkey.Modifier{hotkey.ModCtrl, hotkey.Mod2, hotkey.Mod4}, hotkey.KeyS)
err := hk.Register()
if err != nil {
return
}
fmt.Printf("hotkey: %v is registered\n", hk)
<-hk.Keydown()
fmt.Printf("hotkey: %v is down\n", hk)
<-hk.Keyup()
fmt.Printf("hotkey: %v is up\n", hk)
hk.Unregister()
fmt.Printf("hotkey: %v is unregistered\n", hk)
}
OK,Let me try.
How did you find the other mod keys that are mapped?
I can’t use it,is it my problem? (system:ubuntu 22.04)