You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hotkey shortcut monitoring will hijack the information of the shortcut key. When I run the following code, I copy a piece of text and paste it in the browser's search box. The information is hijacked, and it can only be paused when I end the program.
package main
import (
"golang.design/x/clipboard"
"log"
"sync"
"golang.design/x/hotkey"
"golang.design/x/hotkey/mainthread"
)
func main() {
mainthread.Init(fn)
}
func fn() {
err := clipboard.Init()
if err != nil {
panic(err)
}
wg := sync.WaitGroup{}
wg.Add(2)
go func() {
defer wg.Done()
for {
err := listenHotkey(hotkey.KeyC, hotkey.ModCtrl)
if err != nil {
log.Println(err)
}
}
}()
go func() {
defer wg.Done()
for {
err := listenHotkey(hotkey.KeyV, hotkey.ModCtrl)
if err != nil {
log.Println(err)
}
//imageData := clipboard.Read(clipboard.FmtImage)
//base64String := base64.StdEncoding.EncodeToString(imageData)
//log.Println(base64String)
textData := clipboard.Read(clipboard.FmtText)
log.Println(string(textData))
}
}()
wg.Wait()
}
func listenHotkey(key hotkey.Key, mods ...hotkey.Modifier) (err error) {
var ms []hotkey.Modifier
ms = append(ms, mods...)
hk := hotkey.New(ms, key)
err = hk.Register()
if err != nil {
return
}
<-hk.Keydown()
log.Printf("hotkey: %v is down\n", hk)
<-hk.Keyup()
log.Printf("hotkey: %v is up\n", hk)
hk.Unregister()
return
}
The text was updated successfully, but these errors were encountered:
Hotkey shortcut monitoring will hijack the information of the shortcut key. When I run the following code, I copy a piece of text and paste it in the browser's search box. The information is hijacked, and it can only be paused when I end the program.
The text was updated successfully, but these errors were encountered: