robotgo
robotgo copied to clipboard
KeyTap panic runtime from v1.0.0-beta4 : segmentation violation
- Robotgo version (or commit ref): v1.0.0-beta4 & v1.0.0-beta5
- Go version: 1.17.8
- Gcc version: 4.2.1
- Operating system and bit: macos 10.13.4, 64 bit
- Resolution:
- Can you reproduce the bug at Examples:
- [ ✔ ] Yes (provide example code)
- [ ] No
- [ ] Not relevant
- Provide example code:
package main
import (
"github.com/go-vgo/robotgo"
)
func main() {
robotgo.KeyTap("a")
}
- Log gist:
fatal error: unexpected signal during runtime execution [signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x41493b8]
runtime stack: runtime.throw({0x419b5c8, 0x470f3b0}) /Users/chenggang/sdk/go1.17.8/src/runtime/panic.go:1198 +0x71 runtime.sigpanic() /Users/chenggang/sdk/go1.17.8/src/runtime/signal_unix.go:719 +0x396
goroutine 1 [syscall]: runtime.cgocall(0x4149390, 0xc000129e08) /Users/chenggang/sdk/go1.17.8/src/runtime/cgocall.go:156 +0x5c fp=0xc000129de0 sp=0xc000129da8 pc=0x4003e9c github.com/go-vgo/robotgo._Cfunc_keyCodeForChar(0x61) _cgo_gotypes.go:696 +0x47 fp=0xc000129e08 sp=0xc000129de0 pc=0x4147ce7 github.com/go-vgo/robotgo.checkKeyCodes({0x4190e05, 0x418fcc0}) /Users/chenggang/go/pkg/mod/github.com/go-vgo/[email protected]/key.go:313 +0x7f fp=0xc000129e60 sp=0xc000129e08 pc=0x4147fff github.com/go-vgo/robotgo.keyTaps({0x4190e05, 0x1}, {0x0, 0x1, 0xee4322cf9c6}) /Users/chenggang/go/pkg/mod/github.com/go-vgo/[email protected]/key.go:371 +0x48 fp=0xc000129e90 sp=0xc000129e60 pc=0x4148588 github.com/go-vgo/robotgo.KeyTap({0x4190e05, 0x0}, {0x0, 0x0, 0x0}) /Users/chenggang/go/pkg/mod/github.com/go-vgo/[email protected]/key.go:466 +0x2ab fp=0xc000129f48 sp=0xc000129e90 pc=0x4148a4b main.main() /Users/chenggang/go/src/github.com/gangcheng1030/game_script/cmd/keyboard/keyboard.go:8 +0x2c fp=0xc000129f80 sp=0xc000129f48 pc=0x4148c8c runtime.main() /Users/chenggang/sdk/go1.17.8/src/runtime/proc.go:255 +0x227 fp=0xc000129fe0 sp=0xc000129f80 pc=0x4035b67 runtime.goexit() /Users/chenggang/sdk/go1.17.8/src/runtime/asm_amd64.s:1581 +0x1 fp=0xc000129fe8 sp=0xc000129fe0 pc=0x40621c1
Description
The same code work fine in v1.0.0-beta3, but panic in v1.0.0-beta4 and v1.0.0-beta5.
Have you solved the problem yet,I have the same problem.
I'm having the same issue as well. Any update on a fix for this? Bug is still present in v1.0.0-beta6. @xingcici and @gangcheng1030 were either of you able to find a solution to this issue?
@vcaesar this bug is preventing me from implementing a critical feature of my application. I know you guys are swamped so I'm attempting to track down the cause.
I have limited experience with Go's C package but I think it might be because key.go is missing the following header statement: #include "key/keycode_c.h".
This line makes a call to the keyCodeForChar function which I believe is located here but key.go isn't importing that file. Can you let me know if my assumption is correct? If so I can implement the fix and create a PR if that would be helpful.
Thanks,
- same issue to me. @vcaesar please
ok, i has fixed this problem.
Got the same problem on my mac
Golang info
go1.21.5 darwin/amd64
Gcc info
Apple clang version 15.0.0 (clang-1500.1.0.2.5) Target: x86_64-apple-darwin23.1.0 Thread model: posix
OS
macOS 14.1.2 amd64
It panics on both the latest tag and the latest commit (4d780b9).
code
package main
import (
"github.com/go-vgo/robotgo"
)
func main() {
robotgo.KeyTap("a")
}
panic info
SIGSEGV: segmentation violation PC=0x100155d28 m=0 sigcode=1 signal arrived during cgo execution
goroutine 1 [syscall]: runtime.cgocall(0x100155d00, 0xc0000f3cb8) /usr/local/go/src/runtime/cgocall.go:157 +0x4b fp=0xc0000f3c90 sp=0xc0000f3c58 pc=0x10000a78b github.com/go-vgo/robotgo._Cfunc_keyCodeForChar(0x6b) _cgo_gotypes.go:715 +0x46 fp=0xc0000f3cb8 sp=0xc0000f3c90 pc=0x100154486 github.com/go-vgo/robotgo.checkKeyCodes({0x1001c06b8?, 0x10032c840?}) /Users/franklee/go/pkg/mod/github.com/go-vgo/[email protected]/key.go:351 +0x85 fp=0xc0000f3d18 sp=0xc0000f3cb8 pc=0x1001547e5 github.com/go-vgo/robotgo.keyTaps({0x1001c06b8, 0x1}, {0x0?, 0x0?, 0x0?}, 0x0?) /Users/franklee/go/pkg/mod/github.com/go-vgo/[email protected]/key.go:409 +0x45 fp=0xc0000f3d50 sp=0xc0000f3d18 pc=0x100154ca5 github.com/go-vgo/robotgo.KeyTap({0x1001c06b8, 0x1}, {0x0?, 0x0?, 0x0?}) /Users/franklee/go/pkg/mod/github.com/go-vgo/[email protected]/key.go:528 +0x50a fp=0xc0000f3ef0 sp=0xc0000f3d50 pc=0x10015524a main.main() /Users/franklee/Workspace/go/tests/robot/main.go:36 +0x45 fp=0xc0000f3f40 sp=0xc0000f3ef0 pc=0x100155685 runtime.main() /usr/local/go/src/runtime/proc.go:267 +0x2bb fp=0xc0000f3fe0 sp=0xc0000f3f40 pc=0x10003d25b runtime.goexit() /usr/local/go/src/runtime/asm_amd64.s:1650 +0x1 fp=0xc0000f3fe8 sp=0xc0000f3fe0 pc=0x10006b981
goroutine 2 [force gc (idle)]: runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?) /usr/local/go/src/runtime/proc.go:398 +0xce fp=0xc000048fa8 sp=0xc000048f88 pc=0x10003d6ae runtime.goparkunlock(...) /usr/local/go/src/runtime/proc.go:404 runtime.forcegchelper() /usr/local/go/src/runtime/proc.go:322 +0xb3 fp=0xc000048fe0 sp=0xc000048fa8 pc=0x10003d533 runtime.goexit() /usr/local/go/src/runtime/asm_amd64.s:1650 +0x1 fp=0xc000048fe8 sp=0xc000048fe0 pc=0x10006b981 created by runtime.init.6 in goroutine 1 /usr/local/go/src/runtime/proc.go:310 +0x1a
goroutine 3 [GC sweep wait]: runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?) /usr/local/go/src/runtime/proc.go:398 +0xce fp=0xc000049778 sp=0xc000049758 pc=0x10003d6ae runtime.goparkunlock(...) /usr/local/go/src/runtime/proc.go:404 runtime.bgsweep(0x0?) /usr/local/go/src/runtime/mgcsweep.go:280 +0x94 fp=0xc0000497c8 sp=0xc000049778 pc=0x10002a374 runtime.gcenable.func1() /usr/local/go/src/runtime/mgc.go:200 +0x25 fp=0xc0000497e0 sp=0xc0000497c8 pc=0x10001f705 runtime.goexit() /usr/local/go/src/runtime/asm_amd64.s:1650 +0x1 fp=0xc0000497e8 sp=0xc0000497e0 pc=0x10006b981 created by runtime.gcenable in goroutine 1 /usr/local/go/src/runtime/mgc.go:200 +0x66
goroutine 4 [GC scavenge wait]: runtime.gopark(0xc00007a000?, 0x10020e7a0?, 0x1?, 0x0?, 0xc000007520?) /usr/local/go/src/runtime/proc.go:398 +0xce fp=0xc000049f70 sp=0xc000049f50 pc=0x10003d6ae runtime.goparkunlock(...) /usr/local/go/src/runtime/proc.go:404 runtime.(*scavengerState).park(0x10032c3c0) /usr/local/go/src/runtime/mgcscavenge.go:425 +0x49 fp=0xc000049fa0 sp=0xc000049f70 pc=0x100027c29 runtime.bgscavenge(0x0?) /usr/local/go/src/runtime/mgcscavenge.go:653 +0x3c fp=0xc000049fc8 sp=0xc000049fa0 pc=0x1000281bc runtime.gcenable.func2() /usr/local/go/src/runtime/mgc.go:201 +0x25 fp=0xc000049fe0 sp=0xc000049fc8 pc=0x10001f6a5 runtime.goexit() /usr/local/go/src/runtime/asm_amd64.s:1650 +0x1 fp=0xc000049fe8 sp=0xc000049fe0 pc=0x10006b981 created by runtime.gcenable in goroutine 1 /usr/local/go/src/runtime/mgc.go:201 +0xa5
goroutine 18 [finalizer wait]: runtime.gopark(0x198?, 0x1001bedc0?, 0x1?, 0xe8?, 0x0?) /usr/local/go/src/runtime/proc.go:398 +0xce fp=0xc000048620 sp=0xc000048600 pc=0x10003d6ae runtime.runfinq() /usr/local/go/src/runtime/mfinal.go:193 +0x107 fp=0xc0000487e0 sp=0xc000048620 pc=0x10001e727 runtime.goexit() /usr/local/go/src/runtime/asm_amd64.s:1650 +0x1 fp=0xc0000487e8 sp=0xc0000487e0 pc=0x10006b981 created by runtime.createfing in goroutine 1 /usr/local/go/src/runtime/mfinal.go:163 +0x3d
rax 0x0 rbx 0x0 rcx 0x28 rdx 0x28 rdi 0x11ee5c5308db436f rsi 0x600000850600 rbp 0x7ff7bfeff2e0 rsp 0x7ff7bfeff2c0 r8 0x11ee5c5308db436f r9 0x0 r10 0xffffffffffffffff r11 0x7fc972017800 r12 0x7ff7bfeff040 r13 0x924927f09249e97 r14 0xc0000f4000 r15 0x28 rip 0x100155d28 rflags 0x10246 cs 0x2b fs 0x0 gs 0x0
please help @vcaesar
same issue here
OS
macOS 13.3 M2
Go
go version go1.17.1 darwin/amd64
GCC
Apple clang version 14.0.3 (clang-1403.0.22.14.1)
Target: arm64-apple-darwin22.4.0
Thread model: posix
Debugged this for a while and it seems to be happening on the below line. It only affects single character key taps (a-z A-Z 0-9), as they are handled differently using C.keyCodeForChar().
https://github.com/go-vgo/robotgo/blob/4d780b990873c1dcf24779e5c07df161bc030f97/key.go#L351
I traced through keyCodeForChar and it seems to return a MMKeyCode as expected, and it appears to be valid as far as I can tell.
MMKeyCode: 0 for character: a
MMKeyCode: 16 for character: y
However, no Go code executes whatsoever after C.keyCodeForChar() is called.
I was finally able to get this working and no code change was required. Hopefully, others can confirm, and this issue can be closed.
You need to add GOOS=darwin GOARCH=arm64 CGO_ENABLED=1 when running on MacOS.
Code -
package main
import (
"github.com/go-vgo/robotgo"
)
func main() {
robotgo.KeyTap("a")
}
Command -
GOOS=darwin GOARCH=arm64 CGO_ENABLED=1 go run test.go