Code Monkey home page Code Monkey logo

Comments (6)

changkun avatar changkun commented on August 28, 2024

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

from hotkey.

wsy998 avatar wsy998 commented on August 28, 2024

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

from hotkey.

changkun avatar changkun commented on August 28, 2024

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

from hotkey.

changkun avatar changkun commented on August 28, 2024

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

from hotkey.

wsy998 avatar wsy998 commented on August 28, 2024

OK,Let me try.

from hotkey.

mwalkerr avatar mwalkerr commented on August 28, 2024

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

from hotkey.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.