{"id":14008162,"url":"https://github.com/micmonay/keybd_event","last_synced_at":"2025-10-08T07:26:47.528Z","repository":{"id":3588770,"uuid":"50236311","full_name":"micmonay/keybd_event","owner":"micmonay","description":"For simulate key press in Linux, Windows and Mac in golang","archived":false,"fork":false,"pushed_at":"2023-12-12T08:40:06.000Z","size":100,"stargazers_count":381,"open_issues_count":12,"forks_count":57,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-11-17T12:41:59.817Z","etag":null,"topics":["cgevent","event","golang","key","keybd-event","keyboard","linux","macos","simulate","simulation","uinput","windows"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/micmonay.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-01-23T11:52:12.000Z","updated_at":"2024-11-14T04:14:06.000Z","dependencies_parsed_at":"2024-06-18T13:35:25.641Z","dependency_job_id":"ec8ddbb9-4677-4f78-b5ad-a3d8a561e8dc","html_url":"https://github.com/micmonay/keybd_event","commit_stats":{"total_commits":60,"total_committers":10,"mean_commits":6.0,"dds":"0.18333333333333335","last_synced_commit":"9296c62b9fabb64ffa33d10865ce6d8928a291d7"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micmonay%2Fkeybd_event","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micmonay%2Fkeybd_event/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micmonay%2Fkeybd_event/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micmonay%2Fkeybd_event/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/micmonay","download_url":"https://codeload.github.com/micmonay/keybd_event/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227410474,"owners_count":17774757,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cgevent","event","golang","key","keybd-event","keyboard","linux","macos","simulate","simulation","uinput","windows"],"created_at":"2024-08-10T11:01:18.671Z","updated_at":"2025-10-08T07:26:42.480Z","avatar_url":"https://github.com/micmonay.png","language":"Go","readme":"# keybd_event\n\n[![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go\u0026logoColor=white\u0026style=flat-square)](https://pkg.go.dev/github.com/micmonay/keybd_event)\n\nThis library simulates the key press on a keyboard. It runs on Linux, Windows and Mac.\n\n**Important :** \n- The keys change in the different keyboard layouts of the target computer(s).\n- I have tested this code on my system and I don't find any errors. If you have a bug, please create an issue.\n\n\n### Example :\n```go\npackage main\n\nimport (\n\t\"runtime\"\n\t\"time\"\n\t\"github.com/micmonay/keybd_event\"\n)\n\nfunc main() {\n\tkb, err := keybd_event.NewKeyBonding()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// For linux, it is very important to wait 2 seconds\n\tif runtime.GOOS == \"linux\" {\n\t\ttime.Sleep(2 * time.Second)\n\t}\n\t\n\t// Select keys to be pressed\n\tkb.SetKeys(keybd_event.VK_A, keybd_event.VK_B) \n\n\t// Set shift to be pressed\n\tkb.HasSHIFT(true) \n\n\t// Press the selected keys\n\terr = kb.Launching() \n\tif err != nil {\n\t\tpanic(err)\n\t}\n\t\n\t// Or you can use Press and Release\n\tkb.Press()\n\ttime.Sleep(10 * time.Millisecond)\n\tkb.Release()\n\n\t// Here, the program will generate \"ABAB\" as if they were pressed on the keyboard.\n}\n```\n\nFor easy access to all the keys on the virtual keyboard, I have added more special keycodes constants `VK_SP*`. \n\nBelow is an illustration showing the \"VK_\" symbols for each key on the keyboard:\n![keyboard.png](./keyboard.png)\n\n## Linux\n\nOn Linux this library uses **uinput**, which on the major distributions requires root permissions. \n\nThe easy solution is executing through root user (by using `sudo`). A worse way is by changing the executable's permissions by using `chmod`.\n\n### Secure Linux Example\n```bash\nsudo groupadd uinput\nsudo usermod -a -G uinput my_username\nsudo udevadm control --reload-rules\necho \"SUBSYSTEM==\\\"misc\\\", KERNEL==\\\"uinput\\\", GROUP=\\\"uinput\\\", MODE=\\\"0660\\\"\" | sudo tee /etc/udev/rules.d/uinput.rules\necho uinput | sudo tee /etc/modules-load.d/uinput.conf\n```\n\nAnother subtlety on Linux: it is important after creating the `keybd_event` to **wait 2 seconds before running first keyboard actions**.\n\n## Darwin (MacOS)\nThis library depends on Apple's frameworks, and I did not find a solution to cross-compile from another OS to MacOS.\n","funding_links":[],"categories":["Go"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicmonay%2Fkeybd_event","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmicmonay%2Fkeybd_event","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicmonay%2Fkeybd_event/lists"}