In this project, we used the Keyboard Python library to emulate a real keyboard using just the push buttons that controlled playing, pausing, and stopping video playback. The Keyboard library can be used to press any keys, so we can automate multiple key presses all from one push button. The library can also be used to write text to the screen.
However, the most dangerous function of this library is that it can be used to record every single key press on the target machine. These key presses can be recorded to a list, then saved to a file, and used for nefarious purposes. Of course, recording the key presses of a user, without their consent, is illegal, and can land you in a lot of trouble—so don’t do it! With that said, it can be used as a powerful tool when debugging how a user interacts with your code, so for software testing (under consent with the general public and in-house testers), you can see which keys they were pressing right before the code locked up and/or went thermonuclear!
The Keyboard library works with Linux and Windows, and it’s certainly lots of fun to play with. To read more about this library, head over to the blog post at https://bigl.es/tuesday-toolingrecord-replay-keystrokes-withpython, and see a few examples of how it can be used in day-to-day life.