Exemple #1
0
 def mouseup(posx,posy,device,isLeft):
     mousemove(posx,posy,False,False,device)
     if isLeft:
         fake_input(display, X.ButtonRelease, X.Button1)
     else:
         fake_input(display, X.ButtonRelease, X.Button3)
     display.sync()
Exemple #2
0
 def release(self, x, y, button=1):
     if isinstance(button, str): 
         button = BUTTONS.get(button)
         if not button: return 
     self.move(x, y)
     fake_input(self.display, X.ButtonRelease, button)
     self.display.sync()
Exemple #3
0
def Fake_Key(Key):
	d=display.Display()
	Key = String_to_Keycode(Key)
	xtest.fake_input(d, X.KeyPress, Key) 
	d.sync()
	xtest.fake_input(d, X.KeyRelease, Key)
	d.sync()
Exemple #4
0
def mouse_move(x, y):
    from Xlib.display import Display
    from Xlib import X
    from Xlib.ext.xtest import fake_input
    d = Display()
    fake_input(d, X.MotionNotify, x=x, y=y)
    d.flush()
Exemple #5
0
def _keyUp(key):
    """Performs a keyboard key release (without the press down beforehand).

    Args:
      key (str): The key to be released up. The valid names are listed in
      pyautogui.KEY_NAMES.

    Returns:
      None
    """

    """
    Release a given character key. Also works with character keycodes as
    integers, but not keysyms.
    """
    if key not in keyboardMapping or keyboardMapping[key] is None:
        return

    if type(key) == int:
        keycode = key
    else:
        keycode = keyboardMapping[key]

    fake_input(_display, X.KeyRelease, keycode)
    _display.sync()
Exemple #6
0
 def run(self):
     print "START AUTOCLICKING THREAD"
     if len(self.clicks) > 0:
         i = 1
         while not self.stop is True:
             if not self.loops == 0 and i > self.loops:
                 break
             i += 1
             for x, y, button, delay in self.clicks:
                 if self.stop is True:
                     break
                 print "Clicking in %d, %d" % (x, y)
                 if self.wTree is not None:
                     self.update_status(x, y, button, delay)
                 self.root.warp_pointer(x, y)
                 self.display.sync()
                 sleep(0.1)
                 fake_input(self.display, X.ButtonPress, button)
                 self.display.sync()
                 sleep(0.1)
                 fake_input(self.display, X.ButtonRelease, button)
                 self.display.sync()
                 start_time = localtime().tm_sec
                 while not (start_time - localtime().tm_sec) % delay == 0 \
                         or localtime().tm_sec == start_time:
                     while gtk.events_pending():
                         gtk.main_iteration()
                     click = self.root.query_pointer().mask
                     if self.stop is True or click > 500 and click < 600:
                         break
                     sleep(0.1)
     if self.wTree is not None:
         self.wTree.get_widget("btnStop").set_property("sensitive", False)
         self.wTree.get_widget("btnStart").set_property("sensitive", True)
     self.stop = True
Exemple #7
0
 def mousedown(posx,posy,device,isLeft):
     mousemove(posx,posy,False,False,device)
     if isLeft:
         fake_input(display, X.ButtonPress, X.Button1)
     else:
         fake_input(display, X.ButtonPress, X.Button3)
     display.sync()
Exemple #8
0
 def click(self, button=BUTTON_LEFT):
     display = XlibDisplay()
     for event, button in \
             [(X.ButtonPress, button), (X.ButtonRelease, button)]:
         LOGGER.debug('%s %s', event, button)
         xtest.fake_input(display, event, button)
         display.sync()
