Home PYHK – Python Hotkey Module
PYHK – Python Hotkey Module
Cancel

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.

Functionality

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.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
<pre lang="py" toggle="no">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()

Documentation

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

2.6

Python modules required

pyhook, pywin32

License

GNU GENERAL PUBLIC LICENSE, feel free to use and share it 🙂

Download

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

pyhk0.36

– bug fix in isIDHotkey

pyhk0.35

– execute single keys on KeyUpEvent with addHotkey( … , up = True)

pyhk0.34

– return id on addHotkey registration

– enable removeHotkey(id = id)

– removeHotkey() removes al hotkeys

pyhk0.33

– isThread option at addHotkey

pyhk0.32

– 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)

pyhk0.30

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

Trending Tags