Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: document the correct usage of X11 hotkey registration #17

Closed
wsy998 opened this issue Sep 1, 2022 · 6 comments
Closed

doc: document the correct usage of X11 hotkey registration #17

wsy998 opened this issue Sep 1, 2022 · 6 comments
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@wsy998
Copy link

wsy998 commented Sep 1, 2022

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

@changkun
Copy link
Member

changkun commented Sep 1, 2022

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:

func main() {
w := app.New().NewWindow("golang.design/x/hotkey")
label := widget.NewLabel("Hello golang.design!")
button := widget.NewButton("Hi!", func() { label.SetText("Welcome :)") })
w.SetContent(container.NewVBox(label, button))
go func() {
// Register a desired hotkey.
hk := hotkey.New([]hotkey.Modifier{hotkey.ModCtrl, hotkey.ModShift}, hotkey.KeyS)
if err := hk.Register(); err != nil {
panic("hotkey registration failed")
}
// Start listen hotkey event whenever it is ready.
for range hk.Keydown() {
button.Tapped(&fyne.PointEvent{})
}
}()
w.ShowAndRun()
}

@wsy998
Copy link
Author

wsy998 commented Sep 1, 2022

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

@changkun
Copy link
Member

changkun commented Sep 2, 2022

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

@changkun
Copy link
Member

changkun commented Sep 2, 2022

@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 changkun changed the title I can’t use it? doc: document the correct usage of X11 hotkey registration Sep 2, 2022
@changkun changkun added documentation Improvements or additions to documentation and removed NeedsInvestigation labels Sep 2, 2022
@changkun changkun self-assigned this Sep 2, 2022
@wsy998
Copy link
Author

wsy998 commented Sep 5, 2022

OK,Let me try.

changkun added a commit that referenced this issue Dec 28, 2022
changkun added a commit that referenced this issue Dec 28, 2022
@mwalkerr
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants