So I set off looking for a Node.js library to notify of key presses and found
iohook (https://www.npmjs.com/package/iohook). I downloaded it, setup a simple npm/node project, and was console log printing key presses in no time. I of course also pushed code to GitHub, see link at top of article for full code base.
Now I was able to log the actual key being pressed!
At first, the key logger simply recorded how many times each key had been pressed, but that only gives one measure and one dimension so I added another metric: time. I logged how long each key was pressed for in an aggregate manner so that I could calculate averages and other interesting stats. I used the time metric to calculate last press, taps, and holds to liven up the data available for visualization as well. I sprinkled in some other global data such as total server runtime etc. to figure out how much time keys are actually depressed for as a percentage.
I had to add Express.js, which is a simple web framework to create basic web applications and REST API endpoints, to the codebase as well to return the data object that retained information from the actual key logger on how many times each key had been pressed. Don’t forget to setup CORS (Cross-Origin Resource Sharing) too to allow localhost to access the aforementioned Express.js API endpoint. For more about CORS, see the following: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
Originally published at emilyplusplus.wordpress.com on March 29, 2018.