Global keyboard input

Does Go provide a way to listen to global keyboard inputs? Essentially, like a keylogger (but that's not my goal), where it captures input if the focus is outside its own context.

Ideally, it would be a cross-platform, but if not for Windows, work would be as well.

My ultimate goal is a tool that is cross-platform, does not require runtime, which allows you to write global keyboard shortcuts to javascript calls applications (mainly control Google Music). This will be done if the Chrome extension connects to the socket.io connection in the Golang application and has the application, then issue the extension commands.

+4
source share
1 answer

Capturing keyboard input outside the application context is platform dependent. Go specifically has no binding to these APIs.

Mac OS X has an Objective-C API called short events . Windows has a C ++ function, RegisterHotKey , although I'm less familiar with the Windows API.

There may be tools / frameworks that allow you to run this cross platform, but there are currently no such in Go. If you find it in C, you can connect it to Go using cgo .

Perhaps you complicate things too much? Here's a page that describes how to add keyboard shortcuts for the Chrome extension.

+1
source

Source: https://habr.com/ru/post/1536511/


All Articles