The short, quick story of how we finally found something we liked after hours of uncomfortable typing.
Well we have Python sessions every week and we have this one person whose space-bar was not working or working when you don't expect it and it was shop closed for most of the time.
Once luck hit really hard and for some three weeks we forgot about it until the spacebar decided to make a comeback. The permanent solution the person was using was a virtual keyboard. He would position the mouse pointer on the keyboard's spacebar before typing and instead of pressing the spacebar, he would right click on the laptop's mouse pad, clicking the virtual spacebar. It's no fun typing i can tell you and no fun coding, for sure! We'll add in doing git push with it, it was really &^&^%*^%$%$£.
It was exactly after our practical git session that i started asking myself what we were teaching if we could not solve this with Python. I reached out to my keys and my first intuition was PyAuto Gui. And yes, the person was leaving in 5 minutes, he was collecting his things ... I had to get it right, right now!
I was lost in PyAutoGUI's keys docs, i decided to explore new options right there, out in the wild blue. I saw a package, keyboard gloups, should have thought of it XD. With the import antigravity joke flashing through my mind, i was off to the docs page which ... was a .md file. Euhh the example showed only one use case, i was digging, ploughing, rummaging ... I was ctrl+f brute searching until i came up with an infinite loop, event detection and key send. Cool! The api was really great as you intuitively guessed keys' names. Well done keyboard devs 🎉.
import keyboard # using module keyboard while True: # making a loop try: # used try so that if user pressed other than the given key error will not be shown if keyboard.is_pressed('ctrl+alt+s'): print('pressed') keyboard.write(' ') except: pass
Instead of sending the file, i virtual-keyboard typed the program in the person's laptop, i had no time to setup that crazy mouse setup for space bar. I went in quick, mobile messaging experience helped. Then we had to think out of combinations. On my PC, ctrl+s was working fine, but it was the popular save command and it was hitting hard on his pc. We tried z+x but it was typing those letters. Finally we settled on ctrl+alt+s.
Then about deployment, win8 links py files automatically. One click on the file and it was running. Phew we tested and the person liked it very much as he was tired of mousing around. The snake finally swallowed the mouse .
Do you have a story of how a short snippet ate away a bugging problem? Share it below!
(  Mike Driscoll has a Mouse Vs Python blog)
Images from unsplash