Exemple #9
0
    def run(self):
        """Do a single keyboard action using xlib"""
        if isinstance(self.key, six.string_types):
            key = self.key
            self.key = Xlib.XK.string_to_keysym(self.key)
            if self.key == 0:
                self.key = Xlib.XK.string_to_keysym(spec_keysyms[key])
            self.key = _display.keysym_to_keycode(self.key)
            if self.key == 0:
                raise RuntimeError('Key {} not found!'.format(self.key))
            self.is_shifted = key.isupper() or key in '~!@#$%^&*()_+{}|:"<>?'
        elif not isinstance(self.key, six.integer_types):
            raise TypeError('self.key = {} is not a string or integer'.format(self.key))

        self._key_modifiers(self.ctrl, (self.shift or self.is_shifted),
                            self.alt, action = X.KeyPress)
        if self.down:
            fake_input(_display, X.KeyPress, self.key)
            _display.sync()
        if self.up:
            fake_input(_display, X.KeyRelease, self.key)
            _display.sync()
        self._key_modifiers(self.ctrl, (self.shift or self.is_shifted),
                            self.alt, action = X.KeyRelease)
        _display.sync()
Exemple #10
0
    def __sendStringClipboard(self, string, pasteCommand):
        logger.debug("Sending string: %r", string)

        if pasteCommand is None:
            if common.USING_QT:
                self.sem = threading.Semaphore(0)
                self.app.exec_in_main(self.__fillSelection, string)
                self.sem.acquire()
            else:
                self.__fillSelection(string)

            focus = self.localDisplay.get_input_focus().focus
            xtest.fake_input(focus, X.ButtonPress, X.Button2)
            xtest.fake_input(focus, X.ButtonRelease, X.Button2)

        else:
            if common.USING_QT:
                self.sem = threading.Semaphore(0)
                self.app.exec_in_main(self.__fillClipboard, string)
                self.sem.acquire()
            else:
                self.__fillClipboard(string)

            self.mediator.send_string(pasteCommand)

            if common.USING_QT:
                self.app.exec_in_main(self.__restoreClipboard)

        logger.debug("Send via clipboard done")
Exemple #11
0
def move( x=0, y=0, point=None ):
    """
    Changes the mouse position to the specified coords.

    Arguments:
    - self: The main object pointer.
    - x: The x position.
    - y: the y position.
    """
    global isGnome

    if point is not None:
        x, y = point.x, point.y

    if isGnome:
        try:
            reg.generateMouseEvent( x, y, 'abs' )
        except:
            isGnome = False
    else:
        xtest.fake_input( xDisplay, X.MotionNotify, x = x, y = y)
        #display.sync()
        xDisplay.flush()

    return True
Exemple #12
0
    def click(self, button):
        self.clickx = self.x
        self.clicky = self.y

        fake_input(self.wind.display, X.ButtonPress, button)
        fake_input(self.wind.display, X.ButtonRelease, button)
        self.wind.display.sync()
Exemple #13
0
		def sendSingle(self, char):
			disp = self.disp
			ksym = Xlib.XK.string_to_keysym(char)
			kcode = disp.keysym_to_keycode(ksym)
			xtest.fake_input(disp, Xlib.X.KeyPress, kcode)
			xtest.fake_input(disp, Xlib.X.KeyRelease, kcode)
			disp.flush()
Exemple #14
0
 def move_desktop(self, direction):
     combo = (XK.XK_Alt_L, XK.XK_Control_L) + (direction,)
     for action in (X.KeyPress, X.KeyRelease):
         for keysym in combo:
             key = self.display.keysym_to_keycode(keysym)
             fake_input(self.display, action, key)
         self.display.sync()
Exemple #15
0
 def __fakeKeypress(self, keyName, interval=0):
     keyCode = self.__lookupKeyCode(keyName)
     xtest.fake_input(self.rootWindow, X.KeyPress, keyCode)
     if interval:
         self.__sendSleep(interval)
     xtest.fake_input(self.rootWindow, X.KeyRelease, keyCode)
     if interval:
         self.__sendSleep(interval)
def Release(x, y, button=1):
    Move(x, y)
    '''
    Redefined right button flag 3 to 2
    '''
    if button == 2:
        button = 3
    fake_input(display, X.ButtonRelease, button)
