Professional Documents
Culture Documents
html
Contents
Package pyhook...........................................................................................................................................2
Module HookManager................................................................................................................................2
Class HookConstants...................................................................................................................................3
MsgToName(cls, msg) Class Method..................................................................................................5
IDToName(cls, code) Class Method.....................................................................................................5
VKeyToID(cls, vkey) Class Method.......................................................................................................6
vk_to_id...............................................................................................................................................6
msg_to_name......................................................................................................................................6
Class HookEvent..........................................................................................................................................7
__init__(self, msg, time, hwnd, window_name) (Constructor)...........................................................8
GetMessageName(self).......................................................................................................................8
Class MouseEvent........................................................................................................................................9
__init__(self, msg, x, y, data, flags, time, hwnd, window_name) (Constructor).............................10
Class KeyboardEvent..................................................................................................................................11
__init__(self, msg, vk_code, scan_code, ascii, flags, time, hwnd, window_name) (Constructor)...12
GetKey(self).......................................................................................................................................12
IsExtended(self).................................................................................................................................12
IsInjected(self)....................................................................................................................................12
IsAlt(self)............................................................................................................................................13
IsTransition(self)................................................................................................................................13
Class HookManager...................................................................................................................................14
__init__(self) (Constructor)................................................................................................................17
MouseSwitch(self, msg, x, y, data, flags, time, hwnd, window_name)...........................................17
KeyboardSwitch(self, msg, vk_code, scan_code, ascii, flags, time, hwnd, win_name)...................18
SubscribeMouseMove(self, func).......................................................................................................18
SubscribeMouseLeftUp(self, func).....................................................................................................18
SubscribeMouseLeftDown(self, func)................................................................................................18
SubscribeMouseLeftDbl(self, func)....................................................................................................19
SubscribeMouseRightUp(self, func)...................................................................................................19
SubscribeMouseRightDown(self, func)..............................................................................................19
SubscribeMouseRightDbl(self, func)..................................................................................................19
http://pyhook.sourceforge.net/doc_1.5.0/pyhook-module.html
SubscribeMouseMiddleUp(self, func)................................................................................................20
SubscribeMouseMiddleDown(self, func)...........................................................................................20
SubscribeMouseMiddleDbl(self, func)...............................................................................................20
SubscribeMouseWheel(self, func)......................................................................................................20
SubscribeMouseAll(self, func)............................................................................................................21
SubscribeMouseAllButtons(self, func)...............................................................................................21
SubscribeMouseAllButtonsDown(self, func)......................................................................................21
SubscribeMouseAllButtonsUp(self, func)...........................................................................................21
SubscribeMouseAllButtonsDbl(self, func)..........................................................................................22
SubscribeKeyDown(self, func)............................................................................................................22
SubscribeKeyUp(self, func)................................................................................................................22
SubscribeKeyChar(self, func).............................................................................................................22
SubscribeKeyAll(self, func).................................................................................................................23
connect(self, switch, id, func)...........................................................................................................23
disconnect(self, switch, id)................................................................................................................23
MouseAllButtonsDown......................................................................................................................23
http://pyhook.sourceforge.net/doc_1.5.0/pyhook-module.html
Package pyhook
source code
[hide private]
Submodules
pyhook.HookManager
Module HookManager
source code
[hide private]
Classes
HookConstants
Stores internal windows hook constants including hook types, mappings from virtual
keycode name to value and value to name, and event type value to name.
HookEvent
Holds information about a general hook event.
MouseEvent
Holds information about a mouse event.
KeyboardEvent
Holds information about a mouse event.
HookManager
Registers and manages callbacks for low level mouse and keyboard events.
[hide private]
Functions
GetKeyState(key_id) source code
http://pyhook.sourceforge.net/doc_1.5.0/pyhook-module.html
Class HookConstants
source code
Stores internal windows hook constants including hook types, mappings from virtual
keycode name to value and value to name, and event type value to name.
[hide private]
Class Methods
WH_MSGFILTER = -1
WH_JOURNALRECORD = 0
WH_JOURNALPLAYBACK = 1
WH_KEYBOARD = 2
WH_GETMESSAGE = 3
WH_CALLWNDPROC = 4
WH_CBT = 5
WH_SYSMSGFILTER = 6
WH_MOUSE = 7
WH_HARDWARE = 8
WH_DEBUG = 9
WH_SHELL = 10
WH_FOREGROUNDIDLE = 11
WH_CALLWNDPROCRET = 12
WH_KEYBOARD_LL = 13
http://pyhook.sourceforge.net/doc_1.5.0/pyhook-module.html
WH_MOUSE_LL = 14
WH_MAX = 15
WM_MOUSEFIRST = 0x0200
WM_MOUSEMOVE = 0x0200
WM_LBUTTONDOWN = 0x0201
WM_LBUTTONUP = 0x0202
WM_LBUTTONDBLCLK = 0x0203
WM_RBUTTONDOWN = 0x0204
WM_RBUTTONUP = 0x0205
WM_RBUTTONDBLCLK = 0x0206
WM_MBUTTONDOWN = 0x0207
WM_MBUTTONUP = 0x0208
WM_MBUTTONDBLCLK = 0x0209
WM_MOUSEWHEEL = 0x020A
WM_MOUSELAST = 0x020A
WM_KEYFIRST = 0x0100
WM_KEYDOWN = 0x0100
WM_KEYUP = 0x0101
WM_CHAR = 0x0102
WM_DEADCHAR = 0x0103
WM_SYSKEYDOWN = 0x0104
WM_SYSKEYUP = 0x0105
WM_SYSCHAR = 0x0106
WM_SYSDEADCHAR = 0x0107
WM_KEYLAST = 0x0108
http://pyhook.sourceforge.net/doc_1.5.0/pyhook-module.html
[hide private]
Method Details
MsgToName(cls, msg) source code
Class Method
Class method. Converts a message value to message name.
Parameters:
Returns: string
Name of the event
IDToName(cls, code) source code
Class Method
Class method. Gets the keycode name for the given value.
Parameters:
Returns: string
Virtual keycode name
VKeyToID(cls, vkey) source code
Class Method
Class method. Converts a virtual keycode name to its value.
Parameters:
Returns: integer
Virtual keycode value
http://pyhook.sourceforge.net/doc_1.5.0/pyhook-module.html
[hide private]
Class Variable Details
vk_to_id
Value:
msg_to_name
Value:
Class HookEvent
source code
object --+
|
HookEvent
MessageName = property(fget= GetMessageName)
[hide private]
Instance Variables
integer Message
Keyboard or mouse event message
integer Time
Seconds since the epoch when the even current
integer Window
Window handle of the foreground window at the time of the event
string WindowName
Name of the foreground window at the time of the event
[hide private]
Properties
Inherited from object: __class__
[hide private]
Method Details
__init__(self, msg, time, hwnd, window_name) source code
(Constructor)
http://pyhook.sourceforge.net/doc_1.5.0/pyhook-module.html
GetMessageName(self) source code
Returns: string
Class MouseEvent
source code
object --+
|
HookEvent --+
|
MouseEvent
__init__(self, msg, x, y, data, flags, time, hwnd, wi source co
ndow_name) de
Initializes an instance of the class.
Inherited from HookEvent: GetMessageName
from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduc
e_ex__, __repr__, __setattr__, __str__
[hide private]
Class Variables
Inherited from HookEvent: MessageName
[hide private]
Instance Variables
boolean Injected
Was this event generated programmatically?
2-tuple of Position
integer Location of the mouse event on the screen
integer Wheel
Positive if the wheel scrolls up, negative if down, zero otherwise
Inherited from HookEvent: Message, Time, Window, WindowName
[hide private]
Properties
Inherited from object: __class__
[hide private]
Method Details
__init__(self, msg, x, y, data, flags, time, hwnd, window_name) source code
(Constructor)
Initializes an instance of the class.
http://pyhook.sourceforge.net/doc_1.5.0/pyhook-module.html
Overrides: object.__init__
http://pyhook.sourceforge.net/doc_1.5.0/pyhook-module.html
Class KeyboardEvent
source code
object --+
|
HookEvent --+
|
KeyboardEvent
__init__(self, msg, vk_code, scan_code, ascii, flags, source c
time, hwnd, window_name) ode
Initializes an instances of the class.
string GetKey(self) source code
Returns: Name of the virtual keycode
boolean IsExtended(self) source code
Returns: Is this an extended key?
boolean IsInjected(self) source code
Returns: Was this event generated programmatically?
boolean IsAlt(self) source code
Returns: Was the alt key depressed?
boolean IsTransition(self) source code
Returns: Is this a transition from up to down or vice versa?
Inherited from HookEvent: GetMessageName
Inherited
from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduc
e_ex__, __repr__, __setattr__, __str__
[hide private]
Class Variables
Key = property(fget= GetKey)
Extended = property(fget= IsExtended)
Injected = property(fget= IsInjected)
Alt = property(fget= IsAlt)
Transition = property(fget= IsTransition)
Inherited from HookEvent: MessageName
http://pyhook.sourceforge.net/doc_1.5.0/pyhook-module.html
[hide private]
Instance Variables
string Ascii
ASCII value, if one exists
integer KeyID
Virtual key code
integer ScanCode
Scan code
Inherited from HookEvent: Message, Time, Window, WindowName
[hide private]
Properties
Inherited from object: __class__
[hide private]
Method Details
source cod
__init__(self, msg, vk_code, scan_code, ascii, flags, time, hwnd, windo
e
w_name)
(Constructor)
Initializes an instances of the class.
Overrides: object.__init__
GetKey(self) source code
Returns: string
IsExtended(self) source code
Returns: boolean
IsInjected(self) source code
Returns: boolean
IsAlt(self) source code
Returns: boolean
http://pyhook.sourceforge.net/doc_1.5.0/pyhook-module.html
IsTransition(self) source code
Returns: boolean
Class HookManager
source code
object --+
|
HookManager
Registers and manages callbacks for low level mouse and keyboard events.
[hide private]
Instance Methods
__init__(self) source code
Initializes an instance by setting up an empty set of handlers.
__del__(self) source code
Unhook all registered hooks.
HookMouse(self) source code
Begins watching for mouse events.
HookKeyboard(self) source code
Begins watching for keyboard events.
UnhookMouse(self) source code
Stops watching for mouse events.
UnhookKeyboard(self) source code
Stops watching for keyboard events.
MouseSwitch(self, msg, x, y, data, flags, time, hwnd, source co
window_name) de
Passes a mouse event on to the appropriate handler if one is registered.
KeyboardSwitch(self, msg, vk_code, scan_code, ascii, f source
lags, time, hwnd, win_name) code
Passes a keyboard event on to the appropriate handler if one is registered.
SubscribeMouseMove(self, func) source code
Registers the given function as the callback for this mouse event type.
SubscribeMouseLeftUp(self, func) source code
Registers the given function as the callback for this mouse event type.
SubscribeMouseLeftDown(self, func) source code
Registers the given function as the callback for this mouse event type.
SubscribeMouseLeftDbl(self, func) source code
Registers the given function as the callback for this mouse event type.
SubscribeMouseRightUp(self, func) source code
Registers the given function as the callback for this mouse event type.
SubscribeMouseRightDown(self, func) source code
Registers the given function as the callback for this mouse event type.
SubscribeMouseRightDbl(self, func) source code
http://pyhook.sourceforge.net/doc_1.5.0/pyhook-module.html
Registers the given function as the callback for this mouse event type.
SubscribeMouseMiddleUp(self, func) source code
Registers the given function as the callback for this mouse event type.
SubscribeMouseMiddleDown(self, func) source code
Registers the given function as the callback for this mouse event type.
SubscribeMouseMiddleDbl(self, func) source code
Registers the given function as the callback for this mouse event type.
SubscribeMouseWheel(self, func) source code
Registers the given function as the callback for this mouse event type.
SubscribeMouseAll(self, func) source code
Registers the given function as the callback for all mouse events.
SubscribeMouseAllButtons(self, func) source code
Registers the given function as the callback for all mouse button events.
SubscribeMouseAllButtonsDown(self, func) source code
Registers the given function as the callback for all mouse button down
events.
SubscribeMouseAllButtonsUp(self, func) source code
Registers the given function as the callback for all mouse button up events.
SubscribeMouseAllButtonsDbl(self, func) source code
Registers the given function as the callback for all mouse button double click
events.
SubscribeKeyDown(self, func) source code
Registers the given function as the callback for this keyboard event type.
SubscribeKeyUp(self, func) source code
Registers the given function as the callback for this keyboard event type.
SubscribeKeyChar(self, func) source code
Registers the given function as the callback for this keyboard event type.
SubscribeKeyAll(self, func) source code
Registers the given function as the callback for all keyboard events.
connect(self, switch, id, func) source code
Registers a callback to the given function for the event with the given ID in
the provided dictionary.
disconnect(self, switch, id) source code
Unregisters a callback for the event with the given ID in the provided
dictionary.
Inherited
from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduc
e_ex__, __repr__, __setattr__, __str__
[hide private]
Class Variables
http://pyhook.sourceforge.net/doc_1.5.0/pyhook-module.html
MouseAll = property(fset= SubscribeMouseAll)
MouseAllButtons = property(fset=
SubscribeMouseAllButtons)
MouseAllButtonsUp = property(fset=
SubscribeMouseAllButtonsUp)
MouseAllButtonsDown = property(fset=
SubscribeMouseAllButtonsD...
MouseAllButtonsDbl = property(fset=
SubscribeMouseAllButtonsDbl)
MouseWheel = property(fset= SubscribeMouseWheel)
MouseMove = property(fset= SubscribeMouseMove)
MouseLeftUp = property(fset= SubscribeMouseLeftUp)
MouseLeftDown = property(fset= SubscribeMouseLeftDown)
MouseLeftDbl = property(fset= SubscribeMouseLeftDbl)
MouseRightUp = property(fset= SubscribeMouseRightUp)
MouseRightDown = property(fset= SubscribeMouseRightDown)
MouseRightDbl = property(fset= SubscribeMouseRightDbl)
MouseMiddleUp = property(fset= SubscribeMouseMiddleUp)
MouseMiddleDown = property(fset=
SubscribeMouseMiddleDown)
MouseMiddleDbl = property(fset= SubscribeMouseMiddleDbl)
KeyUp = property(fset= SubscribeKeyUp)
KeyDown = property(fset= SubscribeKeyDown)
KeyChar = property(fset= SubscribeKeyChar)
KeyAll = property(fset= SubscribeKeyAll)
[hide private]
Instance Variables
http://pyhook.sourceforge.net/doc_1.5.0/pyhook-module.html
boolean key_hook
Is a keyboard hook set?
dictionary keyboard_funcs
Callbacks for keyboard events
dictionary mouse_funcs
Callbacks for mouse events
boolean mouse_hook
Is a mouse hook set?
[hide private]
Properties
Inherited from object: __class__
[hide private]
Method Details
__init__(self) source code
(Constructor)
Initializes an instance by setting up an empty set of handlers.
Overrides: object.__init__
MouseSwitch(self, msg, x, y, data, flags, time, hwnd, window_name) source code
KeyboardSwitch(self, msg, vk_code, scan_code, ascii, flags, time, hwnd, source cod
e
win_name)
Passes a keyboard event on to the appropriate handler if one is registered.
Parameters:
SubscribeMouseMove(self, func) source code
Registers the given function as the callback for this mouse event type. Use the MouseMove
property as a shortcut.
Parameters:
SubscribeMouseLeftUp(self, func) source code
Registers the given function as the callback for this mouse event type. Use the MouseLeftUp
property as a shortcut.
Parameters:
SubscribeMouseLeftDown(self, func) source code
Registers the given function as the callback for this mouse event type. Use the MouseLeftDown
property as a shortcut.
Parameters:
SubscribeMouseLeftDbl(self, func) source code
Registers the given function as the callback for this mouse event type. Use the MouseLeftDbl
property as a shortcut.
Parameters:
SubscribeMouseRightUp(self, func) source code
Registers the given function as the callback for this mouse event type. Use the MouseRightUp
http://pyhook.sourceforge.net/doc_1.5.0/pyhook-module.html
property as a shortcut.
Parameters:
SubscribeMouseRightDown(self, func) source code
Registers the given function as the callback for this mouse event type. Use the
MouseRightDown property as a shortcut.
Parameters:
SubscribeMouseRightDbl(self, func) source code
Registers the given function as the callback for this mouse event type. Use the MouseRightDbl
property as a shortcut.
Parameters:
SubscribeMouseMiddleUp(self, func) source code
Registers the given function as the callback for this mouse event type. Use the MouseMiddleUp
property as a shortcut.
Parameters:
SubscribeMouseMiddleDown(self, func) source code
Registers the given function as the callback for this mouse event type. Use the
MouseMiddleDown property as a shortcut.
Parameters:
SubscribeMouseMiddleDbl(self, func) source code
Registers the given function as the callback for this mouse event type. Use the
http://pyhook.sourceforge.net/doc_1.5.0/pyhook-module.html
SubscribeMouseWheel(self, func) source code
Registers the given function as the callback for this mouse event type. Use the MouseWheel
property as a shortcut.
Parameters:
SubscribeMouseAll(self, func) source code
Registers the given function as the callback for all mouse events. Use the MouseAll property as
a shortcut.
Parameters:
SubscribeMouseAllButtons(self, func) source code
Registers the given function as the callback for all mouse button events. Use the
MouseButtonAll property as a shortcut.
Parameters:
SubscribeMouseAllButtonsDown(self, func) source code
Registers the given function as the callback for all mouse button down events. Use the
MouseAllButtonsDown property as a shortcut.
Parameters:
SubscribeMouseAllButtonsUp(self, func) source code
Registers the given function as the callback for all mouse button up events. Use the
http://pyhook.sourceforge.net/doc_1.5.0/pyhook-module.html
SubscribeMouseAllButtonsDbl(self, func) source code
Registers the given function as the callback for all mouse button double click events. Use the
MouseAllButtonsDbl property as a shortcut.
Parameters:
SubscribeKeyDown(self, func) source code
Registers the given function as the callback for this keyboard event type. Use the KeyDown
property as a shortcut.
Parameters:
SubscribeKeyUp(self, func) source code
Registers the given function as the callback for this keyboard event type. Use the KeyUp
property as a shortcut.
Parameters:
SubscribeKeyChar(self, func) source code
Registers the given function as the callback for this keyboard event type. Use the KeyChar
property as a shortcut.
Note: this is currently non-functional, no WM_*CHAR messages are processed by the
keyboard hook.
Parameters:
SubscribeKeyAll(self, func) source code
http://pyhook.sourceforge.net/doc_1.5.0/pyhook-module.html
Registers the given function as the callback for all keyboard events. Use the KeyAll property as
a shortcut.
Parameters:
connect(self, switch, id, func) source code
Registers a callback to the given function for the event with the given ID in the provided
dictionary. Internal use only.
Parameters:
disconnect(self, switch, id) source code
Unregisters a callback for the event with the given ID in the provided dictionary. Internal use
only.
Parameters:
[hide private]
Class Variable Details
MouseAllButtonsDown
Value:
property(fset= SubscribeMouseAllButtonsDown)