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


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

pyhook, pywin32


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.

Current version

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

The ideal time to determination health problem is before any visible sign appears. Actually there isn’t anything you can’t purchase on the Internet anymore. Whereas erectile dysfunction is more common among older men, that doesn’t something you simply have to live with. What about “canadian pharmacy cialis 5 mg” and “cialis canadian pharmacy“? In our generation, there are divers options for those ones who suffer from erectile dysfunction. You may have heard about “canadian pharmacy online cialis“. More information about the problem available at “canadian pharmacy cialis 20mg“. Why it happen? Can sexual disorders in men be prevented? If you get any prescription remedies like Viagra, check with a dispenser that they are sure to take with your other remedies.


  1. Ruso says

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

    Can you please help me with it.

    • admin says

      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.

  2. DavidA says

    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 says

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

  3. John says

    Will there be any inclusion of keys like “PrtScr” or “PgUp”? I am trying to make a program that takes a screen-shot when a user presses win+prtscr. But all around a great program. Also, it doesn’t really support pip 🙁 It would be great if it were to support pip and the other keys I mentioned. Thanks for this great script!

    • says

      Hi John,

      sorry but at this point I am not actively maintaing PYHK :(. PYHK is mostly a wrapper around pyhook. If pyhook supports the keys you need it should be rather simple to extend PYHK. Hope this helps 🙂

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.