I used to program quite a bit using AutoHotKey to automate several tasks in Windows. Its pretty easy to use and as long as you dont need to do anything too complicated it does the job. But as soon as you need to do something more than just move around a window, or sending a hotkey, you need a more powerful tool. This is when I developed pyhk – a python hotkey module.
At some point I was looking to use some hotkeys for some advanced programming. It seemed appropriate to use pythonW for that. I found pywinautoW fairly quickly and immediately fell in love with it. The only thing missing were global hotkeys. The best module I could find was pyhookW. I somehow couldnt find a way to just register simple hotkeys. I feel like I reinvented the wheel and invented a program to register hotkeys and trigger functions with it. I called it pyhk to honor its main source pyhookW and to attribute the inspiration from autohotkeyW.
You can register any sequence of keys with any function you like. This will create a global hotkey used in all running programs on your Windows machine.
import pyhk def fun(): print "Do something" #create pyhk class instance hot = pyhk.pyhk() #add hotkey hot.addHotkey(['Ctrl', 'Alt','7'],fun) #start looking for hotkey. hot.start()
Please see the end user documentation for more details. It contains various examples and solutions for common problems. Using hotkeys in python should be simple. It is.
Python modules required
GNU GENERAL PUBLIC LICENSE, feel free to use and share it
Want to stay up to date with new releases? Subscribe to the right. Are you using PYHK? Let me know what you think about it in the comments below. I am always open to new ideas and ways to improve.
– bug fix in isIDHotkey
– execute single keys on KeyUpEvent with addHotkey( … , up = True)
– return id on addHotkey registration
– enable removeHotkey(id = id)
– removeHotkey() removes al hotkeys
– isThread option at addHotkey
– add getHotkeyListNoSingleNoModifiers function to return list of hotkeys
– set endHotkey with merged hotkeys (i.e. change endHotkey from ['Lcontrol','Lshift','Q'] to ['Ctrl','Shift','Q'])
– changed endHotkey loop (just made it a normal hotkey)
– Mouse hotkeys. Example: ['mouse left','A'] is now possible as a hotkey
– Single use hotkeys for mouse move, mouse wheel up and mouse wheel down. They can not be combined with any other hotkey. Example use: ['mouse wheel up']
– Easier hotkey registration for Ctrl, Alt, Shift: ['Ctrl','7'] is equal to ['Lcontrol','7'] and ['Rcontrol','7']