Here is a simple example that can be adapter for your use-case: GitHub - caseyscarborough/keylogger: A no-frills keylogger for macOS.
Personally, I would rewrite the application to log the keystrokes in console and use Port to receive the keystroke events into your erlang runtime.