def Press(x, y, button=1):
    Move(x, y)
    '''
    Redefined right button flag 3 to 2
    '''
    if button == 2:
        button = 3
    fake_input(display, X.ButtonPress, button)
Exemple #18
0
def girale(mov):
	up=4 #4 scrolls up 
	down=5 #5 scrolls down 
	d = Display()
	m = up if mov==1 else down
	fake_input(d,X.ButtonPress,m)
	d.sync()
	fake_input(d,X.ButtonRelease,m)
	d.sync()
 def sendMouseButton(self, buttonIndex, isDown):
     if buttonIndex < 1:
         buttonIndex = 1
     if isDown:
         xtest.fake_input(self.display.screen().root, X.ButtonPress, detail=buttonIndex)
         #os.system("xdotool mousedown 1" )
     else:
         xtest.fake_input(self.display.screen().root, X.ButtonRelease, detail=buttonIndex)
         #os.system("xdotool mouseup 1")
     self.display.sync()
Exemple #20
0
def mouse_click(button=1):
    from Xlib import X
    from Xlib.display import Display
    from Xlib.ext.xtest import fake_input

    d = Display()
    fake_input(d, X.ButtonPress, button)
    d.sync()
    fake_input(d, X.ButtonRelease, button)
    d.sync()
Exemple #21
0
def press_at(x, y):
    window = display.get_input_focus().focus
    g = window.get_geometry()
    if x < 0:
        x += g.width
    if y < 0:
        y += g.height
    window.warp_pointer(x, y)
    display.sync()
    fake_input(display, ButtonPress, 1)
    display.sync()
Exemple #22
0
    def __send_key(self, x_event, key_code):
        key = key_code.X11

        if key is None:
            print("key not defined on X11!")
            pass

        d = Display()
        x11key = d.keysym_to_keycode(XK.string_to_keysym(key))
        fake_input(d, x_event, x11key)
        d.sync()
Exemple #23
0
def send_event(key, mod, act):
    print 'send key,mod,act:'+str(key)+','+str(mod)+','+str(act)
    if key in ['MoveLeft', 'MoveRight', 'MoveUp', 'MoveDown']:
       if key=='MoveLeft':
          disp.warp_pointer(-act, 0)
       if key=='MoveRight':
          disp.warp_pointer(act, 0)
       if key=='MoveUp':
          disp.warp_pointer(0, -act)
       if key=='MoveDown':
          disp.warp_pointer(0, act)
       return

    if key in [X.Button1,X.Button2,X.Button3,X.Button4,X.Button5]:
       wind=root
       window=root.query_pointer().child
       #wind=root.query_pointer().child
       #window=root.query_pointer().child.query_pointer().child #in some linux, it is root.query_pointer().child
       key_action=[X.ButtonPress,X.ButtonRelease][act]
       if act:
          KeyAction=ButtonRelease
       else:
            KeyAction=ButtonPress
            #try:
            #    window.configure(stack_mode=X.Above)  #set foreground window
            #except:
            #       window=wind
            #       window.configure(stack_mode=X.Above)
            #window.set_input_focus(X.RevertToParent, X.CurrentTime)
    else:
         wind=disp.get_input_focus().focus
         windows=wind.query_pointer().child
         key=string_to_keycode(key)
         key_action=[X.KeyPress,X.KeyRelease][act]
         if act:
            KeyAction=KeyRelease
         else:
              KeyAction=KeyPress
    try:
        window.query_pointer()
    except:
           window=wind
    x=window.query_pointer().win_x
    y=window.query_pointer().win_y
    evt_key=KeyAction(detail=key, state=mod,
                      root=root, window=window, child=X.NONE,
                      root_x=0, root_y=0, event_x=x, event_y=y,
                      same_screen=1, time=X.CurrentTime
                     )
    if key_action in [X.ButtonPress, X.ButtonRelease]:
        fake_input(disp, key_action, key) #only use fake_input in mouse button, for it won't send modifiers
    else:
         #disp.send_event(X.PointerWindow, evt_key)   #if keyboard event, to use X.InputFocus
         window.send_event(evt_key)
