Package: python-xdo Version: 0.3-2 Severity: wishlist Tags: patch Hi,
Please find attached patches adding support for the send_keysequence_window() function, which lets me drive a fully automated Debian Installation within kvm/qemu for regression testing purposes. I haven't really checked the clearmodifiers part (which I've borrowed from enter_text_window()) since I'm mostly sending simple keystrokes: typing hostnames, passwords, login name, etc. means I'm sending basically: - letters, - shift+letters, - space, - Tab, - Return, - Up, - Down. Tested on a jessie system (libxdo3:amd64 = 1:3.20140805.1-2). Thanks for considering. Cheers, -- Cyril Brulebois -- Debian Consultant @ DEBAMAX -- https://debamax.com/
>From 4c0d78cc2f7f0c5e33ed9373025a6c3007299eae Mon Sep 17 00:00:00 2001 From: Cyril Brulebois <[email protected]> Date: Mon, 13 Feb 2017 01:12:54 +0100 Subject: [PATCH 3/4] Add support for send_keysequence_window(). Mimick the enter_text_window() behaviour, including the clearmodifiers part but excluding the encoding part. This was tested successfully by driving a full Debian installation using Debian Installer within kvm/qemu. Signed-off-by: Cyril Brulebois <[email protected]> --- xdo/__init__.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ xdo/_xdo.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/xdo/__init__.py b/xdo/__init__.py index d3c99c3..751cd9e 100644 --- a/xdo/__init__.py +++ b/xdo/__init__.py @@ -91,6 +91,58 @@ class xdo(object): return ret + def send_keysequence_window(self, keysequence, clearmodifiers=True, + delay=timedelta(microseconds=12000), + window=CURRENTWINDOW): + """ + Send a keysequence to the specified window. + + This allows you to send keysequences by symbol name. Any combination + of X11 KeySym names separated by '+' are valid. Single KeySym names + are valid, too. + + Examples: + "l" + "semicolon" + "alt+Return" + "Alt_L+Tab" + + If you want to type a string, such as "Hello world." you want to instead + use xdo_enter_text_window. + + :param window: + The window you want to send the keysequence to or CURRENTWINDOW + :param keysequence: + The string keysequence to send. + :param delay: + The delay between keystrokes in microseconds. + :param clearmodifiers: + Whether to clear any current modifier keys before sending + the keysequence (defaults to True). + """ + if type(delay) == timedelta: + delay_int = int(delay.total_seconds() * 1000000) + elif type(delay) == int: + delay_int = delay + else: + raise TypeError("delay parameter should be either a timedelta or an int") + + if clearmodifiers: + active_mods_n = ctypes.c_int(0) + active_mods = _charcodemap_ptr() + _libxdo.xdo_get_active_modifiers(self._xdo, ctypes.byref(active_mods), + ctypes.byref(active_mods_n)) + _libxdo.xdo_clear_active_modifiers(self._xdo, window, active_mods, + active_mods_n) + ret = _libxdo.xdo_send_keysequence_window(self._xdo, window, keysequence, + delay_int) + if clearmodifiers: + _libxdo.xdo_set_active_modifiers(self._xdo, window, active_mods, + active_mods_n) + _libc.free(active_mods) + + return ret + @deprecated def type(self, string, clearmodifiers=True, delay=12000, window=CURRENTWINDOW): """ diff --git a/xdo/_xdo.py b/xdo/_xdo.py index ef4fd74..eaa9c72 100644 --- a/xdo/_xdo.py +++ b/xdo/_xdo.py @@ -110,6 +110,34 @@ want instead xdo_send_keysequence_window(...). """ # ============================================================================ +# int xdo_send_keysequence_window(const xdo_t *xdo, Window window, +# const char *keysequence, useconds_t delay); +libxdo.xdo_send_keysequence_window.argtypes = ( + xdo_ptr, window_t, c_char_p, useconds_t) +libxdo.xdo_send_keysequence_window.restype = c_int +libxdo.xdo_send_keysequence_window.errcheck = _errcheck +libxdo.xdo_send_keysequence_window.__doc__ = """ +Send a keysequence to the specified window. + +This allows you to send keysequences by symbol name. Any combination +of X11 KeySym names separated by '+' are valid. Single KeySym names +are valid, too. + +Examples: + "l" + "semicolon" + "alt+Return" + "Alt_L+Tab" + +If you want to type a string, such as "Hello world." you want to instead +use xdo_enter_text_window. + +:param window: The window you want to send the keysequence to or CURRENTWINDOW +:param keysequence: The string keysequence to send. +:param delay: The delay between keystrokes in microseconds. +""" + +# ============================================================================ # int xdo_focus_window(const xdo_t *xdo, Window wid); libxdo.xdo_focus_window.argtypes = (xdo_ptr, window_t) libxdo.xdo_focus_window.restype = c_int -- 2.1.4
>From a94bcbf1a3950dc149f44f5b7628942089805529 Mon Sep 17 00:00:00 2001 From: Cyril Brulebois <[email protected]> Date: Mon, 13 Feb 2017 00:50:19 +0100 Subject: [PATCH 4/4] Unmark send_keysequence_window() as unimplemented. Signed-off-by: Cyril Brulebois <[email protected]> --- xdo/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xdo/__init__.py b/xdo/__init__.py index 751cd9e..4edef5a 100644 --- a/xdo/__init__.py +++ b/xdo/__init__.py @@ -47,8 +47,8 @@ class xdo(object): Type a string to the specified window. If you want to send a specific key or key sequence, such as - "alt+l", you want instead the (currently unimplemented) - function ``send_keysequence_window(...)``. + "alt+l", you want instead the ``send_keysequence_window(...)`` + function. :param string: The string to type, like "Hello world!" -- 2.1.4
_______________________________________________ Python-modules-team mailing list [email protected] http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/python-modules-team

