Need help with keybd_event?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

229 Stars 36 Forks MIT License 71 Commits 8 Opened issues


For simulate key press in Linux, Windows and Mac in golang

Services available


Need anything else?

Contributors list

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

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

// Press the selected keys
err = kb.Launching() 
if err != nil {

// Or you can use Press and Release
time.Sleep(10 * time.Millisecond)

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


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


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

The easy solution is executing through root user (by using

). A worse way is by changing the executable's permissions by using

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

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.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.