Exemple #24
0
def transmit(sol):
	d = display.Display()
	s = d.screen()
	root = s.root

	for p in sol:
		x,y = coords[p]	
		root.warp_pointer(x, y)
		xtest.fake_input(d, Xlib.X.ButtonPress, 1)
		time.sleep(0.1)
		xtest.fake_input(d, Xlib.X.ButtonRelease, 1)
		d.sync()

		time.sleep(0.1)	

	time.sleep(1)	

	x = 600
	y = 495

	root.warp_pointer(x, y)
	xtest.fake_input(d, Xlib.X.ButtonPress, 1)
	time.sleep(0.1)
	xtest.fake_input(d, Xlib.X.ButtonRelease, 1)
	d.sync()
 def emulateWritingString(d, cmd, delay, k=None):
     '''
         Processes a string by writing it to the screen with a certain delay
     '''
     for c in cmd:
         if k is not None:
             # Emulate the key.
             emulateSpecialKey(d, k, delay)
         keysym = XK.string_to_keysym(c)
         if keysym == 0:
             # Its a symbol, not a letter.
             emulateSpecialKey(d, c, delay)
         else:
             # It's a letter
             keycode = d.keysym_to_keycode(keysym)
             # If it's uppercase, we press shift.
             if c.isupper():
                 xtest.fake_input(d, X.KeyPress, kmap[u'shift_l'])
             # Its even a specialer key :P
             if keycode == 0:
                 emulateSpecialKey(d, c, delay)
             else:
                 xtest.fake_input(d, X.KeyPress, keycode)
                 d.flush()
                 time.sleep(delay)
                 xtest.fake_input(d, X.KeyRelease, keycode)
                 # Delay time between letters
     #            time.sleep(0.025)
             # If it's uppercase, we release shift.
             if c.isupper():
                 xtest.fake_input(d, X.KeyRelease, kmap[u'shift_l'])
         d.flush()
Exemple #26
0
def x11Key(display, state, raw):
    if type(raw) in (str, unicode):
        keysym = keyEventMap.get(raw)
        if keysym is None:
            try:
                keysym = ord(raw)
            except TypeError:
                raise ProtocolError('Unknown x11 key {}'.format(raw))
    else:
        keysym = raw

    keycodes = display.keysym_to_keycodes(keysym)
    if len(keycodes) == 0:
        return
    keycode = keycodes[0]

    if 'down' in state:
        if keycode[1] == 1:  # ie this keycode is in modmap group 2, which means shift needs to be pressed... yuck, X keyboard sucks!
            fake_input(display, X.KeyPress, detail=display.keysym_to_keycode(misckeysyms.XK_Shift_L))
            display.sync()

        fake_input(display, X.KeyPress, detail=keycode[0])
        display.sync()

    if 'up' in state:
        fake_input(display, X.KeyRelease, detail=keycode[0])
        display.sync()

        if keycode[1] == 1:
            fake_input(display, X.KeyRelease, detail=display.keysym_to_keycode(misckeysyms.XK_Shift_L))
            display.sync()
Exemple #27
0
 def send_key(display, window, keycodes):
     '''Send a KeyPress and KeyRelease event'''
     if not type(keycodes) in (tuple, list):
         keycodes = (keycodes,)
     # send with modifier
     for keycode in keycodes:
         xtest.fake_input(window,
                          X.KeyPress,
                          display.keysym_to_keycode(keycode))
     for keycode in reversed(keycodes):
         xtest.fake_input(window,
                          X.KeyRelease,
                          display.keysym_to_keycode(keycode))
     display.sync()
