def execute(self, window): zero = pointer(c_ulong(0)) inputs = [ MouseInput(0, 0, flag[1], flag[0], 0, zero) for flag in self._flags ] array = make_input_array(inputs) send_input_array(array)
def send_keyboard_events(cls, events): """ Send a sequence of keyboard events. Positional arguments: events -- a sequence of 3-tuples of the form (keycode, down, timeout), where keycode (int): virtual key code. down (boolean): True means the key will be pressed down, False means the key will be released. timeout (int): number of seconds to sleep after the keyboard event. """ items = [] for keycode, down, timeout in events: input = KeyboardInput(keycode, down) items.append(input) if timeout: array = make_input_array(items) items = [] send_input_array(array) time.sleep(timeout) if items: array = make_input_array(items) send_input_array(array) if timeout: time.sleep(timeout)
def _process_recognition(self, node, extras): updown = extras["updown"] if "button" in extras: button = extras["button"] else: button = 0 key = (button, updown) flags = self.flag_map[key] input = sendinput.MouseInput(0, 0, 0, flags, 0, pointer(c_ulong(0))) array = sendinput.make_input_array([input]) sendinput.send_input_array(array)
def send_keyboard_events(cls, events): """ Send a sequence of keyboard events. Positional arguments: events -- a sequence of tuples of the form (keycode, down, timeout), where keycode (int): Win32 Virtual Key code. down (boolean): True means the key will be pressed down, False means the key will be released. timeout (int): number of seconds to sleep after the keyboard event. or (character, down, timeout, is_text), where character (str): Unicode character. down (boolean): True means the key will be pressed down, False means the key will be released. timeout (int): number of seconds to sleep after the keyboard event. is_text (boolean): True means that the keypress is targeted at a window or control that accepts Unicode text. """ layout = cls.get_current_layout() # Process and send keyboard events. items = [] for event in events: if len(event) == 3: # Pass scancode=0 to press keys via virtual-key codes # instead of scancodes. keycode, down, timeout = event input_structure = KeyboardInput( keycode, down, # scancode=0, layout=layout) elif len(event) == 4 and event[3]: character, down, timeout = event[:3] input_structure = KeyboardInput(0, down, scancode=character) else: raise ValueError("invalid keyboard event tuple: %r" % event) items.append(input_structure) if timeout: array = make_input_array(items) items = [] send_input_array(array) time.sleep(timeout) if items: array = make_input_array(items) send_input_array(array) if timeout: time.sleep(timeout)
def execute(self, window): # Ensure that the primary mouse button is the *left* button before # sending events. primary_changed = windll.user32.SwapMouseButton(0) # Prepare and send the mouse events. zero = pointer(c_ulong(0)) inputs = [ MouseInput(0, 0, flag[1], flag[0], 0, zero) for flag in self._flags ] array = make_input_array(inputs) send_input_array(array) # Swap the primary mouse button back if it was previously set to # *right*. if primary_changed: windll.user32.SwapMouseButton(1)
def send_keyboard_events(cls, events): """ Send a sequence of keyboard events. Positional arguments: events -- a sequence of tuples of the form (keycode, down, timeout), where keycode (int): Win32 Virtual Key code. down (boolean): True means the key will be pressed down, False means the key will be released. timeout (int): number of seconds to sleep after the keyboard event. or (character, down, timeout, is_text), where character (str): Unicode character. down (boolean): True means the key will be pressed down, False means the key will be released. timeout (int): number of seconds to sleep after the keyboard event. is_text (boolean): True means that the keypress is targeted at a window or control that accepts Unicode text. """ items = [] for event in events: if len(event) == 3: keycode, down, timeout = event input_structure = KeyboardInput(keycode, down) elif len(event) == 4 and event[3]: character, down, timeout = event[:3] input_structure = KeyboardInput(0, down, scancode=character) items.append(input_structure) if timeout: array = make_input_array(items) items = [] send_input_array(array) time.sleep(timeout) if items: array = make_input_array(items) send_input_array(array) if timeout: time.sleep(timeout)