micmonay / keybd_event Goto Github PK
View Code? Open in Web Editor NEWFor simulate key press in Linux, Windows and Mac in golang
License: MIT License
For simulate key press in Linux, Windows and Mac in golang
License: MIT License
(I am really new to Go so I made probably the Mistake so sorry if I wasted your time) When I wanted to install this Package with the "go get github.com/micmonay/keybd_event" it didnt worked, my folder-structur looks like this:
folder_structur.txt
Hi!
Thank you for developing this.
Attempting to build a tool using keybd_event inside a docker container failed.
I build on the Mac OS and build success.
I don't know the cause of the error.
$ docker build -t skanehira/docui . 933ms
Sending build context to Docker daemon 70.03MB
Step 1/13 : FROM golang:1.12.8 AS build-docui
1.12.8: Pulling from library/golang
4ae16bd47783: Already exists
bbab4ec87ac4: Already exists
2ea1f7804402: Already exists
96465440c208: Already exists
16a3d8aca6cd: Pull complete
a04ada715f6e: Pull complete
255e23a40665: Pull complete
Digest: sha256:2a5dc837ac980ba4576dcb838dfb3710675d72e56debbd9bccea2607626317d8
Status: Downloaded newer image for golang:1.12.8
---> 8a91d9dc9d09
Step 2/13 : ENV GOPATH /go
---> Running in 00a4cef1741b
Removing intermediate container 00a4cef1741b
---> 10f60ec92652
Step 3/13 : ENV GOOS linux
---> Running in 69c7e0be9afd
Removing intermediate container 69c7e0be9afd
---> da9d6cb6cc5c
Step 4/13 : ENV GOARCH amd64
---> Running in 581c84b966f8
Removing intermediate container 581c84b966f8
---> 962ef2577ada
Step 5/13 : ENV CGO_ENABLED 0
---> Running in b73061e695a2
Removing intermediate container b73061e695a2
---> 77193a47df78
Step 6/13 : ENV GO111MODULE on
---> Running in 94b86a2bbfb1
Removing intermediate container 94b86a2bbfb1
---> 644fbf1358af
Step 7/13 : ENV TERM xterm-256color
---> Running in 9551f6ac6cd4
Removing intermediate container 9551f6ac6cd4
---> bd443ee96d37
Step 8/13 : COPY . ./src/github.com/skanehira/docui
---> a5c579bf9dc7
Step 9/13 : WORKDIR /go/src/github.com/skanehira/docui
---> Running in 385c10239283
Removing intermediate container 385c10239283
---> df2a4ab18f12
Step 10/13 : RUN go build
---> Running in 1d27e17447b4
go: finding github.com/micmonay/keybd_event v0.0.0-20190804163414-202c5b2c8150
go: finding github.com/google/go-cmp v0.2.0
go: finding github.com/docker/go-units v0.3.3
go: finding github.com/docker/go-connections v0.4.0
go: finding github.com/konsorten/go-windows-terminal-sequences v1.0.2
go: finding github.com/Microsoft/go-winio v0.4.11
go: finding github.com/opencontainers/image-spec v1.0.1
go: finding github.com/opencontainers/go-digest v1.0.0-rc1
go: finding golang.org/x/time v0.0.0-20181108054448-85acf8d2951c
go: finding google.golang.org/grpc v1.18.0
go: finding github.com/rivo/uniseg v0.0.0-20190313204849-f699dde9c340
go: finding github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78
go: finding github.com/docker/docker v0.7.3-0.20190111153827-295413c9d0e1
go: finding github.com/gorilla/mux v1.7.0
go: finding github.com/lucasb-eyer/go-colorful v1.0.1
go: finding github.com/mitchellh/go-homedir v1.1.0
go: finding github.com/gdamore/tcell v1.1.1
go: finding golang.org/x/text v0.3.2
go: finding github.com/rivo/tview v0.0.0-20190324182152-8a9e26fab0ff
go: finding gotest.tools v2.2.0+incompatible
go: finding golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be
go: finding golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52
go: finding github.com/stretchr/testify v1.3.0
go: finding github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5
go: finding github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d
go: finding cloud.google.com/go v0.26.0
go: finding github.com/DATA-DOG/go-sqlmock v1.3.3
go: finding github.com/mattn/go-runewidth v0.0.4
go: finding honnef.co/go/tools v0.0.0-20180728063816-88497007e858
go: finding github.com/client9/misspell v0.3.4
go: finding golang.org/x/sys v0.0.0-20190428183149-804c0c7841b5
go: finding github.com/golang/protobuf v1.2.0
go: finding golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e
go: finding google.golang.org/appengine v1.1.0
go: finding github.com/golang/mock v1.1.1
go: finding github.com/lucasb-eyer/go-colorful v0.0.0-20181028223441-12d3b2882a08
go: finding github.com/docker/distribution v2.7.1+incompatible
go: finding google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8
go: finding github.com/stretchr/objx v0.1.0
go: finding golang.org/x/text v0.3.0
go: finding github.com/gogo/protobuf v1.2.0
go: finding github.com/davecgh/go-spew v1.1.0
go: finding github.com/sirupsen/logrus v1.4.1
go: finding golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f
go: finding github.com/pkg/errors v0.8.1
go: finding github.com/pmezard/go-difflib v1.0.0
go: finding gopkg.in/DATA-DOG/go-sqlmock.v1 v1.3.0
go: finding golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3
go: finding golang.org/x/sync v0.0.0-20190423024810-112230192c58
go: finding golang.org/x/sys v0.0.0-20180830151530-49385e6e1522
go: finding github.com/jroimartin/gocui v0.4.0
go: finding github.com/gdamore/encoding v1.0.0
go: finding github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
go: finding golang.org/x/net v0.0.0-20180826012351-8a410e7b638d
go: finding golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33
go: finding github.com/stretchr/objx v0.1.1
go: finding github.com/stretchr/testify v1.2.2
go: finding github.com/davecgh/go-spew v1.1.1
go: finding github.com/kisielk/gotool v1.0.0
go: finding golang.org/x/net v0.0.0-20190424112056-4829fb13d2c6
go: finding github.com/konsorten/go-windows-terminal-sequences v1.0.1
go: finding golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2
go: finding golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a
go: downloading github.com/docker/docker v0.7.3-0.20190111153827-295413c9d0e1
go: downloading github.com/micmonay/keybd_event v0.0.0-20190804163414-202c5b2c8150
go: downloading github.com/sirupsen/logrus v1.4.1
go: downloading github.com/mitchellh/go-homedir v1.1.0
go: downloading github.com/rivo/tview v0.0.0-20190324182152-8a9e26fab0ff
go: extracting github.com/micmonay/keybd_event v0.0.0-20190804163414-202c5b2c8150
go: extracting github.com/mitchellh/go-homedir v1.1.0
go: extracting github.com/sirupsen/logrus v1.4.1
go: downloading github.com/jroimartin/gocui v0.4.0
go: extracting github.com/jroimartin/gocui v0.4.0
go: extracting github.com/rivo/tview v0.0.0-20190324182152-8a9e26fab0ff
go: extracting github.com/docker/docker v0.7.3-0.20190111153827-295413c9d0e1
go: downloading github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d
go: downloading golang.org/x/sys v0.0.0-20190428183149-804c0c7841b5
go: downloading github.com/gdamore/tcell v1.1.1
go: downloading github.com/mattn/go-runewidth v0.0.4
go: downloading github.com/lucasb-eyer/go-colorful v1.0.1
go: downloading github.com/docker/go-units v0.3.3
go: downloading github.com/pkg/errors v0.8.1
go: extracting github.com/mattn/go-runewidth v0.0.4
go: downloading github.com/opencontainers/go-digest v1.0.0-rc1
go: downloading github.com/docker/go-connections v0.4.0
go: downloading github.com/rivo/uniseg v0.0.0-20190313204849-f699dde9c340
go: extracting github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d
go: downloading github.com/docker/distribution v2.7.1+incompatible
go: extracting github.com/docker/go-units v0.3.3
go: downloading github.com/opencontainers/image-spec v1.0.1
go: extracting github.com/pkg/errors v0.8.1
go: extracting github.com/lucasb-eyer/go-colorful v1.0.1
go: extracting github.com/docker/go-connections v0.4.0
go: downloading github.com/gogo/protobuf v1.2.0
go: extracting github.com/opencontainers/go-digest v1.0.0-rc1
go: downloading golang.org/x/net v0.0.0-20190424112056-4829fb13d2c6
go: extracting github.com/rivo/uniseg v0.0.0-20190313204849-f699dde9c340
go: extracting github.com/opencontainers/image-spec v1.0.1
go: extracting github.com/gdamore/tcell v1.1.1
go: extracting golang.org/x/sys v0.0.0-20190428183149-804c0c7841b5
go: extracting github.com/docker/distribution v2.7.1+incompatible
go: downloading github.com/gdamore/encoding v1.0.0
go: downloading golang.org/x/text v0.3.2
go: extracting github.com/gdamore/encoding v1.0.0
go: extracting golang.org/x/net v0.0.0-20190424112056-4829fb13d2c6
go: extracting github.com/gogo/protobuf v1.2.0
go: extracting golang.org/x/text v0.3.2
# github.com/micmonay/keybd_event
/go/pkg/mod/github.com/micmonay/[email protected]/keybd_event.go:19:9: undefined: initKeyB
Does you know anything?
Is that a limitation of the OS or my mistake but alt-tab seems to do nothing:
kb.Clear()
kb.SetKeys(keybd_event.VK_TAB)
kb.HasALT(true)
err := kb.Launching()
Same with .Press() .Release()
go: downloading github.com/micmonay/keybd_event v1.1.0
verifying github.com/micmonay/[email protected]: checksum mismatch
downloaded: h1:M9GwE6u6aZTmXMBK9GPXcdaF1Drd6QyBs9cKEEJNs6A=
go.sum: h1:fQzkqiG/Siwji1Ju9NDkIb8FSFFlPU76YbJntrXdtQw=
SECURITY ERROR
This download does NOT match an earlier download recorded in go.sum.
The bits may have been replaced on the origin server, or an attacker may
have intercepted the download attempt.
For more information, see 'go help module-auth'.
Did you change release v1.1.0 after releasing it?
I got some errors related to C code while trying to compile app. How can I fix it?
macOS version: 12.3 (21E230)
CPU: M1 Max
XCode version: 13.3 (13E113)
GoLang version: go version go1.17.4 darwin/arm64
Compiler logs: https://pastebin.com/M2S7w2QT
=== RUN ExampleNewKeyBonding
--- FAIL: ExampleNewKeyBonding (2.00s)
got:
want:
AB
FAIL
exit status 1
FAIL github.com/micmonay/keybd_event 2.068s
dh_auto_test: go test -v -p 8 github.com/micmonay/keybd_event returned exit code 1
make: *** [build] Error 1
Not really sure what's happening here. Looks like it can't a reference for that var.
GOROOT=/usr/local/go #gosetup
GOPATH=/Users/leki/go #gosetup
/usr/local/go/bin/go build -o /private/var/folders/1h/j6ckgx_n6td25545c0w84kn00000gn/T/GoLand/___go_build_github_com_zLeki_JJBot github.com/zLeki/JJBot #gosetup
github.com/micmonay/keybd_event
../../../go/pkg/mod/github.com/micmonay/[email protected]/keybd_darwin.go:73:2: could not determine kind of name for C.AddActionKey
../../../go/pkg/mod/github.com/micmonay/[email protected]/keybd_darwin.go:69:18: could not determine kind of name for C.CGEventRef
../../../go/pkg/mod/github.com/micmonay/[email protected]/keybd_darwin.go:85:15: could not determine kind of name for C.CreateDown
../../../go/pkg/mod/github.com/micmonay/[email protected]/keybd_darwin.go:110:13: could not determine kind of name for C.CreateUp
../../../go/pkg/mod/github.com/micmonay/[email protected]/keybd_darwin.go:107:2: could not determine kind of name for C.KeyTap
../../../go/pkg/mod/github.com/micmonay/[email protected]/keybd_darwin.go:27:21: could not determine kind of name for C.kCGEventFlagMaskAlphaShift
../../../go/pkg/mod/github.com/micmonay/[email protected]/keybd_darwin.go:30:21: could not determine kind of name for C.kCGEventFlagMaskAlternate
../../../go/pkg/mod/github.com/micmonay/[email protected]/keybd_darwin.go:31:21: could not determine kind of name for C.kCGEventFlagMaskCommand
../../../go/pkg/mod/github.com/micmonay/[email protected]/keybd_darwin.go:29:21: could not determine kind of name for C.kCGEventFlagMaskControl
../../../go/pkg/mod/github.com/micmonay/[email protected]/keybd_darwin.go:32:21: could not determine kind of name for C.kCGEventFlagMaskHelp
../../../go/pkg/mod/github.com/micmonay/[email protected]/keybd_darwin.go:35:21: could not determine kind of name for C.kCGEventFlagMaskNonCoalesced
../../../go/pkg/mod/github.com/micmonay/[email protected]/keybd_darwin.go:34:21: could not determine kind of name for C.kCGEventFlagMaskNumericPad
../../../go/pkg/mod/github.com/micmonay/[email protected]/keybd_darwin.go:33:21: could not determine kind of name for C.kCGEventFlagMaskSecondaryFn
../../../go/pkg/mod/github.com/micmonay/[email protected]/keybd_darwin.go:28:21: could not determine kind of name for C.kCGEventFlagMaskShift
cgo:
clang errors for preamble:
../../../go/pkg/mod/github.com/micmonay/[email protected]/keybd_darwin.go:7:2: error: unknown type name 'CGEventRef'
CGEventRef CreateDown(int k){
^
../../../go/pkg/mod/github.com/micmonay/[email protected]/keybd_darwin.go:8:2: error: use of undeclared identifier 'CGEventRef'
CGEventRef event = CGEventCreateKeyboardEvent (NULL, (CGKeyCode)k, true);
^
../../../go/pkg/mod/github.com/micmonay/[email protected]/keybd_darwin.go:9:9: error: use of undeclared identifier 'event'
return event;
^
../../../go/pkg/mod/github.com/micmonay/[email protected]/keybd_darwin.go:11:2: error: unknown type name 'CGEventRef'
CGEventRef CreateUp(int k){
^
../../../go/pkg/mod/github.com/micmonay/[email protected]/keybd_darwin.go:12:2: error: use of undeclared identifier 'CGEventRef'
CGEventRef event = CGEventCreateKeyboardEvent (NULL, (CGKeyCode)k, false);
^
../../../go/pkg/mod/github.com/micmonay/[email protected]/keybd_darwin.go:13:9: error: use of undeclared identifier 'event'
return event;
^
../../../go/pkg/mod/github.com/micmonay/[email protected]/keybd_darwin.go:15:14: error: unknown type name 'CGEventRef'
void KeyTap(CGEventRef event){
^
../../../go/pkg/mod/github.com/micmonay/[email protected]/keybd_darwin.go:16:14: error: use of undeclared identifier 'kCGAnnotatedSessionEventTap'
CGEventPost(kCGAnnotatedSessionEventTap, event);
^
../../../go/pkg/mod/github.com/micmonay/[email protected]/keybd_darwin.go:19:20: error: unknown type name 'CGEventFlags'; did you mean 'MPEventFlags'?
void AddActionKey(CGEventFlags type,CGEventRef event){
^~~~~~~~~~~~
MPEventFlags
/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework/Headers/Multiprocessing.h:119:41: note: 'MPEventFlags' declared here
typedef UInt32 MPEventFlags;
^
../../../go/pkg/mod/github.com/micmonay/[email protected]/keybd_darwin.go:19:38: error: unknown type name 'CGEventRef'
void AddActionKey(CGEventFlags type,CGEventRef event){
^
10 errors generated.
Compilation finished with exit code 2
using example code from main page ubuntu 22.04/1 LTS
go version go1.21.1 linux/amd64
package main
import (
"runtime"
"time"
"github.com/micmonay/keybd_event"
)
func main() {
kb, err := keybd_event.NewKeyBonding()
if err != nil {
panic(err)
}
// For linux, it is very important to wait 2 seconds
if runtime.GOOS == "linux" {
time.Sleep(2 * time.Second)
}
// Select keys to be pressed
kb.SetKeys(keybd_event.VK_A, keybd_event.VK_B)
// Set shift to be pressed
kb.HasSHIFT(true)
// Press the selected keys
err = kb.Launching()
if err != nil {
panic(err)
}
// Or you can use Press and Release
kb.Press()
time.Sleep(10 * time.Millisecond)
kb.Release()
// Here, the program will generate "ABAB" as if they were pressed on the keyboard.
}
$ go build .
../../go/pkg/mod/github.com/micmonay/[email protected]/keybd_event.go:20:9: undefined: initKeyBD
Hello, guys!
Can i somehow emulate hold button functionality on macOs without repeating "keypress"?
Desirable result after this code
kb.SetKeys(keybd_event.VK_D)
kb.Press()
is continuously adding a letter 'D' in any text editable zone until kb.Release()
will be called.
May be you can prompt me what macOs API I can use for it?
kb.SetKeys(keybd_event.VK_CAPSLOCK)
kb.SetKeys(keybd_event.VK_A)
kb.Launching()
kb.Clear()
kb.SetKeys(keybd_event.VK_CAPSLOCK)
kb.SetKeys(keybd_event.VK_A)
kb.Launching()
output:
aa
Hi! I find this library very useful for accessibility automation. I am thinking it'd also be very useful to be able to send mouse click down/up events for this purpose. What do you think about the level of effort to add that?
Hello, when using this package I found that the latency for making keypresses is much greater on MacOS than on Linux, to the point where it is a problem for my project. Is there any ways to reduce the time it takes to make a keypress? If you want I can provide a minimum viable example for where i find the latency to be too high.
Thanks
$ go version
go version go1.15.6 darwin/amd64
$ uname -a
Darwin Olavs-MBP 19.6.0 Darwin Kernel Version 19.6.0: Thu Oct 29 22:56:45 PDT 2020; root:xnu-6153.141.2.2~1/RELEASE_X86_64 x86_64
Hi. I tried to type the "#" key by using "kb.HasShift(true)" + "keybd_event.VK_3" which is how I would do it on my Swedish keyboard. How can I get the "#" typed? I can't figure it out so any help would be appreciated :)
What I mean by that that most of the keys (A-Z, space) on Windows are instantly released after executing Press
method. Strangely, keys like shift stay pressed. Here is my code that I tested that on:
package main
import (
"fmt"
"runtime"
"time"
"github.com/micmonay/keybd_event"
)
func main() {
kb, err := keybd_event.NewKeyBonding()
if err != nil {
panic(err)
}
// For linux, it is very important to wait 2 seconds
if runtime.GOOS == "linux" {
time.Sleep(2 * time.Second)
}
// Select keys to be pressed
kb.SetKeys(keybd_event.VK_A)
// Set shift to be pressed
kb.HasSHIFT(true)
// Give user a bit of time to switch windows
fmt.Println("Switch windows now!")
time.Sleep(5 * time.Second)
// Press keys for 5 seconds
fmt.Println("Pressing keys!")
kb.Press()
time.Sleep(5 * time.Second)
kb.Release()
}
Keys specified in SetKeys
method stay pressed after invoking Press
method until Release
method is executed.
The keyboard input I would like to get:
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...
The keys specified in SetKeys
method are instantly released after executing Press
method. I can manually press the key before the Release
function is called and it will be typed out as if that key wasn't pressed.
The keyboard input I actuallly get:
A
Strangely, the shift key stays pressed until the Release
method is called and that's what it should be for all the other keys.
This is the command I used:
GOOS=linux GOARCH=386 go build -o bin/app-386-linux app.go
This is the error I get:
# github.com/micmonay/keybd_event ../go/pkg/mod/github.com/micmonay/[email protected]/keybd_event.go:20:9: undefined: initKeyBD
I'm trying to press FN key on macOS
I looks it's already implemented in keybd_darwin.go _VK_FN = C.kCGEventFlagMaskSecondaryFn
,
but I can't use it SetKeys method, there's no method like UseShift too.
How can I press Function key?
// Found VK.Function, nvm
Hi,
Thank you for your work, this saves time :)
By default the keys seems to be pressed on os.Stdin is it possible to specify another stdin?
Use case: having multiple os/exec programs and need to send specific keys to a specific stdin that's being fed to that specific program
Hope it's clear :)
Shift + arrow sending only arrow key. E.g.:
kb.SetKeys(keybd_event.VK_LEFT)
kb.HasSHIFT(true)
kb.Press()
time.Sleep(10 * time.Millisecond)
kb.Release()
sends left key press without shift (easy check: in any textfield it should select text, not just move caret).
Im looking for a way to find the key int value by its name, because the SetKeys
function requires ints. I know I can do keybd_events.VK_SP1
but what if i want to get the key based on a string variable? (keyName := "VK_SP1"
)
Code works perfectly locally, however, over a remote connection (like SSH), I get nadda.
It's just a basic Ubuntu install. I've tried via MobaXterm, Putty, Windows CMD, etc... All give same results.
Any help would be a life-saver.
I have tried the code in the example on Mac, but nothing gets printed out. The same code works fine on Windows.
Thanx for this library !
I just wanted to mention that it would be useful to add support for azerty, dvorak and other types of keyboards.
Im using this library in a project but I cant seem to get it compiled for som platforms:
root@5c3afb402c7b:/go/src/github.com/odino/touchy# env GOOS=darwin GOARCH=amd64 go build -v github.com/odino/touchy
runtime
math
errors
unicode/utf8
sync/atomic
unicode
crypto/subtle
sort
sync
container/list
io
syscall
hash
hash/crc32
crypto/cipher
crypto/hmac
bytes
strings
strconv
bufio
time
math/rand
internal/singleflight
path
encoding
unicode/utf16
github.com/micmonay/keybd_event
reflect
crypto
# github.com/micmonay/keybd_event
../../micmonay/keybd_event/keybd_event.go:22: undefined: initKeyBD
ie. this is the output using gox
:
Number of parallel builds: 3
--> netbsd/arm: github.com/odino/touchy
--> darwin/386: github.com/odino/touchy
--> darwin/amd64: github.com/odino/touchy
--> openbsd/386: github.com/odino/touchy
--> linux/386: github.com/odino/touchy
--> linux/amd64: github.com/odino/touchy
--> linux/arm: github.com/odino/touchy
--> freebsd/386: github.com/odino/touchy
--> freebsd/amd64: github.com/odino/touchy
--> windows/amd64: github.com/odino/touchy
--> openbsd/amd64: github.com/odino/touchy
--> windows/386: github.com/odino/touchy
--> netbsd/386: github.com/odino/touchy
--> freebsd/arm: github.com/odino/touchy
--> netbsd/amd64: github.com/odino/touchy
12 errors occurred:
--> darwin/amd64 error: exit status 2
Stderr: # github.com/micmonay/keybd_event
../../micmonay/keybd_event/keybd_event.go:22: undefined: initKeyBD
--> darwin/386 error: exit status 2
Stderr: # github.com/micmonay/keybd_event
../../micmonay/keybd_event/keybd_event.go:22: undefined: initKeyBD
--> netbsd/arm error: exit status 2
Stderr: # github.com/micmonay/keybd_event
../../micmonay/keybd_event/keybd_event.go:22: undefined: initKeyBD
--> openbsd/386 error: exit status 2
Stderr: # github.com/micmonay/keybd_event
../../micmonay/keybd_event/keybd_event.go:22: undefined: initKeyBD
--> linux/386 error: exit status 2
Stderr: # github.com/micmonay/keybd_event
../../micmonay/keybd_event/keybd_event.go:22: undefined: initKeyBD
--> linux/arm error: exit status 2
Stderr: # github.com/micmonay/keybd_event
../../micmonay/keybd_event/keybd_event.go:22: undefined: initKeyBD
--> freebsd/386 error: exit status 2
Stderr: # github.com/micmonay/keybd_event
../../micmonay/keybd_event/keybd_event.go:22: undefined: initKeyBD
--> freebsd/amd64 error: exit status 2
Stderr: # github.com/micmonay/keybd_event
../../micmonay/keybd_event/keybd_event.go:22: undefined: initKeyBD
--> openbsd/amd64 error: exit status 2
Stderr: # github.com/micmonay/keybd_event
../../micmonay/keybd_event/keybd_event.go:22: undefined: initKeyBD
--> netbsd/386 error: exit status 2
Stderr: # github.com/micmonay/keybd_event
../../micmonay/keybd_event/keybd_event.go:22: undefined: initKeyBD
--> freebsd/arm error: exit status 2
Stderr: # github.com/micmonay/keybd_event
../../micmonay/keybd_event/keybd_event.go:22: undefined: initKeyBD
--> netbsd/amd64 error: exit status 2
Stderr: # github.com/micmonay/keybd_event
../../micmonay/keybd_event/keybd_event.go:22: undefined: initKeyBD
There doesnt seem to be a method to easily type out a provided string such as:
"Hello World"
I believe this would require creating a map of sorts. looping through the characters and translating each rune into its corresponding keypress. This would be a very helpful tool for this library.
Great tooling though!
The code works fine when complied on mac-os-10.15 but doing the same on mac-os-11 and mac-os-12 results in following errors.
keyboard_darwin.go:19:38: error: unknown type name 'CGEventRef'
keyboard_darwin.go:19:20: error: unknown type name 'CGEventFlags'; did you mean 'MPEventFlags'?
keyboard_darwin.go:16:14: error: use of undeclared identifier 'kCGAnnotatedSessionEventTap'
keyboard_darwin.go:15:14: error: unknown type name 'CGEventRef'
keyboard_darwin.go:13:9: error: use of undeclared identifier 'event'
keyboard_darwin.go:12:2: error: use of undeclared identifier 'CGEventRef'
keyboard_darwin.go:11:2: error: unknown type name 'CGEventRef'
keyboard_darwin.go:9:9: error: use of undeclared identifier 'event'
keyboard_darwin.go:8:2: error: use of undeclared identifier 'CGEventRef'
keyboard_darwin.go:7:2: error: unknown type name 'CGEventRef'
keyboard_darwin.go:28:21: could not determine kind of name for C.kCGEventFlagMaskShift
keyboard_darwin.go:33:21: could not determine kind of name for C.kCGEventFlagMaskSecondaryFn
keyboard_darwin.go:34:21: could not determine kind of name for C.kCGEventFlagMaskNumericPad
keyboard_darwin.go:35:21: could not determine kind of name for C.kCGEventFlagMaskNonCoalesced
keyboard_darwin.go:32:21: could not determine kind of name for C.kCGEventFlagMaskHelp
keyboard_darwin.go:29:21: could not determine kind of name for C.kCGEventFlagMaskControl
keyboard_darwin.go:31:21: could not determine kind of name for C.kCGEventFlagMaskCommand
keyboard_darwin.go:30:21: could not determine kind of name for C.kCGEventFlagMaskAlternate
keyboard_darwin.go:27:21: could not determine kind of name for C.kCGEventFlagMaskAlphaShift
keyboard_darwin.go:107:2: could not determine kind of name for C.KeyTap
keyboard_darwin.go:110:13: could not determine kind of name for C.CreateUp
keyboard_darwin.go:85:15: could not determine kind of name for C.CreateDown
keyboard_darwin.go:69:18: could not determine kind of name for C.CGEventRef
keyboard_darwin.go:73:2: could not determine kind of name for C.AddActionKey
Is it possible to add some support for non-ASCII chars eg letters from French, Spanish, Cyrillic alphabets.
For Windows I've found SendInput function that could be used instead of keybd_event. Unicode char could be passed to this function to create keyboard event.
Maybe there are some analogs for MacOS and Linux?
Sorry for opening an issue for this, but couldnt find a better way :) thanks for this library, need to trigger some keyboard presses programmatically and this is perfect!
Hey, I don´t know what is going on under the hood when using this with windows but after using your module for a while Razer Synapse (the device control center) can´t find my keyboard anymore.
I am to lazy to debug this so I´m leaving it in your hands :)
Here is the chain of events:
I use the .Press() and .Release() like so:
kb.Press()
time.Sleep(time.Duration(controlValue) * time.Millisecond)
kb.Release()
At first everything was fine until I started using the MEDIA controls, then the first thing to break was the Razer custom keybindings.. like mapping caps to esc and esc to caps
after I did a restart my keybindings are back.. but the control center (synapse) can´t find the keyboard anymore.
Hi Michaël.
Why the two seconds delay for Linux isn't inside initKeyBD()
on keybd_linux.go
?
Given it's a hard requirement, I consider it a safer way to avoid issues when using this library.
And great job BTW ;-)
There no value mentioned in the image for command button. How to trigger that?
When trying to output a word like 'Hello' using the SetKeys
method, only one 'l' is outputted when using kb.Launching()
Is this intended?
Code:
package main
import (
"time"
"github.com/micmonay/keybd_event"
)
func main() {
kb, err := keybd_event.NewKeyBonding()
if err != nil {
panic(err)
}
time.Sleep(2 * time.Second)
// Select keys to be pressed
kb.SetKeys(keybd_event.VK_H, keybd_event.VK_E, keybd_event.VK_L, keybd_event.VK_L, keybd_event.VK_O, keybd_event.VK_L) // extra L at the end for test
// Press the selected keys
err = kb.Launching()
if err != nil {
panic(err)
}
}
Sorry if this isn't a bug - If I am using this incorrectly, please could you give an example of how to use this correctly?
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.