Exemple #28
0
def _keyDown(key):
    """Performs a keyboard key press without the release. This will put that
    key in a held down state.

    NOTE: For some reason, this does not seem to cause key repeats like would
    happen if a keyboard key was held down on a text field.

    Args:
      key (str): The key to be pressed down. The valid names are listed in
      pyautogui.KEY_NAMES.

    Returns:
      None
    """
    if key not in keyboardMapping or keyboardMapping[key] is None:
        return

    if type(key) == int:
        fake_input(_display, X.KeyPress, key)
        _display.sync()
        return

    needsShift = pyautogui.isShiftCharacter(key)
    if needsShift:
        fake_input(_display, X.KeyPress, keyboardMapping['shift'])

    fake_input(_display, X.KeyPress, keyboardMapping[key])

    if needsShift:
        fake_input(_display, X.KeyRelease, keyboardMapping['shift'])
    _display.sync()
Exemple #29
0
    def __sendMouseClickRelative(self, xoff, yoff, button):
        # Get current pointer position
        pos = self.rootWindow.query_pointer()

        xCoord = pos.root_x + xoff
        yCoord = pos.root_y + yoff

        self.rootWindow.warp_pointer(xCoord, yCoord)
        xtest.fake_input(self.rootWindow, X.ButtonPress, button, x=xCoord, y=yCoord)
        xtest.fake_input(self.rootWindow, X.ButtonRelease, button, x=xCoord, y=yCoord)

        self.rootWindow.warp_pointer(pos.root_x, pos.root_y)

        self.__flush()
Exemple #30
0
def move( x=0, y=0, point=None ):
    """
    Changes the mouse position to the specified coords.

    Arguments:
    - self: The main object pointer.
    - x: The x position.
    - y: the y position.
    """
    global isGnome

    if point is not None:
        x, y = point.x, point.y
        
    
    old_x, old_y = position()
    x_diff = abs(old_x - x) 
    y_diff = abs(old_y - y) 
    
    while True:
        old_x, old_y = position()
        
        if x_diff <= 0 and y_diff <= 0:
            break
        
        x_diff -= 1
        y_diff -= 1
        
        if x > old_x:
             new_x = x + 1
        else:
             new_x = x - 1
             
        if y > old_y:
             new_y = y + 1
        else:
             new_y = y - 1
             
        if isGnome:
            try:
                reg.generateMouseEvent( x, y, 'abs' )
            except:
                isGnome = False
        else:
            xtest.fake_input( xDisplay, X.MotionNotify, x = x, y = y)
            #display.sync()
            xDisplay.flush()
            
    return True
def press_key(code):
    fake_input(dp, X.KeyPress, code)
    dp.sync()
def release_key(code):
    fake_input(dp, X.KeyRelease, code)
    dp.sync()
def _mouseUp(x, y, button):
    _moveTo(x, y)
    assert button in BUTTON_NAME_MAPPING.keys(), "button argument not in ('left', 'middle', 'right', 4, 5, 6, 7)"
    button = BUTTON_NAME_MAPPING[button]
    fake_input(_display, X.ButtonRelease, button)
    _display.sync()
Exemple #34
0
 def click_up():
     """Simulates an up click"""
     fake_input(d, ButtonRelease, 1)
     d.sync()
Exemple #35
0
def send_key_event(code, event_type):
    display_loc = display.Display()
    bar = find_bar(display_loc)
    xtest.fake_input(bar, event_type, code)
    display_loc.sync()
Exemple #36
0
 def release(self, x, y, button=1):
     self.move(x, y)
     fake_input(self.display, X.ButtonRelease, [None, 1, 3, 2, 4,
                                                5][button])
     self.display.sync()
Exemple #37
0
 def __fakeKeydown(self, keyName):
     keyCode = self.__lookupKeyCode(keyName)
     xtest.fake_input(self.rootWindow, X.KeyPress, keyCode)
Exemple #38
0
 def __fakeKeyup(self, keyName):
     keyCode = self.__lookupKeyCode(keyName)
     xtest.fake_input(self.rootWindow, X.KeyRelease, keyCode)
