Comments (2)
I have found a solution for that, but it have nothing to do with the windows api "keybd_event".
So i'm keeping the code here for future ref, hope it helps someone,
also i'm closing this issue for now.
Code: (Windows Only)
func PostKey(pid int, key uint8) (uintptr, error) {
if runtime.GOOS == "windows" {
var user32 = syscall.NewLazyDLL("user32.dll")
EnumWindows := func (enumFunc uintptr, lparam uintptr) {
user32.NewProc("EnumWindows").Call(uintptr(enumFunc), uintptr(lparam))
}
var hwnd uintptr
cb := syscall.NewCallback(func(h uintptr , prm uintptr) uintptr {
var itr_pid uint32
itr_pid = 0x0001
user32.NewProc("GetWindowThreadProcessId").Call(uintptr(h), uintptr(unsafe.Pointer(&itr_pid)))
if int(itr_pid) == pid {
hwnd = h
user32.NewProc("PostMessageW").Call(h, 0x0100, uintptr(key), 0)
//return 0 // stop enumeration (commented to make sure all windows created by our process get's the message)
}
return 1 // continue enumeration
})
EnumWindows(cb, 0)
if hwnd == 0 {
return 0, fmt.Errorf("No window with pid %d found", pid)
}
return hwnd, nil
}
return 0, fmt.Errorf("unsupported os")
}
Example:
PostKey(7777, 0x53)
will send the key 'S' to all the windows that are created by the process which it's id is 7777
list of keys
Notes:
If you are using a pid = cmd.Process.Pid (os/exec)
your binary should be built passing the "-H=windowsgui" flag
from keybd_event.
The library simulates a keyboard and it has the same output with the hardware keyboard. If you have a solution to set multiple keyboards on various output, it is probably possible. But I don't know if that exists.
(The library does not specify the output)
from keybd_event.
Related Issues (20)
- Insert Linux delay into keybd_linux.go HOT 4
- Hold button functionality
- Remote SSH Connections... HOT 2
- High latency on MacOS
- VK_CAPSLOCK is invalid HOT 3
- Question/Bug - Setting the same key twice only outputs once HOT 1
- checksum mismatch HOT 5
- How to type the # character? HOT 3
- Search for key by string? HOT 2
- Problems with the installation
- Shift+arrow sends only arrow key
- Function key in macOS
- Can not compile on macOS 12.3 (C code errors) HOT 1
- Strange error im getting. HOT 3
- Pressing most keys on Windows doesn't work as expected HOT 1
- Compilation fails on macos-11 & macos-12 HOT 3
- Error while building for Linux Arch 386 HOT 5
- Error in libraries when compiling HOT 2
- macos: alt-tab not ... alt tabbing? HOT 1
- (removed)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from keybd_event.