Repository: ethanhs/pyhooked Branch: master Commit: 6bef30310e7d Files: 11 Total size: 28.6 KB Directory structure: gitextract_ojmednc2/ ├── .gitignore ├── LGPL ├── MANIFEST ├── change-log.md ├── example.py ├── example_gui.py ├── pyhooked/ │ └── __init__.py ├── readme.md ├── setup.cfg ├── setup.py └── test.py ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] *$py.class # C extensions *.so # Distribution / packaging .Python env/ build/ develop-eggs/ dist/ downloads/ eggs/ .eggs/ lib/ lib64/ parts/ sdist/ var/ *.egg-info/ .installed.cfg *.egg # PyInstaller # Usually these files are written by a python script from a template # before PyInstaller builds the exe, so as to inject date/other infos into it. *.manifest *.spec # Installer logs pip-log.txt pip-delete-this-directory.txt # Unit test / coverage reports htmlcov/ .tox/ .coverage .coverage.* .cache nosetests.xml coverage.xml *,cover .hypothesis/ # Translations *.mo *.pot # Django stuff: *.log local_settings.py # Flask stuff: instance/ .webassets-cache # Scrapy stuff: .scrapy # Sphinx documentation docs/_build/ # PyBuilder target/ # IPython Notebook .ipynb_checkpoints # pyenv .python-version # celery beat schedule file celerybeat-schedule # dotenv .env # virtualenv venv/ ENV/ # Spyder project settings .spyderproject # Rope project settings .ropeproject ================================================ FILE: LGPL ================================================ GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library. ================================================ FILE: MANIFEST ================================================ # file GENERATED by distutils, do NOT edit setup.cfg setup.py pyhooked\__init__.py ================================================ FILE: change-log.md ================================================ #Change log for Hooked: #####v0.5: * Initial module * Had hook to raw key-codes and scan-codes * Parsed these codes into names of the keys. * Limited dependencies to just standard library modules. * functions called when keys pressed #####v0.6: * added many mouse hooks * Left, middle, and right button presses are supported * Scrolling the scroll wheel is supported. * Hooking mouse coordinates is supported. * Passing arguments on function call supported. #####v0.7: * release to PyPi #####v0.8: * major overhaul of code to optimize and improve code quality and efficiency (expect a v0.9) * may have breaking changes * 64bit support thanks to @swprojects * fixed memory access violation due to conflicting with UI frameworks. #####v0.8.1 * fix for keys held down thanks to @denniseffing ================================================ FILE: example.py ================================================ from pyhooked import Hook, KeyboardEvent, MouseEvent def handle_events(args): if isinstance(args, KeyboardEvent): print(args.key_code) if args.current_key == 'A' and args.event_type == 'key down' and 'Lcontrol' in args.pressed_key: print("Ctrl + A was pressed") elif args.current_key == 'Q' and args.event_type == 'key down' and 'Lcontrol' in args.pressed_key: hk.stop() print('Quitting.') if isinstance(args, MouseEvent): if args.mouse_x == 300 and args.mouse_y == 400: print("Mouse is at (300,400") hk = Hook() # make a new instance of PyHooked hk.handler = handle_events # add a new shortcut ctrl+a, or triggered on mouseover of (300,400) hk.hook() # hook into the events, and listen to the presses ================================================ FILE: example_gui.py ================================================ import sys from pyhooked import Hook, KeyboardEvent import threading from PySide.QtCore import * from PySide.QtGui import * class MyWindow(QMainWindow): def __init__(self, *args): QMainWindow.__init__(self, *args) self.label = QLabel(self) self.label.setText('A PySide Window') self.resize(640, 480) hk = Hook() # make a new instance of PyHooked hk.handler = self.foo # set the handler function # thread the call to hook, otherwise we block the GUI thread = threading.Thread(target=hk.hook) # start hooking thread.start() def foo(self, args): if isinstance(args, KeyboardEvent): print(args.key_code) if args.current_key == 'A' and args.event_type == 'key down' and 'Lcontrol' in args.pressed_key: self.label.setText("Ctrl + A was pressed") if __name__ == "__main__": app = QApplication(sys.argv) w = MyWindow() w.show() sys.exit(app.exec_()) ================================================ FILE: pyhooked/__init__.py ================================================ """ This file is part of pyhooked, an LGPL licensed pure Python hotkey module for Windows Copyright (C) 2016 Ethan Smith """ import ctypes from ctypes import wintypes from ctypes import CFUNCTYPE, POINTER, c_int, c_uint, c_void_p, windll from ctypes import byref from warnings import warn from traceback import format_exc import atexit __version__ = '0.8.1' cmp_func = CFUNCTYPE(c_int, c_int, wintypes.HINSTANCE, POINTER(c_void_p)) # redefine names to avoid needless clutter GetModuleHandleA = ctypes.windll.kernel32.GetModuleHandleA SetWindowsHookExA = ctypes.windll.user32.SetWindowsHookExA GetMessageW = ctypes.windll.user32.GetMessageW DispatchMessageW = ctypes.windll.user32.DispatchMessageW TranslateMessage = ctypes.windll.user32.TranslateMessage CallNextHookEx = ctypes.windll.user32.CallNextHookEx UnhookWindowsHookEx = ctypes.windll.user32.UnhookWindowsHookEx # specify the argument and return types of functions GetModuleHandleA.restype = wintypes.HMODULE GetModuleHandleA.argtypes = [wintypes.LPCWSTR] SetWindowsHookExA.restype = c_int SetWindowsHookExA.argtypes = [c_int, cmp_func, wintypes.HINSTANCE, wintypes.DWORD] GetMessageW.argtypes = [POINTER(wintypes.MSG), wintypes.HWND, c_uint, c_uint] TranslateMessage.argtypes = [POINTER(wintypes.MSG)] DispatchMessageW.argtypes = [POINTER(wintypes.MSG)] def _callback_pointer(handler): """Create and return C-pointer""" return cmp_func(handler) class BaseEvent(object): """A keyboard or mouse event.""" pass class KeyboardEvent(BaseEvent): """Class to describe an event triggered by the keyboard""" def __init__(self, current_key=None, event_type=None, pressed_key=None, key_code=None): self.current_key = current_key self.event_type = event_type self.pressed_key = pressed_key self.key_code = key_code class MouseEvent(BaseEvent): """Class to describe an event triggered by the mouse""" def __init__(self, current_key=None, event_type=None, mouse_x=None, mouse_y=None): self.current_key = current_key self.event_type = event_type self.mouse_x = mouse_x self.mouse_y = mouse_y # The following section contains dictionaries that map key codes and other event codes to the event type (e.g. key up) # and the key or button doing the action (e.g. Tab) MOUSE_ID_TO_KEY = {512: 'Move', 513: 'LButton', 514: 'LButton', 516: 'RButton', 517: 'RButton', 519: 'WheelButton', 520: 'WheelButton', 522: 'Wheel'} MOUSE_ID_TO_EVENT_TYPE = {512: None, 513: 'key down', 514: 'key up', 516: 'key down', 517: 'key up', 519: 'key down', 520: 'key up', 522: None} # stores the relation between keyboard event codes and the key pressed. Reference: # https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx # seems to only work on 32 bits ID_TO_KEY = {8: 'Back', 9: 'Tab', 13: 'Return', 20: 'Capital', 27: 'Escape', 32: 'Space', 33: 'Prior', 34: 'Next', 35: 'End', 36: 'Home', 37: 'Left', 38: 'Up', 39: 'Right', 40: 'Down', 44: 'PrtScr', 46: 'Delete', 48: '0', 49: '1', 50: '2', 51: '3', 52: '4', 53: '5', 54: '6', 55: '7', 56: '8', 57: '9', 65: 'A', 66: 'B', 67: 'C', 68: 'D', 69: 'E', 70: 'F', 71: 'G', 72: 'H', 73: 'I', 74: 'J', 75: 'K', 76: 'L', 77: 'M', 78: 'N', 79: 'O', 80: 'P', 81: 'Q', 82: 'R', 83: 'S', 84: 'T', 85: 'U', 86: 'V', 87: 'W', 88: 'X', 89: 'Y', 90: 'Z', 91: 'Lwin', 92: 'Rwin', 93: 'App', 95: 'Sleep', 96: 'Numpad0', 97: 'Numpad1', 98: 'Numpad2', 99: 'Numpad3', 100: 'Numpad4', 101: 'Numpad5', 102: 'Numpad6', 103: 'Numpad7', 104: 'Numpad8', 105: 'Numpad9', 106: 'Multiply', 107: 'Add', 109: 'Subtract', 110: 'Decimal', 111: 'Divide', 112: 'F1', 113: 'F2', 114: 'F3', 115: 'F4', 116: 'F5', 117: 'F6', 118: 'F7', 119: 'F8', 120: 'F9', 121: 'F10', 122: 'F11', 123: 'F12', 144: 'Numlock', 160: 'Lshift', 161: 'Rshift', 162: 'Lcontrol', 163: 'Rcontrol', 164: 'Lmenu', 165: 'Rmenu', 186: 'Oem_1', 187: 'Oem_Plus', 188: 'Oem_Comma', 189: 'Oem_Minus', 190: 'Oem_Period', 191: 'Oem_2', 192: 'Oem_3', 219: 'Oem_4', 220: 'Oem_5', 221: 'Oem_6', 222: 'Oem_7', #223: 'OEM_8', 1001: 'mouse left', # mouse hotkeys 1002: 'mouse right', 1003: 'mouse middle', 1000: 'mouse move', # single event hotkeys 1004: 'mouse wheel up', 1005: 'mouse wheel down', 1010: 'Ctrl', # merged hotkeys 1011: 'Alt', 1012: 'Shift', 1013: 'Win', } event_types = {0x100: 'key down', # WM_KeyDown for normal keys 0x101: 'key up', # WM_KeyUp for normal keys 0x104: 'key down', # WM_SYSKEYDOWN, used for Alt key. 0x105: 'key up', # WM_SYSKEYUP, used for Alt key. } # these are used for specifying the hook type we want to make WH_KEYBOARD_LL = 0x00D WH_MOUSE_LL = 0x0E # the Windows quit message, if the program quits while listening. WM_QUIT = 0x0012 class Hook(object): """Main hotkey class used to and listen for hotkeys. Set an event handler to check what keys are pressed.""" def __init__(self, warn_unrecognised = False): """Initializer of the Hook class, creates class attributes. If warn_unrecognised is True, warn when an unrecognised key is pressed.""" self.warn_unrecognised = warn_unrecognised self.pressed_keys = [] self.keyboard_id = None self.mouse_id = None self.mouse_is_hook = False self.keyboard_is_hook = True def handler(self, event): """Handle keyboard and mouse events.""" raise NotImplementedError() def stop(self): """Stop this object from listening.""" windll.user32.PostQuitMessage (0) def hook(self, keyboard=True, mouse=False): """Hook mouse and/or keyboard events""" self.mouse_is_hook = mouse self.keyboard_is_hook = keyboard # check that we are going to hook into at least one device if not self.mouse_is_hook and not self.keyboard_is_hook: raise Exception("You must hook into either the keyboard and/or mouse events") if self.keyboard_is_hook: def keyboard_low_level_handler(code, event_code, kb_data_ptr): """Used to catch keyboard events and deal with the event""" key_code = 0xFFFFFFFF & kb_data_ptr[0] # key code current_key = ID_TO_KEY.get(key_code) # check the type of event (see ID_TO_KEY for a list) if current_key is None: event = None # We can check this later. if self.warn_unrecognised: warn('Unrecognised key ID %d.' % key_code) else: event_type = event_types[0xFFFFFFFF & event_code] if event_type == 'key down': # add key to those down to list if current_key not in self.pressed_keys: self.pressed_keys.append(current_key) if event_type == 'key up': # remove when no longer pressed try: self.pressed_keys.remove(current_key) except ValueError: pass # current_key is not in the list. # wrap the keyboard information grabbed into a container class event = KeyboardEvent(current_key, event_type, self.pressed_keys, key_code) # Call the event handler to deal with keys in the list try: if event: self.handler(event) except Exception as e: warn('While handling {}, self.handler produced a traceback:\n{}'.format(event, format_exc())) finally: # TODO: fix return here to use non-blocking call return CallNextHookEx(self.keyboard_id, code, event_code, kb_data_ptr) keyboard_pointer = _callback_pointer(keyboard_low_level_handler) self.keyboard_id = SetWindowsHookExA(WH_KEYBOARD_LL, keyboard_pointer, GetModuleHandleA(None), 0) if self.mouse_is_hook: def mouse_low_level_handler(code, event_code, kb_data_ptr): """Used to catch and deal with mouse events""" current_key = MOUSE_ID_TO_KEY.get(event_code) # check the type of event (see MOUSE_ID_TO_KEY for a list) if current_key is None: event = None # We can check this later. if self.warn_unrecognised: warn('Unrecognised mouse ID %d.' % event_code) else: if current_key != 'Move': # if we aren't moving, then we deal with a mouse click event_type = MOUSE_ID_TO_EVENT_TYPE[event_code] # the first two members of kb_data_ptr hold the mouse position, x and y event = MouseEvent(current_key, event_type, kb_data_ptr[0], kb_data_ptr[1]) try: if event: self.handler(event) except Exception as e: warn('While handling {}, self.handler produced a traceback:\n{}'.format(event, format_exc())) finally: # TODO: fix return here to use non-blocking call return CallNextHookEx(self.mouse_id, code, event_code, kb_data_ptr) mouse_pointer = _callback_pointer(mouse_low_level_handler) self.mouse_id = SetWindowsHookExA(WH_MOUSE_LL, mouse_pointer, GetModuleHandleA(None), 0) atexit.register(UnhookWindowsHookEx, self.keyboard_id) atexit.register(UnhookWindowsHookEx, self.mouse_id) message = wintypes.MSG() while self.mouse_is_hook or self.keyboard_is_hook: msg = GetMessageW(byref(message), 0, 0, 0) if msg in [0, -1]: self.unhook_keyboard() self.unhook_mouse() break # Exit the loop. else: TranslateMessage(byref(message)) DispatchMessageW(byref(message)) def unhook_mouse(self): """Stop listening to the mouse""" if self.mouse_is_hook: self.mouse_is_hook = False UnhookWindowsHookEx(self.mouse_id) def unhook_keyboard(self): """Stop listening to the keyboard""" if self.keyboard_is_hook: self.keyboard_is_hook = False UnhookWindowsHookEx(self.keyboard_id) ================================================ FILE: readme.md ================================================ # PyHooked: a pure Python hotkey module [![Join the chat at https://gitter.im/IronManMark20/pyhooked](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/IronManMark20/pyhooked?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) ### ATTENTION: pyhooked has been deprecated in favor of [keyboard](https://github.com/boppreh/keyboard) for new projects. This library is will no longer be supported. Please use one keyboard or one of the alternatives listed in Alternatives. #### About - PyHooked is a pure python keyboard and mouse hotkey module that allows the creation of hotkeys in all Python implementations that support sane implementations of ctypes. Instead of messing around with low level Windows calls, just give Hooked a callback and tell it to start listening. PyHooked supports IronPython (2.7.5+, incl. 2.7.6 RC2), PyPy (5.3.1+) and CPython (Tested:2.7 x86,3.4 x64,3.5 x86; Most are likely to work) currently. It is pure Python, so porting to other Python implementations and versions should be very simple. #### Usage - Please see [example.py](https://github.com/ethanhs/pyhooked/blob/master/example.py) for a basic example. If you are using it with a UI library, please see [example_gui.py](https://github.com/ethanhs/pyhooked/blob/master/example_gui.py) Please note that the wiki is out of date, and needs to be updated. #### Installing Just run `$ pip install pyhooked` or `$ pip install git+https://github.com/ethanhs/pyhooked.git` to get the latest version. #### Alternatives - [pyHook](http://sourceforge.net/projects/pyhook/) and [pyhk](https://github.com/schurpf/pyhk) inspired the creation of this project. They are great hotkey modules too! [pywinauto](https://github.com/pywinauto/pywinauto) is an incredibly useful Windows automation library that also includes among a plethora of tools, a hotkey detection library. #### License - PyHooked Copyright (C) 2015 Ethan Smith This program comes with ABSOLUTELY NO WARRANTY; This is free software, and you are welcome to redistribute it under certain conditions; PyHooked is licensed under the LGPL v3, or at your choice, any later version. This program comes with the lgpl in a .txt file. Pyhooked v0.8+ is based on work by Maxim Samokhvalov, who has my graditude for his work, and others in the PyWinAuto project, licensed under the BSD 3-clause license. The copyright notice is given below. Copyright (C) 2016 Maxim Samokhvalov Copyright (C) 2016 Vasily Ryabov Copyright (C) 2016 ethanhs All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of pywinauto nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. * Neither the name of hooks.py nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #####As of v0.6, the module is LGPL licensed, not under the GPL. ####The Future - Here are a few things that I would like to see: * ~~add support for args for called functions~~ __(DONE)__ * ~~get mouse inputs~~ __(DONE)__ * ~~support all scancodes found [here](https://msdn.microsoft.com/en-us/library/aa299374%28v=vs.60%29.aspx)~~ __(DONE)__ * Jython support * ????
I am open to feature requests. If you have ideas, let me know (mr.smittye (at) gmail). Or, even better, make your changes and a pull request! ================================================ FILE: setup.cfg ================================================ [metadata] description-file = readme.md ================================================ FILE: setup.py ================================================ from setuptools import setup setup( name='pyhooked', packages=['pyhooked'], version='0.8.1', description='Pure Python hotkey hook, with thanks to pyHook, pywinauto, and pyhk', author='Ethan Smith', author_email='ethan@ethanhs.me', url='https://github.com/ethanhs/pyhooked', download_url="https://github.com/ethanhs/pyhooked/tarball/0.8.1", keywords=['hotkey', 'shortcut', 'windows', 'keyboard', 'hooks', 'hook'], classifiers=[], ) ================================================ FILE: test.py ================================================ from pyhooked import Hook, KeyboardEvent h = Hook() def f(event): if isinstance(event, KeyboardEvent): print(event.pressed_key) if event.pressed_key == ['Q']: h.stop() else: raise Exception() h.handler = f if __name__ == '__main__': h.hook(mouse = True)