Exemple #39
0
 def move(self, x, y):
     fake_input(self.display, X.MotionNotify, x=x, y=y)
     self.display.sync()
Exemple #40
0
 def keypress(self, keyval):
     fake_input(self.display, X.KeyPress, keyval)
     self.display.sync()
Exemple #41
0
 def keyrelease(self, keyval):
     fake_input(self.display, X.KeyRelease, keyval)
     self.display.sync()
Exemple #42
0
def send_key(window, keycode):
    '''Send a KeyPress and KeyRelease event'''
    if type(keycode) == tuple:
        # send with modifier
        xtest.fake_input(window, X.KeyPress, keycode[0])
        xtest.fake_input(window, X.KeyPress, keycode[1])
        xtest.fake_input(window, X.KeyRelease, keycode[1])
        xtest.fake_input(window, X.KeyRelease, keycode[0])
    else:
        # send without modifier
        xtest.fake_input(window, X.KeyPress, keycode)
        xtest.fake_input(window, X.KeyRelease, keycode)
Exemple #43
0
 def _key_up(self, keycode):
     fake_input(self.display, X.KeyRelease, keycode)
Exemple #44
0
def Move(x, y):
    fake_input(display, X.MotionNotify, x, y)
Exemple #45
0
 def sendKey(self):
     xtest.fake_input(self.root, X.KeyPress, self.key)
     xtest.fake_input(self.root, X.KeyRelease, self.key)
     self.disp.flush()
Exemple #46
0
 def mousemove(x, y):
     fake_input(disp, X.MotionNotify, x=x, y=y)
     disp.sync()
Exemple #47
0
	def goto_xy(browser,x, y):   
		'''move to position x y'''
		xtest.fake_input(browser.display, X.MotionNotify, x = x, y = y)
		browser.display.flush()
Exemple #48
0
def process_message(message):
    parsed_message = json.loads(message)
    event_type = parsed_message['type']
    data = parsed_message['data']
    logging.info('Got ' + event_type + ' event ({})'.format(data))
    if event_type == 'LEFT_CLICK':
        xtest.fake_input(display, X.ButtonPress, LEFT_CLICK_BUTTON)
        xtest.fake_input(display, X.ButtonRelease, LEFT_CLICK_BUTTON)
        display.sync()
    elif event_type == 'RIGHT_CLICK':
        xtest.fake_input(display, X.ButtonPress, RIGHT_CLICK_BUTTON)
        xtest.fake_input(display, X.ButtonRelease, RIGHT_CLICK_BUTTON)
        display.sync()
    elif event_type == 'MOVE':
        velocity_x = data['velocityX']
        velocity_y = data['velocityY']
        pointer = display.screen().root.query_pointer()
        geometry = display.screen().root.get_geometry()
        min_dimension = min(geometry.width, geometry.height)
        scale = 0.05
        new_x = pointer.root_x + int(velocity_x * min_dimension * scale)
        new_y = pointer.root_y + int(velocity_y * min_dimension * scale)
        xtest.fake_input(display, X.MotionNotify, x=new_x, y=new_y)
        display.sync()
    elif event_type == 'SCROLL':
        button = SCROLL_DIRECTION_TO_BUTTON[data['direction']]
        xtest.fake_input(display, X.ButtonPress, button)
        xtest.fake_input(display, X.ButtonRelease, button)
        display.sync()
    elif event_type == 'KEYBOARD':
        # TODO: Document this.
        key_str = data['key']
        modifier = 0
        SPECIAL_CHARS_MAP = {
            'Enter': 'Return',
            'Backspace': 'BackSpace',
            'Escape': 'Escape',
            'Tab': 'Tab',
            'Up': 'Up',
            'Down': 'Down',
            'Left': 'Left',
            'Right': 'Right',
            'Insert': 'Insert',
            'PrintScreen': 'Print',
            'Delete': 'Delete',
            'PageUp': 'Page_Up',
            'PageDown': 'Page_Down',
            'Home': 'Home',
            'End': 'End',
            'F1': 'F1',
            'F2': 'F2',
            'F3': 'F3',
            'F4': 'F4',
            'F5': 'F5',
            'F6': 'F6',
            'F7': 'F7',
            'F8': 'F8',
            'F9': 'F9',
            'F10': 'F10',
            'F11': 'F11',
            'F12': 'F12',
        }
        if key_str in SPECIAL_CHARS_MAP:
            key, modifier = display.keysym_to_keycode(
                    Xlib.XK.string_to_keysym(SPECIAL_CHARS_MAP[key_str])), 0
        else:
            # key = display.keysym_to_keycode(Xlib.XK.string_to_keysym(key_str))
            keycodes = list(display.keysym_to_keycodes(ord(key_str)))
            if keycodes == []:
                logging.warn('Can not convert `' + key_str + '` to keycode')
                return
            key, modifier = keycodes[0]
        if modifier != 0 and modifier != 1:
            logging.warn('Unknown modifier', modifier)
            return
        modifiers = [
                (modifier, Xlib.XK.XK_Shift_L),
                (data['ctrl'], Xlib.XK.XK_Control_L),
                (data['alt'], Xlib.XK.XK_Alt_L),
                (data['altGr'], Xlib.XK.XK_Alt_R),
                (data['super'], Xlib.XK.XK_Super_L),
        ];
        # TODO: alt + tab does not seem to work as expected
        for flag, keysym in modifiers:
            if flag:
                keycode = display.keysym_to_keycode(keysym)
                xtest.fake_input(display, X.KeyPress, keycode)
        xtest.fake_input(display, X.KeyPress, key)
        xtest.fake_input(display, X.KeyRelease, key)
        for flag, keysym in reversed(modifiers):
            if flag:
                keycode = display.keysym_to_keycode(keysym)
                xtest.fake_input(display, X.KeyRelease, keycode)
        display.sync()
    else:
        raise Exception("Unknown event type")
