robotn / gohook Goto Github PK
View Code? Open in Web Editor NEWGoHook, Go global keyboard and mouse listener hook
License: MIT License
GoHook, Go global keyboard and mouse listener hook
License: MIT License
Gohook version (or commit ref):0.40.0
Go version:1.19
Gcc version:……
Operating system and bit:windows x64
Log gist:
gohook detect win、ctrl、alt、shift,but it shows by call hook.RawcodetoKeychar(ev.Rawcode) like l-super、$、؛、^,so i wanna know how to fix it
Using the code examples, having the following code
hook.Register(hook.KeyDown, []string{"w"}, func(e hook.Event) {
fmt.Println("w-")
run=false
})
hook.Register(hook.KeyHold, []string{"space"}, func(e hook.Event) { ww
run=true
})
hook.Register(hook.KeyUp, []string{"space"}, func(e hook.Event) {
run=false
})
If you press spacebar once, run is set to true, however on release it is still set to true, and only on pressing w it is set to false
Hi,
Sometimes when calling hook.End() the program is crashing (not always).
double free or corruption (out)
SIGABRT: abort
PC=0x7ff0e767e755 m=6 sigcode=18446744073709551610
Small example app which should reproduce the issue:
Seems crashing is more likely when the mouse is moved around while it is running.
func main() {
events := hook.Start()
go func() {
for {
event := <-events
fmt.Println(event)
}
}()
go func() {
for {
time.Sleep(100 * time.Millisecond)
hook.End()
time.Sleep(100 * time.Millisecond)
hook.Start()
}
}()
reader := bufio.NewReader(os.Stdin)
for {
input, _ := reader.ReadString('\n')
input = strings.Replace(input, "\n", "", -1)
if input == "quit" {
hook.End()
break
}
}
}
Running on linux, so X11.
I am using ubuntu 18.04 and go version 1.14 and gohook version v 0.30.3
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x7fc83fc0f215]
runtime stack:
runtime.throw(0xdf06d7, 0x2a)
/usr/local/go/src/runtime/panic.go:1116 +0x72
runtime.sigpanic()
/usr/local/go/src/runtime/signal_unix.go:679 +0x46a
goroutine 1498 [syscall, 1 minutes]:
runtime.cgocall(0xbeb450, 0xc001da47e0, 0xb26f74)
/usr/local/go/src/runtime/cgocall.go:133 +0x5b fp=0xc001da47b0 sp=0xc001da4778 pc=0x4386db
github.com/robotn/gohook._Cfunc_start_ev()
_cgo_gotypes.go:124 +0x41 fp=0xc001da47e0 sp=0xc001da47b0 pc=0xb259b1
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1373 +0x1 fp=0xc001da47e8 sp=0xc001da47e0 pc=0x498281
created by github.com/robotn/gohook.Start
/home/karthik/go/pkg/mod/github.com/robotn/[email protected]/hook.go:224 +0x67
I see some confusion or errors when listen keyboard on win10
Code:
package main
import (
"fmt"
hook "github.com/robotn/gohook"
)
func main() {
kind := map[uint8]string{3: "KeyDown", 4: "KeyHold", 5: "KeyUp"}
when := []uint8{hook.KeyDown, hook.KeyHold, hook.KeyUp}
for _, w := range when {
hook.Register(w, nil, func(e hook.Event) {
char := hook.RawcodetoKeychar(e.Rawcode)
fmt.Printf("Kind: %7v, Rawcode: %3v, Keychar: %5v, Keycode: %5v, Char: %v\n", kind[e.Kind], e.Rawcode, e.Keychar, e.Keycode, char)
})
}
s := hook.Start()
<-hook.Process(s)
}
When I press left shift, ctrl, alt and right alt, ctrl, shift, I get:
(which I guess take a wrong rawcode)
Kind: KeyHold, Rawcode: 160, Keychar: 65535, Keycode: 42, Char: ^
Kind: KeyUp, Rawcode: 160, Keychar: 65535, Keycode: 42, Char: ^
Kind: KeyHold, Rawcode: 162, Keychar: 65535, Keycode: 29, Char: ؛
Kind: KeyUp, Rawcode: 162, Keychar: 65535, Keycode: 29, Char: ؛
Kind: KeyHold, Rawcode: 164, Keychar: 65535, Keycode: 56, Char: $
Kind: KeyUp, Rawcode: 164, Keychar: 65535, Keycode: 56, Char: $
Kind: KeyHold, Rawcode: 165, Keychar: 65535, Keycode: 3640, Char: ù
Kind: KeyUp, Rawcode: 165, Keychar: 65535, Keycode: 3640, Char: ù
Kind: KeyHold, Rawcode: 163, Keychar: 65535, Keycode: 3613, Char: #
Kind: KeyUp, Rawcode: 163, Keychar: 65535, Keycode: 3613, Char: #
Kind: KeyHold, Rawcode: 161, Keychar: 65535, Keycode: 54, Char: !
Kind: KeyUp, Rawcode: 161, Keychar: 65535, Keycode: 54, Char: !
When I press tab, space, enter, backspace, I get:
(which rawcode cannot convert to keychar)
Kind: KeyHold, Rawcode: 9, Keychar: 65535, Keycode: 15, Char:
Kind: KeyDown, Rawcode: 9, Keychar: 9, Keycode: 0, Char:
Kind: KeyUp, Rawcode: 9, Keychar: 65535, Keycode: 15, Char:
Kind: KeyHold, Rawcode: 32, Keychar: 65535, Keycode: 57, Char:
Kind: KeyDown, Rawcode: 32, Keychar: 32, Keycode: 0, Char:
Kind: KeyUp, Rawcode: 32, Keychar: 65535, Keycode: 57, Char:
Kind: KeyHold, Rawcode: 13, Keychar: 65535, Keycode: 28, Char:
Kind: KeyDown, Rawcode: 13, Keychar: 13, Keycode: 0, Char:
Kind: KeyUp, Rawcode: 13, Keychar: 65535, Keycode: 28, Char:
Kind: KeyHold, Rawcode: 8, Keychar: 65535, Keycode: 14, Char:
Kind: KeyDown, Rawcode: 8, Keychar: 8, Keycode: 0, Char:
Kind: KeyUp, Rawcode: 8, Keychar: 65535, Keycode: 14, Char:
When I press something with esc, I get:
(which rawcode cannot convert to keychar, and erase a char after it when printing)
Kind: KeyHold, Rawcode: 66, Keychar: 65535, Keycode: 48, Char: b
Kind: KeyDown, Rawcode: 66, Keychar: 98, Keycode: 0, Char: b
Kind: KeyUp, Rawcode: 66, Keychar: 65535, Keycode: 48, Char: b
Kind: KeyHold, Rawcode: 65, Keychar: 65535, Keycode: 30, Char: a
Kind: KeyDown, Rawcode: 65, Keychar: 97, Keycode: 0, Char: a
Kind: KeyUp, Rawcode: 65, Keychar: 65535, Keycode: 30, Char: a
Kind: KeyHold, Rawcode: 67, Keychar: 65535, Keycode: 46, Char: c
Kind: KeyDown, Rawcode: 67, Keychar: 99, Keycode: 0, Char: c
Kind: KeyUp, Rawcode: 67, Keychar: 65535, Keycode: 46, Char: c
Kind: KeyHold, Rawcode: 27, Keychar: 65535, Keycode: 1, Char:
ind: KeyDown, Rawcode: 27, Keychar: 27, Keycode: 0, Char:
ind: KeyUp, Rawcode: 27, Keychar: 65535, Keycode: 1, Char:
ind: KeyHold, Rawcode: 65, Keychar: 65535, Keycode: 30, Char: a
Kind: KeyDown, Rawcode: 65, Keychar: 97, Keycode: 0, Char: a
Kind: KeyUp, Rawcode: 65, Keychar: 65535, Keycode: 30, Char: a
Other keys display just perfectly
There is still a problem, KeyUp cannot be triggered, and it may be triggered incorrectly.
hook.Register(hook.KeyUp, []string{"w"}, func(e hook.Event) {
// fmt.Println("hook(KeyUp): ", e)
ee, _ := json.Marshal(e)
fmt.Println("hook(KeyUp): ", string(ee))
fmt.Println("w")
})
When this code is run, pressing the ‘w’ key does not produce any response. But when q, w, e are pressed quickly in succession, it enters the KeyUp callback for w. However, at this time, the keycode for e is 16 (and this number represents the event corresponding to q)."
(Windows 11)
When you hold a mouse button (left == 1 for instance) and move the mouse events look like this:
hook: 0 2022-02-06 01:01:06.8846335 -0800 PST m=+9.886081101 - Event: {Kind: MouseHold, Button: 1, X: 1307, Y: 1232, Clicks: 1}
hook: 0 2022-02-06 01:01:07.6386065 -0800 PST m=+10.640054101 - Event: {Kind: MouseDrag, Button: 0, X: 1307, Y: 1233, Clicks: 0}
[...then a lot more of same... until one releases the button...]
hook: 0 2022-02-06 01:01:08.8920229 -0800 PST m=+11.893470501 - Event: {Kind: MouseDrag, Button: 0, X: 1487, Y: 1260, Clicks: 0}
[..this is the issue:...]
hook: 0 2022-02-06 01:01:09.2928355 -0800 PST m=+12.294283101 - Event: {Kind: MouseDown, Button: 1, X: 1487, Y: 1260, Clicks: 0}
hook: 0 2022-02-06 01:01:09.4931115 -0800 PST m=+12.494559101 - Event: {Kind: MouseMove, Button: 0, X: 1487, Y: 1259, Clicks: 0}
I'm pretty sure it should be MouseUp not MouseDown when one releases a button (like it does for KeyHold->KeyUp)?
Right now I'm working around using MouseDown for release (and I wonder who else) so we'd need to change the version tag once fixed
Thanks
Laurent
Gohook version (or commit ref):0.40.0
Go version:1.19
Gcc version:……
Operating system and bit:windows x64
Log gist:
Description
in windows,when i press windows+L to lock system , then the process of input password can not to be captured,so how should i capture keydown after locked
I use gohook in the project github.com/shortcut and publish it to macOS / Linux / Windows.
In macOS if I push some key and hold it will send multiple keyDown events altought I clicked only once and holding.
in Windows if I push some key without holding it send multiple keyDown events, if I hold then also same as macOS - multiple events are sent for simple hit on keys.
go version go1.22.0 darwin/arm64
Apple clang version 15.0.0 (clang-1500.1.0.2.5)
func registerShortcuts(shortcuts []Shortcut) {
for _, shortcut := range shortcuts {
fmt.Printf("Register shortcut %v\n", shortcut)
hook.Register(hook.KeyDown, shortcut.Keys, func(e hook.Event) {
fmt.Printf("Shortcut <%s> activated\n", shortcut.Name)
command := strings.Split(shortcut.Command, " ")
cmd := exec.Command(command[0], command[1:]...)
if err := cmd.Start(); err != nil {
fmt.Printf("Error executing command for shortcut <%s>: %v\n", shortcut.Name, err)
}
})
}
}
when i am using your library i am getting these error suddenly
i am getting this issue in windows10 64 bit can you help me this one
win_hook_event_proc [650]: setWindowsHookEx() failed! (0X486)
Hi, just a quick hint: The example in the README.md
does not work.
The import should probably be:
hook "github.com/robotn/gohook"
instead of just:
"github.com/robotn/gohook"
EDIT: I just saw there is a examples/main.go
file, with the correct code, but I can't get it to work as expected. Could you help me out? I modified it like this (just to add more visible output):
package main
import (
"fmt"
hook "github.com/robotn/gohook"
)
func addEvent() {
fmt.Println("--- Please press ctrl + shift + q to stop hook ---")
hook.Register(hook.KeyDown, []string{"q", "ctrl", "shift"}, func(e hook.Event) {
fmt.Println("ctrl-shift-q")
hook.End()
})
fmt.Println("--- Please press w---")
hook.Register(hook.KeyDown, []string{"w"}, func(e hook.Event) {
fmt.Println("wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww")
})
s := hook.Start()
<-hook.Process(s)
}
// hook listen and return values using detailed examples
func add() {
fmt.Println("hook add...")
s := hook.Start()
defer hook.End()
ct := false
for {
i := <-s
if i.Kind == hook.KeyHold && i.Rawcode == 59 {
ct = true
}
if ct && i.Rawcode == 12 {
break
}
}
}
// base hook example
func base() {
fmt.Println("hook start...")
evChan := hook.Start()
defer hook.End()
for ev := range evChan {
fmt.Println("hook: ", ev)
}
}
func main() {
addEvent()
base()
add()
}
The application runs, but whatever I do or press, I can't manage to print out the wwwwwwwwwwwwwwwwwwwwwwww
string. What is supposed to happen? Also, ctrl
+shift
+q
isn't doing anything either. Here is my output as I press w
a few times, then random other keys and lastly ctrl
+shift
+q
and ctrl+c
to quit:
Hi, I tried to register F6 by using this code
fmt.Println("Press F6")
hook.Register(hook.KeyDown, []string{"f6"}, func(e hook.Event) {
fmt.Println("F6 was pressed")
})
s := hook.Start()
<-hook.Process(s)
but it doesn't seem to work.
My question is, how do I register function keys? Thank you in advance.
AppData\Local\Temp\go-build188103574\b044_x003.o: In function eb_port_create': G:/go/src/github.com/robotn/gohook/chan/eb_chan.h:382: undefined reference to
sched_yield'
C:\Users\F1930235\AppData\Local\Temp\go-build188103574\b044_x003.o: In function eb_port_free': G:/go/src/github.com/robotn/gohook/chan/eb_chan.h:350: undefined reference to
sched_yield'
G:/go/src/github.com/robotn/gohook/chan/eb_chan.h:341: undefined reference to sched_yield' C:\Users\F1930235\AppData\Local\Temp\go-build188103574\b044\_x003.o: In function
cleanup_ops':
G:/go/src/github.com/robotn/gohook/chan/eb_chan.h:858: undefined reference to sched_yield' G:/go/src/github.com/robotn/gohook/chan/eb_chan.h:858: undefined reference to
sched_yield'
C:\Users\F1930235\AppData\Local\Temp\go-build188103574\b044_x003.o:G:/go/src/github.com/robotn/gohook/chan/eb_chan.h:643: more undefined references to `sched_yield' follow
Line 749 in a7a3894
如下的按键mask值也大于8
#define MASK_NUM_LOCK 1 << 13
#define MASK_CAPS_LOCK 1 << 14
#define MASK_SCROLL_LOCK 1 << 15
Xkb cannot locate a valid keyboard when running the exact same code found in Examples.
...
package main
import (
"fmt"
hook "github.com/robotn/gohook"
)
func main() {
// out: alt-q
hook.Register(hook.KeyDown, []string{"alt", "q"}, func(e hook.Event) {
fmt.Println("alt-q")
})
// out: no output
hook.Register(hook.KeyDown, []string{"up"}, func(e hook.Event) {
fmt.Println("up")
})
// out: no output
hook.Register(hook.KeyHold, []string{"left"}, func(e hook.Event) {
fmt.Println("left")
})
// out: no output
hook.Register(hook.KeyUp, []string{"down"}, func(e hook.Event) {
fmt.Println("down")
})
s := hook.Start()
<-hook.Process(s)
}
I'm sure there is nothing wrong with the keyboard, the following code prints out the keys normally
hook.Register(hook.KeyUp, []string{}, func(e hook.Event) {
fmt.Println(e)
})
...
The keycodes in raw2key
https://github.com/robotn/gohook/blob/master/tables.go#L4 are not correct for Mac. See link below for correct mac keys
https://eastmanreference.com/complete-list-of-applescript-key-codes
Gohook version (or commit ref):
latest
Go version:
go version go1.21.5 linux/amd64
Gcc version:
gcc (GCC) 13.2.1 20230801
Operating system and bit:
Linux archlinux 6.6.7-zen1-1-zen #1️⃣ ZEN SMP PREEMPT_DYNAMIC Thu, 14 Dec 2023 03:45:20 +0000 x86_64 GNU/Linux 64 bit
Resolution:
Can you reproduce the bug at [Examples]
yep
(https://github.com/robotn/gohook/blob/master/examples/main.go):
Provide example code:
func main(){
evC := hook.Start()
defer hook.End()
for e := range evC {
if e.Kind == 4 {
log.Printf("%v", e)
}
}
}
2023/12/26 14:29:36 2023-12-26 14:29:36.906394194 +0800 CST m=+227.566967666 - Event: {Kind: KeyHold, Rawcode: 65293, Keychar: 65535}
2023/12/26 14:29:37 2023-12-26 14:29:37.006881198 +0800 CST m=+227.667454600 - Event: {Kind: KeyHold, Rawcode: 65505, Keychar: 65535}
2023/12/26 14:29:37 2023-12-26 14:29:37.107568162 +0800 CST m=+227.768141564 - Event: {Kind: KeyHold, Rawcode: 62, Keychar: 65535}
2023/12/26 14:29:37 2023-12-26 14:29:37.559345436 +0800 CST m=+228.219918838 - Event: {Kind: KeyHold, Rawcode: 32, Keychar: 65535}
as you see , it will print the raw code when I press the key. but when I press the L
key , the log shows me a assemble was pressed: ctrl+l , it's raw code is: 108
.
I have tried much times , all the rawCode shows me the ctrl
key was pressed when I press any key.
Thanks!
Registering F12 triggers every function key (f1 to f12)
I've came across a really annoying bug. is that some keys like ctrl, alt, tab, shift, home, end ,delete, caps_lock keys, functions keys are not recognized and display the wrong keycode, keychar, rawcode.
In the following screenshot you can see, we're not able to obtain the correct keychar/rawcode for ctrl, alt, win key (as an example) are display unrecognized rawcode
You can also notice that Keycode is 0 in KeyDown event.
In Another example we can see the difference clearly. that the rawcode is totally undefined.
I've searched around the code and couldn't exactly find where these codes are coming from.
One other issue i've spotted is that some keys might have the correct keychar but wrong Rawcode like escape, backspace, enter
on keydown event but on up event is not even correct.
Here's a list of undefined keys and their respective rawcode.
Ctrl Left :: 65507 // Ctrl Right :: 65508
Windows/Meta Key :: 65515
Alt key :: 65513 // Alt Key Right 65514
Left shift :: 65505 // Right shift :: 65506
Caps Lock :: 65509 // Num Lock :: 65407
F1 :: 65470 // F2 :: 65471
F3 :: 65472 // F4 :: 65473
F5 :: 65474 // F6 :: 65475
F7 :: 65476 // F8 :: 65477
F9 :: 65478 // F10 :: 65479
F11 :: 65480 // F12 :: 65481
Delete :: 65535 // Insert :: 65379
End :: 65367 // Home :: 65360
Page Down :: 65366 // Page Up :: 65365
This issue on windows doesn't exist (sort of)
All these keys i've tried worked except CTRL (L 162 / R 163) , ALT (L 164 / R 165) , SHIFT (L 160 / R 161)
As titled. Rawcode: 125
is Arrow Down and the others are other arrows.
$ go run example/main.go
--- Please press ctrl + shift + q to stop hook ---
--- Please press w---
ctrl-shift-q
hook start...
hook: 2020-10-29 18:21:20.502464 +0900 JST m=+4.514493252 - Event: {Kind: HookEnabled}
hook: 2020-10-29 18:21:20.502482 +0900 JST m=+4.514510837 - Event: {Kind: KeyUp, Rawcode: 12, Keychar: 65535}
hook: 2020-10-29 18:21:20.610329 +0900 JST m=+4.622362170 - Event: {Kind: KeyUp, Rawcode: 59, Keychar: 65535}
hook: 2020-10-29 18:21:20.610347 +0900 JST m=+4.622380580 - Event: {Kind: KeyUp, Rawcode: 56, Keychar: 65535}
^[[Chook: 2020-10-29 18:21:25.652731 +0900 JST m=+9.664954525 - Event: {Kind: KeyDown, Rawcode: 124, Keychar: 29}
hook: 2020-10-29 18:21:25.652745 +0900 JST m=+9.664968877 - Event: {Kind: KeyHold, Rawcode: 124, Keychar: 65535}
hook: 2020-10-29 18:21:25.708012 +0900 JST m=+9.720237562 - Event: {Kind: KeyUp, Rawcode: 124, Keychar: 65535}
^[[Dhook: 2020-10-29 18:21:28.888841 +0900 JST m=+12.901185835 - Event: {Kind: KeyHold, Rawcode: 123, Keychar: 65535}
hook: 2020-10-29 18:21:28.888842 +0900 JST m=+12.901187556 - Event: {Kind: KeyDown, Rawcode: 123, Keychar: 28}
hook: 2020-10-29 18:21:28.997212 +0900 JST m=+13.009561845 - Event: {Kind: KeyUp, Rawcode: 123, Keychar: 65535}
^[[Ahook: 2020-10-29 18:21:37.633044 +0900 JST m=+21.645718726 - Event: {Kind: KeyHold, Rawcode: 126, Keychar: 65535}
hook: 2020-10-29 18:21:37.633055 +0900 JST m=+21.645729381 - Event: {Kind: KeyDown, Rawcode: 126, Keychar: 30}
hook: 2020-10-29 18:21:37.687625 +0900 JST m=+21.700301346 - Event: {Kind: KeyUp, Rawcode: 126, Keychar: 65535}
^[[Bhook: 2020-10-29 18:21:40.913595 +0900 JST m=+24.926393683 - Event: {Kind: KeyHold, Rawcode: 125, Keychar: 65535}
hook: 2020-10-29 18:21:40.965137 +0900 JST m=+24.977936924 - Event: {Kind: KeyUp, Rawcode: 125, Keychar: 65535}
hook: 2020-10-29 18:21:46.670449 +0900 JST m=+30.683463769 - Event: {Kind: KeyHold, Rawcode: 125, Keychar: 65535}
^[[Bhook: 2020-10-29 18:21:46.775177 +0900 JST m=+30.788196695 - Event: {Kind: KeyUp, Rawcode: 125, Keychar: 65535}
^[[Bhook: 2020-10-29 18:21:50.221418 +0900 JST m=+34.234566667 - Event: {Kind: KeyHold, Rawcode: 125, Keychar: 65535}
Cannot compile on Fedora Workstation 34, which uses Wayland. It looks like it's requiring headers from the X11 subsystem:
$ go get -v github.com/robotn/gohook
go: downloading github.com/robotn/gohook v0.30.5
github.com/robotn/gohook
# github.com/robotn/gohook
In file included from ./event/pub.h:20,
from ./event/goEvent.h:18,
from ../../../go/pkg/mod/github.com/robotn/[email protected]/hook.go:22:
./event/../hook/x11/input_c.h:40:10: fatal error: xkbcommon/xkbcommon-x11.h: No such file or directory
40 | #include <xkbcommon/xkbcommon-x11.h>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
s := hook.Start()
defer hook.End()
for {
select {
case i:= <- s :
fmt.Printf("%s \n", i)
}
I wrote it like the above code and proceeded with the test.
The only result I want is HOLD or DOWN while I'm pressing TAB, But I've seen that UP/DOWN//HOLD is constantly output.
How do I solve this problem?
I've been trying to use the channel gohook provides over multiple goroutines. Is this possible? It hasn't been working for me. Maybe a cgo issue
Hi All, I have used robotn/gohook in my app by registering hook and consuming events - key down, key hold and key up
However I don't think I can write cross-platform application. Below is my explanation:
chanHook := hook.Start()
defer hook.End()
go captureEvents(chanHook)
func captureEvents(chanHook <-chan hook.Event) {
for ev := range chanHook {
if ev.Kind == hook.KeyUp {
fmt.Printf("key up: rawcode=%d rawcode=0x%x keycode=%d keycode=0x%x keychar=%d keychar=0x%x\n\n",
ev.Rawcode, ev.Rawcode, ev.Keycode, ev.Keycode, ev.Keychar, ev.Keychar)
} else if ev.Kind == hook.KeyDown {
fmt.Printf("-----")
fmt.Printf("key down: rawcode=%d rawcode=0x%x keycode=%d keycode=0x%x keychar=%d keychar=0x%x\n\n",
ev.Rawcode, ev.Rawcode, ev.Keycode, ev.Keycode, ev.Keychar, ev.Keychar)
} else if ev.Kind == hook.KeyHold {
fmt.Printf("key hold: rawcode=%d rawcode=0x%x keycode=%d keycode=0x%x keychar=%d keychar=0x%x\n\n",
ev.Rawcode, ev.Rawcode, ev.Keycode, ev.Keycode, ev.Keychar, ev.Keychar)
}
}
}
// The console output is
// when pressed spacebar
key hold: rawcode=49 rawcode=0x31 keycode=57 keycode=0x39 keychar=65535 keychar=0xffff
key down: rawcode=49 rawcode=0x31 keycode=0 keycode=0x0 keychar=32 keychar=0x20
key up: rawcode=49 rawcode=0x31 keycode=57 keycode=0x39 keychar=65535 keychar=0xffff
// when pressed key a
key hold: rawcode=0 rawcode=0x0 keycode=30 keycode=0x1e keychar=65535 keychar=0xffff
key down: rawcode=0 rawcode=0x0 keycode=0 keycode=0x0 keychar=97 keychar=0x61
key up: rawcode=0 rawcode=0x0 keycode=30 keycode=0x1e keychar=65535 keychar=0xffff
// when pressed left arrow
key hold: rawcode=123 rawcode=0x7b keycode=57419 keycode=0xe04b keychar=65535 keychar=0xffff
key down: rawcode=123 rawcode=0x7b keycode=0 keycode=0x0 keychar=28 keychar=0x1c
key up: rawcode=123 rawcode=0x7b keycode=57419 keycode=0xe04b keychar=65535 keychar=0xffff
// when pressed right shift (note missing down event)
key hold: rawcode=60 rawcode=0x3c keycode=54 keycode=0x36 keychar=65535 keychar=0xffff
key up: rawcode=60 rawcode=0x3c keycode=54 keycode=0x36 keychar=65535 keychar=0xffff
// when left shit pressed
key hold: rawcode=56 rawcode=0x38 keycode=42 keycode=0x2a keychar=65535 keychar=0xffff
key up: rawcode=56 rawcode=0x38 keycode=42 keycode=0x2a keychar=65535 keychar=0xffff
As you can see, the right and left shift has no down event. Also the order of events is strange. Why hold before down?. The "a" key can't be read as standard "a", since the code is not byte 65, the spacebar has hex code 0x20, which is almost ok, but only in hold event. The left arrow should have hex value 0x25.
Actually there is no consistency in events and the values which are populated and attributes which are populated are misleading.
Since the gohook is suppose to be cross-platform, we should have also some cross-platform keystroke values.
Just stick to some standards defined by bigger companies like Mozilla - https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode. Why not Microsoft or Apple? Because Mozilla had always web browsers in mind and try to write cross-platform software.
when i press q, will print
press q
ctrl-q
`package main
import (
"fmt"
"github.com/MakeNowJust/hotkey"
hook "github.com/robotn/gohook"
)
func main() {
hook.Register(hook.KeyUp, nil, func(e hook.Event) {
if hook.RawcodetoKeychar(uint16(e.Rawcode)) == "q" {
fmt.Println("press q")
}
})
hook.Register(hook.KeyUp, []string{"q"}, func(e hook.Event) {
fmt.Println("q")
})
hook.Register(hook.KeyDown, []string{"q", "ctrl"}, func(e hook.Event) {
fmt.Println("ctrl-q")
})
s := hook.Start()
<-hook.Process(s)
hook.Register(hook.MouseDown, []string{}, func(e hook.Event) {
log.Println("mouse down:",e.Button,hook.MouseMap["right"])
})
Click mouse right key on Windows and MacOS display e.button is 2,
ubuntu20.04 is 3
as title
func add() {
hook.Register(hook.KeyDown, []string{"a"}, func(e hook.Event) {
fmt.Println("test")
})
}
reacts on everyting except a
I am working on a virtual keyboard mouse application and require to block the keyboard and mouse input to the host system when mouse control is used for a client system. For that I require blocking the input system wide. Is it possible in the library to achieve that.
github.com\go-vgo[[email protected]](https://blog.csdn.net/a1309525802/article/details/[email protected])\hook.go:98:17: invalid operation: geve == 0 (mismatched types bool and untyped int)
Hi, i'm on linux and when i run the following command GOOS=windows go test -c
in this repository i go these errors:
# github.com/robotn/gohook [github.com/robotn/gohook.test]
./hook_test.go:13:7: undefined: Start
./hook_test.go:18:7: undefined: RawcodetoKeychar
./hook_test.go:21:7: undefined: KeychartoRawcode
Same when i try to crosscompile my project with depend on gohook
Is there any way to consume events to prevent farther propagation to windows (disabling alt+tab, windows key for example)?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.