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

Framework doesn't stick to any key codes standard but defines own one #41

Open
aleknasz opened this issue Mar 3, 2023 · 0 comments
Open

Comments

@aleknasz
Copy link

aleknasz commented Mar 3, 2023

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:

  • Gohook version (or commit ref): v0.40.0
  • Go version: 1.20
  • Gcc version: Apple clang version 14.0.0 (clang-1400.0.29.202)
  • Operating system and bit: MacOS Ventura 13.1
  • Resolution: None
  • Can you reproduce the bug: Yes
  • Provide example code:
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.

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

No branches or pull requests

1 participant