Is it possible to catch keyboard inputs with Elixir/Erlang?

Hello everybody,

I never thought about that but is there a way to have an Elixir app that’s running in the background (might be a CLI put in the background of a terminal or just sitting on a terminal that’s minimized) to catch for keyboard input? Basically for catching shortcuts…

Edit: I just noticed we don’t have here a category for Erlang. Maybe it can be useful to have one alongside the Framework category (though it’s not a framework)

This is a highly platform-specific job, the method you need for “scraping” keyboard events depends on your operating system, desktop environment, etc. On linux you could read and parse raw events from /dev/input/*, which could be done with just elixir. For other solutions you’ll have to bind to native OS libraries; for example, on an X11 desktop you’d need something like the libxtst extension, on windows youll need to use SetWindowsHookEx(), or CGEventTapCreate() on mac os.

1 Like

There are the forums for Erlang: