PYHK – Python Hotkey Module

PYHK is now on GitHub!

keyboard PYHK   Python Hotkey Module

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 Python for that. I found Pywinauto fairly quickly and immediately fell in love with it. The only thing missing were global hotkeys. The best module I could find was Pyhook. 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 Pyhook and to attribute the inspiration from AutoHotkey.


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.
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.


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 version


Python modules required



GNU GENERAL PUBLIC LICENSE, feel free to use and share it icon smile PYHK   Python Hotkey Module


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.

Current version

PYHK is now on GitHub!


Samples and offline documentation


Older versions




Log pyhk


- 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']

12 Responses to “PYHK – Python Hotkey Module”

  1. jcitme January 13, 2012 at 7:36 pm # Reply

    Is there a equivalent for pyhk for linux systems?

  2. bean bag chairs green February 24, 2012 at 4:09 am # Reply

    hey :) what design are you making use of for this one? (this actual blog site) I kinda love this and I used to be thinking if this really is obtainable.

  3. Ruso November 14, 2012 at 11:04 pm # Reply

    Cannot import pyhk. It is giving the following error: ImportError: No module named pythoncom

    Can you please help me with it.

  4. k3it December 14, 2012 at 5:20 pm # Reply

    cool it works! I put calls to hot. in a separate thread so my script doesn’t block. Is that OK?

  5. Mike Wisnefsky March 14, 2013 at 12:37 am # Reply

    Any chance of this being available for 3.3?

    • admin April 19, 2013 at 3:56 am # Reply

      Hi Mike,

      sorry for the late response.

      PYHK only depends on Pyhook. To my knowledge they did not port Pyhook to 3.0
      thus I cant port mine either.

      If you get them to port should be a matter of a few minutes to adjust PYHK.

  6. DavidA March 28, 2013 at 5:22 pm # Reply

    Hey, Would be good if you made a module which auto-detects OS and relays to relevant OS-specific hotkey module.

    Basically make this compatible with all OSs

    • admin April 19, 2013 at 4:01 am # Reply

      I agree that this is definitely missing, however, unfortunately I dont have the time to do this right now.

Leave a Reply