All Projects → micmonay → Keybd_event

micmonay / Keybd_event

Licence: mit
For simulate key press in Linux, Windows and Mac in golang

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Keybd event

react-keyevent
An easy-to-use keyboard event react component, Package size less than 3kb
Stars: ✭ 38 (-78.29%)
Mutual labels:  keyboard, event
Chordly
Chordly is a javascript library that may be used to detect and act upon key sequences entered by a user.
Stars: ✭ 14 (-92%)
Mutual labels:  keyboard, event
Enigo
Cross platform input simulation in Rust
Stars: ✭ 254 (+45.14%)
Mutual labels:  keyboard, simulation
Keymousego
类似按键精灵的鼠标键盘录制和自动化操作 模拟点击和键入 | automate mouse clicks and keyboard input
Stars: ✭ 1,145 (+554.29%)
Mutual labels:  keyboard, simulation
Ns3 Mmwave
ns-3 module for simulating mmWave-based cellular systems. See https://ieeexplore.ieee.org/document/8344116/ (open access) as a reference.
Stars: ✭ 169 (-3.43%)
Mutual labels:  simulation
Mx alps hybrid
KiCad Library of custom MX-Alps footprints
Stars: ✭ 160 (-8.57%)
Mutual labels:  keyboard
Noel
A universal, human-centric, replayable javascript event emitter.
Stars: ✭ 158 (-9.71%)
Mutual labels:  event
Keyman
Keyman cross platform input methods system running on Android, iOS, Linux, macOS, Windows and mobile and desktop web
Stars: ✭ 156 (-10.86%)
Mutual labels:  keyboard
Bmtk
Brain Modeling Toolkit
Stars: ✭ 177 (+1.14%)
Mutual labels:  simulation
Veins
Veins - The open source vehicular network simulation framework.
Stars: ✭ 173 (-1.14%)
Mutual labels:  simulation
Autopilot Rs
A simple, cross-platform GUI automation module for Rust.
Stars: ✭ 168 (-4%)
Mutual labels:  simulation
Ndlib
Network Diffusion Library - (for NetworkX and iGraph)
Stars: ✭ 159 (-9.14%)
Mutual labels:  simulation
Keyboardtextfield
KeyboardTextField is a lightweight, simple, non-invasive keyboard accompanying input box! Write in Swift!
Stars: ✭ 170 (-2.86%)
Mutual labels:  keyboard
A Keyboard
javascript keyboard
Stars: ✭ 160 (-8.57%)
Mutual labels:  keyboard
Territory
3D rendered proc-gen world test. C++ homebrew voxel engine for agent-driven prodedural generation / world simulation
Stars: ✭ 175 (+0%)
Mutual labels:  simulation
Locationsimulator
MacOS 10.15 / 11.0 application to spoof your iOS / iPadOS or iPhoneSimulator device location. WatchOS and TvOS are partially supported.
Stars: ✭ 157 (-10.29%)
Mutual labels:  simulation
Oregano
Schematic capture and circuit simulator
Stars: ✭ 163 (-6.86%)
Mutual labels:  simulation
Libuev
Lightweight event loop library for Linux epoll() family APIs
Stars: ✭ 170 (-2.86%)
Mutual labels:  event
Sparkle
🎇 A modern particle engine running on GPU, using c++14 and OpenGL 4.4.
Stars: ✭ 162 (-7.43%)
Mutual labels:  simulation
Mjrl
Reinforcement learning algorithms for MuJoCo tasks
Stars: ✭ 162 (-7.43%)
Mutual labels:  simulation

keybd_event

go.dev reference

This library simulates the key press on a keyboard. It runs on Linux, Windows and Mac.

Important :

  • The keys change in the different keyboard layouts of the target computer(s).
  • I have tested this code on my system and I don't find any errors. If you have a bug, please create an issue.

Example :

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

For easy access to all the keys on the virtual keyboard, I have added more special keycodes constants VK_SP*.

Below is an illustration showing the "VK_" symbols for each key on the keyboard: keyboard.png

Linux

On Linux this library uses uinput, which on the major distributions requires root permissions.

The easy solution is executing through root user (by using sudo). A worse way is by changing the executable's permissions by using chmod.

Secure Linux Example

sudo groupadd uinput
sudo usermod -a -G uinput my_username
sudo udevadm control --reload-rules
echo "SUBSYSTEM==\"misc\", KERNEL==\"uinput\", GROUP=\"uinput\", MODE=\"0660\"" | sudo tee /etc/udev/rules.d/uinput.rules
echo uinput | sudo tee /etc/modules-load.d/uinput.conf

Another subtlety on Linux: it is important after creating the keybd_event to wait 2 seconds before running first keyboard actions.

Darwin (MacOS)

This library depends on Apple's frameworks, and I did not find a solution to cross-compile from another OS to MacOS.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].