Exemple #49
0
 def click_down():
     """Simulates a down click"""
     fake_input(d, ButtonPress, 1)
     d.sync()
 def emulateSpecialKey(d, skey, delay):
     '''
         Emulates Press and Release of Special Keys with a certain delay.
     '''
     print skey
     #        assert(skey in kmap)
     if skey in u'\|@#~½¬{[]}\[}{~─|':
         xtest.fake_input(d, X.KeyPress, kmap[u'alt_l'])
         xtest.fake_input(d, X.KeyPress, kmap[skey])
         d.flush()
         time.sleep(delay)
         xtest.fake_input(d, X.KeyRelease, kmap[skey])
         xtest.fake_input(d, X.KeyRelease, kmap[u'alt_l'])
         d.flush()
     elif skey in u'!"·$%&/()=?¿ª:;>':
         xtest.fake_input(d, X.KeyPress, kmap[u'shift_l'])
         xtest.fake_input(d, X.KeyPress, kmap[skey])
         d.flush()
         time.sleep(delay)
         xtest.fake_input(d, X.KeyRelease, kmap[skey])
         xtest.fake_input(d, X.KeyRelease, kmap[u'shift_l'])
         d.flush()
     else:
         xtest.fake_input(d, X.KeyPress, kmap[skey])
         d.flush()
         time.sleep(delay)
         xtest.fake_input(d, X.KeyRelease, kmap[skey])
         d.flush()
def _moveTo(x, y):
    fake_input(_display, X.MotionNotify, x=x, y=y)
    _display.sync()
Exemple #52
0
def press(keysym):
    # simulates the press (key down then release) of a button; NOTE: found from pyautogui's source code
    fake_input(display, X.KeyPress, keysym)
    fake_input(display, X.KeyRelease, keysym)
    display.sync()
Exemple #53
0
 def click(self, button):
     xtest.fake_input(self.disp, X.ButtonPress, button)
     xtest.fake_input(self.disp, X.ButtonRelease, button)
     self.disp.flush()
