Coder Social home page Coder Social logo

keybd_event's People

Contributors

dimitarvdimitrov avatar hotafrika avatar jguer avatar karreiro avatar micmonay avatar servusdei2018 avatar stephen-fox avatar templarr avatar thalesog avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

keybd_event's Issues

Error in libraries when compiling

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 .

github.com/micmonay/keybd_event

../../go/pkg/mod/github.com/micmonay/[email protected]/keybd_event.go:20:9: undefined: initKeyBD

Question/Bug - Setting the same key twice only outputs once

Issue / Question

Description

When trying to output a word like 'Hello' using the SetKeys method, only one 'l' is outputted when using kb.Launching()

Is this intended?

Replicating

  • OS = W10 Pro
  • Go = go version go1.15.7 windows/amd64

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)
	}
}

Output

image

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?

Send keys to a specific stdin

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 :)

Search for key by string?

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")

Feature Request: Additional keycodes

For me the main use case would be to test "special" keys like VK_F21 (not a typo, see: MSDN and USB HID).

As far as I can see, these are currently not supported in:

VK_F1 = 59
VK_F2 = 60
VK_F3 = 61
VK_F4 = 62
VK_F5 = 63
VK_F6 = 64
VK_F7 = 65
VK_F8 = 66
VK_F9 = 67
VK_F10 = 68
VK_F11 = 87
VK_F12 = 88
VK_NUMLOCK = 69
VK_SCROLLLOCK = 70

Would it be possible to add these?

checksum mismatch

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?

Strange error im getting.

Screen Shot 2022-04-06 at 7 19 23 PM
Not really sure what's happening here. Looks like it can't a reference for that var.

Large error below

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

Build failed with Dockerfile

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?

No easy input for strings

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!

High latency on MacOS

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

Thanks!

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!

Using this module on windows fucks up Razer keyboards.

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:

  1. I use the .Press() and .Release() like so:

    kb.Press()
    time.Sleep(time.Duration(controlValue) * time.Millisecond)
    kb.Release()

  2. 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

  3. after I did a restart my keybindings are back.. but the control center (synapse) can´t find the keyboard anymore.

How to type the # character?

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 :)

Support for non-ASCII chars

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?

Remote SSH Connections...

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.

Insert Linux delay into keybd_linux.go

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 ;-)

Test failed: ExampleNewKeyBonding

=== 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

Pressing most keys on Windows doesn't work as expected

The problem

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()
}

What do I expect?

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...

What actually happens?

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.

Command Button Value

There no value mentioned in the image for command button. How to trigger that?

Function key in macOS

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

Hold button functionality

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?

Shift+arrow sends only arrow key

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).

VK_CAPSLOCK is invalid

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

Problems with the installation

(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

Compilation fails on macos-11 & macos-12

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

Unable to compile on some platforms

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

Example not working on Mac

I have tried the code in the example on Mac, but nothing gets printed out. The same code works fine on Windows.

macos: alt-tab not ... alt tabbing?

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()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.