hotkey icon indicating copy to clipboard operation
hotkey copied to clipboard

doc: document the correct usage of X11 hotkey registration

Open wsy998 opened this issue 1 year ago • 5 comments

I can’t use it,is it my problem? (system:ubuntu 22.04) image

wsy998 avatar Sep 01 '22 09:09 wsy998

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:

https://github.com/golang-design/hotkey/blob/a5dde31e1341de42c328de537041eddd79995ff5/examples/fyne/main.go#L15-L34

changkun avatar Sep 01 '22 09:09 changkun

I checked that my hotkeys (including SYSTEM, INPUT METHOD, IDE) are not conflicting. The sample also failed to run successfully.

wsy998 avatar Sep 01 '22 09:09 wsy998

It might be useful if you could find a second device to test the environment.

changkun avatar Sep 02 '22 08:09 changkun

@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)
}

changkun avatar Sep 02 '22 09:09 changkun

OK,Let me try.

wsy998 avatar Sep 05 '22 05:09 wsy998

How did you find the other mod keys that are mapped?

mwalkerr avatar Jul 21 '23 05:07 mwalkerr