def press(button):
    fake_input(d, X.ButtonPress, [None, 1, 3, 2, 4, 5][button])
def release(button):
    fake_input(d, X.ButtonRelease, [None, 1, 3, 2, 4, 5][button])
Exemple #56
0
    def send_key_combination(self, combo_string):
        """Emulate a sequence of key combinations.

        KeyboardCapture instance would normally detect the emulated
        key events. In order to prevent this, all KeyboardCapture
        instances are told to ignore the emulated key events.

        Argument:

        combo_string -- A string representing a sequence of key
        combinations. Keys are represented by their names in the
        Xlib.XK module, without the 'XK_' prefix. For example, the
        left Alt key is represented by 'Alt_L'. Keys are either
        separated by a space or a left or right parenthesis.
        Parentheses must be properly formed in pairs and may be
        nested. A key immediately followed by a parenthetical
        indicates that the key is pressed down while all keys enclosed
        in the parenthetical are pressed and released in turn. For
        example, Alt_L(Tab) means to hold the left Alt key down, press
        and release the Tab key, and then release the left Alt key.

        """
        # Convert the argument into a sequence of keycode, event type pairs
        # that, if executed in order, would emulate the key
        # combination represented by the argument.
        keycode_events = []
        key_down_stack = []
        current_command = []
        for c in combo_string:            
            if c in (' ', '(', ')'):
                keystring = ''.join(current_command)
                keysym = XK.string_to_keysym(keystring)
                keycode, mods = self._keysym_to_keycode_and_modifiers(keysym)
                current_command = []
                if keycode is None:
                    continue
                if c == ' ':
                    # Record press and release for command's key.
                    keycode_events.append((keycode, X.KeyPress))
                    keycode_events.append((keycode, X.KeyRelease))
                elif c == '(':
                    # Record press for command's key.
                    key_down_stack.append(keycode)
                    keycode_events.append((keycode, X.KeyPress))
                elif c == ')':
                    # Record press and release for command's key and
                    # release previously held key.
                    keycode_events.append((keycode, X.KeyPress))
                    keycode_events.append((keycode, X.KeyRelease))
                    if len(key_down_stack):
                        keycode = key_down_stack.pop()
                        keycode_events.append((keycode, X.KeyRelease))
            else:
                current_command.append(c)                
        # Record final command key.
        keystring = ''.join(current_command)
        keysym = XK.string_to_keysym(keystring)
        keycode, mods = self._keysym_to_keycode_and_modifiers(keysym)
        if keycode is not None:
            keycode_events.append((keycode, X.KeyPress))
            keycode_events.append((keycode, X.KeyRelease))
        # Release all keys.
        for keycode in key_down_stack:
            keycode_events.append((keycode, X.KeyRelease))

        # Tell all KeyboardCapture instances to ignore the key
        # events that are about to be sent.
        for capture in keyboard_capture_instances:
            capture.ignore_key_events(keycode_events)

        # Emulate the key combination by sending key events.
        for keycode, event_type in keycode_events:
            xtest.fake_input(self.display, event_type, keycode)
        self.display.sync()
Exemple #57
0
 def press(self, button=1):
     """Press mouse button at current mouse location."""
     _logger.debug("Pressing mouse button %d", button)
     _PRESSED_MOUSE_BUTTONS.append(button)
     fake_input(get_display(), X.ButtonPress, button)
     get_display().sync()
Exemple #58
0
 def press(self, x, y, button=1):
     self.move(x, y)
     fake_input(self.display, X.ButtonPress, [None, 1, 3, 2, 4, 5][button])
     self.display.sync()
Exemple #59
0
def goto_xy(x, y) :
xtest.fake_input(ds, X.MotionNotify, x = x, y = y) #注意x,y参数的写法
ds.flush()
Exemple #60
0
 def _key_down(self, keycode):
     fake_input(self.display, X.KeyPress, keycode)