Interfaces¶
-
macpy.record(record_type, stop_key=None, timer=None)¶ Record events of record_type and return a list.
Parameters: - record_type (RecordType) – The type of events to record.
- stop_key (Key) – The key or button which will end the
recording. If stop_key is
Nonethe recording will go on until timer runs out. - timer (float) – The duration of recording session. If timer is
Nonethe session will go on until specified key is pressed.
Returns: A list of recorded events.
Return type: [Event]
-
macpy.replay(event_list, delay=0)¶ Replay events from a sequence.
Parameters:
Keyboard¶
-
class
macpy.Keyboard¶ Keyboard interface object.
Allows simulating keyboard input as well as reading data from connected physical keyboards.
-
close()¶ Close opened resources and cleanly exit mainloop.
Call this method when you are done with this object.
-
get_key_state(key)¶ Check whether the key is pressed or released.
Parameters: key (Key) – The key to check. Returns: Current state of the key. Return type: KeyState
-
install_keyboard_hook(callback, grab=False)¶ Installs a low level hook that sends all keyboard input to the callback.
Callback must take a single event argument.
For event definition see
KeyboardEvent.Parameters:
-
uninstall_keyboard_hook()¶ Uninstall keyboard hook and stop hook’s loop.
You don’t have to explicitly call this method, calling
close()automatically removes hook if it’s installed.
-
init_hotkeys()¶ Initialize hotkey loop.
You need to call this method once before using any hotkey related methods.
-
uninit_hotkeys()¶ Deinitialize hotkey loop.
You don’t have to explicitly call this method, calling
close()automatically stop hotkey loop if it’s started.
-
register_hotkey(key, modifiers, callback)¶ Register a key combination that once pressed triggers callback.
Note
It is currently not possible to define hotkeys which trigger only with e.g.
KEY_LEFTSHIFT. Left/right keys are automatically converted to generic modifier e.g.KEY_SHIFT.Parameters: Returns: A hotkey object.
Return type:
-
unregister_hotkey(hotkey)¶ Unegister a previously registered hotkey.
Parameters: hotkey (HotKey) – A hotkey object as returned by e.g. register_hotkey().
-
register_hotstring(string, triggers, callback)¶ Register a string that once typed will trigger callback.
If triggers are empty, the string will trigger as soon as it’s typed. Otherwise it will only trigger if it’s followed by one of the triggers.
Keyboard hook needs to be installed for hotstrings to work. Otherwise this method raises
RuntimeError.Parameters: Returns: A hotstring object.
Return type: Raises:
-
unregister_hotstring(hotstring)¶ Unregister a previously registered hotstring.
Parameters: hotstring (HotString) – A hotstring object as returned by e.g. register_hotstring().
-
keypress(key, state=None)¶ Simulate a key press/release event.
Parameters:
-
type(string)¶ Type a given string.
Depending on underlying implementation and current platform this may be more efficient then using
keypress().Parameters: string (str) – String to type.
-
Pointer¶
-
class
macpy.Pointer¶ Pointer interface object.
Allows simulating pointer input as well as reading data from connected physical pointing devices.
-
close()¶ Close opened resources and cleanly exit mainloop.
Call this method when you are done with this object.
-
install_pointer_hook(callback, grab=False)¶ Installs a low level hook that sends all pointer events to the callback.
Callback must take a single event argument.
For event definitions see
PointerEventMotion,PointerEventButtonandPointerEventAxis.Parameters:
-
uninstall_pointer_hook()¶ Uninstalls pointer hook and stops hook’s loop.
You don’t have to explicitly call this method. Calling
close()will remove the hook automatically if it’s installed.
-
warp(x, y, relative=False)¶ Warp pointer to the given location on screen.
Pointer cannot be warped beyond the bounds of the virtual screen.
Parameters:
-
scroll(axis, value)¶ Simulate mouse scroll wheel along the given axis.
Note
value is platform dependent, so the same value may result in different amount scrolled depending on current platform.
Parameters: - axis (PointerAxis) – The axis along which to scroll.
- value (int) – The amount which to scroll. See Note.
-
click(key, state=None)¶ Simulate a mouse click.
Parameters:
-
Window¶
-
class
macpy.Window(window)¶ Window interface object.
Allows manipulating windows on supported platforms: activating, minimizing, closing, moving, etc.
Rather than instanciating this class directly, use one of the class methods, e.g.
get_active().-
pid¶ PID of the process to which this window belongs. Might be
Noneif window is closed or if window does not set this property.Type: int
-
classmethod
install_window_hook(callback)¶ Hook window creation, destruction and focus change.
Callback is called with
WindowEventas a single argument.Parameters: callback (Callable) – A callable to receive events. Raises: NotImplementedError
-
classmethod
uninstall_window_hook()¶ Remove window hook.
Since hook runs in a separate thread, you should call this method once you are done for a clean exit.
Raises: NotImplementedError
-
classmethod
list_windows()¶ Return a tuple of currently open window objects.
Returns: A tuple of currently open windows. Return type: (Window, …) Raises: NotImplementedError
-
classmethod
get_active()¶ Return currently focused window.
Returns: A window object. Return type: Window Raises: NotImplementedError
-
classmethod
get_under_pointer()¶ Return the window that is currently under pointer.
Returns: A window object. Return type: Window Raises: NotImplementedError
-
classmethod
get_by_class(wm_class)¶ Return the first window whose
wm_classmatches wm_class.Parameters: wm_class (str) – Window class to match. Returns: A window object. Return type: Window Raises: NotImplementedError
-
classmethod
get_by_title(title)¶ Return the first window whose
titlematches title.Parameters: title (str) – Partial window title to match. Returns: A window object. Return type: Window Raises: NotImplementedError
-
state¶ This window’s state.
Returns: Window state. Return type: WindowState
-
position¶ This window’s position on screen in pixels.
Returns: A namedtuple of x and y coordinates. Return type: (int, int)
-
size¶ This window’s size in pixels.
Returns: A namedtuple of width and height. Return type: (int, int)
-
activate()¶ Activate this window.
-
restore()¶ Restore this window.
-
minimize()¶ Minimize this window.
-
maximize()¶ Maximize this window.
-
resize(width, height)¶ Resize this window to the given width and height in pixels.
Parameters:
-
move(x, y)¶ Move this window to the given screen x and y coordinates in pixels.
Parameters:
-
close()¶ Request this window to close.
If there are unsaved data, the window may refuse to close.
-
force_close()¶ Forcibly close this window.
-
send_event(event)¶ Send an input event dirrectly to this window, regardless of whether it has input focus.
Valid input events are
KeyboardEvent,PointerEventMotion,PointerEventButtonandPointerEventAxis.Note
For events that contain coordinates, these coordinates are always relative to this window.
Parameters: event (Event) – Event to send.
-