예제 #1
0
    def mouse_event(x, y, button, eventType):
        """
        > Description
            Generates a mouse press or release event on a specific pixel on the screen

        > Parameters
            x (int): the x coordinate where the event will be generated
            y (int): the y coordinate where the event will be generated
            button (str): A string indicating which mouse button to press/release. One of 'left', 'right' or 'middle'
            eventType (str): A string indicating the event type. One of 'press' or 'release'

        > Returns
            None

        > Example
            # this example could demonstrate a drag and drop of a file

            # press the left mouse button at 100, 100
            Macro.mouse_event(100, 100, 'left', 'press')
            # move the cursor to 400, 400
            Macro.move_cursor_to(400, 400)
            # then, release the mouse
            Macro.mouse_event(400, 400, 'left', 'press')
        """
        buttonToNo = {'left': 1, 'right': 2, 'middle': 3}
        controller.generateMouseEvent(
            x, y, 'b' + str(buttonToNo[button]) +
            ('p' if eventType == 'press' else 'r'))
예제 #2
0
    def key_down(key):
        """
        > Description
            Hold a specific key down, useful when you want to do key combinations, like Alt + Shift to change the current keyboard layout

        > Parameters
            key (string): The key to hold down

        > Returns
            None

        > Example
            # send Alt + F4 to the current application
            Macro.key_down('Alt')
            Macro.key_down('F4')

            time.sleep(0.2)

            Macro.key_up('Alt')
            Macro.key_up('F4')
        """
        # TODO check for special keys
        if key in Macro.KEY_LIST:
            controller.generateKeyboardEvent(Macro.KEY_LIST[key], None,
                                             KEY_PRESS)
예제 #3
0
파일: rawinput.py 프로젝트: Lorquas/dogtail
def relativeMotion(x, y, mouseDelay=None):
    logger.log("Mouse relative motion of (%s,%s)" % (x, y))
    registry.generateMouseEvent(x, y, 'rel')
    if mouseDelay:
        doDelay(mouseDelay)
    else:
        doDelay()
예제 #4
0
    def test_image_video_mix(self):
        files = [
            "tears of steel.webm",
            "flat_colour2_640x480.png",
            "flat_colour4_1600x1200.jpg",
            "flat_colour1_640x480.png",
            "flat_colour3_320x180.png",
            "flat_colour5_1600x1200.jpg",
        ]
        samples = self.import_media_multiple(files)
        timecode_widget = self.viewer.child(name="timecode_entry").child(roleName="text")
        tpos = self.timeline.position

        # One video, one image
        for sample in samples[1:]:
            self.insert_clip(sample)
            self.insert_clip(samples[0])

        sleep(0.3)
        end = self.search_clip_end(30, timecode_widget, self.timeline)
        cend = end / 11.139
        dogtail.rawinput.absoluteMotion(tpos[0] + cend - 2, tpos[1] + 30)
        registry.generateKeyboardEvent(dogtail.rawinput.keyNameToKeyCode("Shift_L"), None, KEY_PRESS)
        dogtail.rawinput.press(tpos[0] + cend - 2, tpos[1] + 30)
        sleep(0.5)
        dogtail.rawinput.absoluteMotion(tpos[0] + cend - 40, tpos[1] + 30)
        sleep(0.5)
        dogtail.rawinput.release(tpos[0] + cend - 40, tpos[1] + 30)
        registry.generateKeyboardEvent(dogtail.rawinput.keyNameToKeyCode("Shift_L"), None, KEY_RELEASE)
        self.goToEnd_button.click()
        self.assertNotEqual(timecode_widget.text, "0:00:11.139")
예제 #5
0
def absoluteMotionWithTrajectory(source_x, source_y, dest_x, dest_y, mouseDelay=None, check=True):
    """
    Synthetize mouse absolute motion with trajectory. The 'trajectory' means that the whole motion
    is divided into several atomic movements which are synthetized separately.
    """
    if check:
        checkCoordinates(source_x, source_y)
        checkCoordinates(dest_x, dest_y)
    logger.log("Mouse absolute motion with trajectory to (%s,%s)" % (dest_x, dest_y))

    dx = float(dest_x - source_x)
    dy = float(dest_y - source_y)
    max_len = max(abs(dx), abs(dy))
    if max_len == 0:
        # actually, no motion requested
        return
    dx /= max_len
    dy /= max_len
    act_x = float(source_x)
    act_y = float(source_y)

    for _ in range(0, int(max_len)):
        act_x += dx
        act_y += dy
        if mouseDelay:
            doDelay(mouseDelay)
        registry.generateMouseEvent(int(act_x), int(act_y), name='abs')

    if mouseDelay:
        doDelay(mouseDelay)
    else:
        doDelay()
예제 #6
0
    def test_image_video_mix(self):
        files = [
            "tears of steel.webm", "flat_colour2_640x480.png",
            "flat_colour4_1600x1200.jpg", "flat_colour1_640x480.png",
            "flat_colour3_320x180.png", "flat_colour5_1600x1200.jpg"
        ]
        samples = self.import_media_multiple(files)
        timecode_widget = self.viewer.child(name="timecode_entry").child(
            roleName="text")
        tpos = self.timeline.position

        #One video, one image
        for sample in samples[1:]:
            self.insert_clip(sample)
            self.insert_clip(samples[0])

        sleep(0.3)
        end = self.search_clip_end(30, timecode_widget, self.timeline)
        cend = end / 11.139
        dogtail.rawinput.absoluteMotion(tpos[0] + cend - 2, tpos[1] + 30)
        registry.generateKeyboardEvent(
            dogtail.rawinput.keyNameToKeyCode("Shift_L"), None, KEY_PRESS)
        dogtail.rawinput.press(tpos[0] + cend - 2, tpos[1] + 30)
        sleep(0.5)
        dogtail.rawinput.absoluteMotion(tpos[0] + cend - 40, tpos[1] + 30)
        sleep(0.5)
        dogtail.rawinput.release(tpos[0] + cend - 40, tpos[1] + 30)
        registry.generateKeyboardEvent(
            dogtail.rawinput.keyNameToKeyCode("Shift_L"), None, KEY_RELEASE)
        self.goToEnd_button.click()
        self.assertNotEqual(timecode_widget.text, "0:00:11.139")
예제 #7
0
    def mouse_event(x, y, button, eventType):
        """
        > Description
            Generates a mouse press or release event on a specific pixel on the screen

        > Parameters
            x (int): the x coordinate where the event will be generated
            y (int): the y coordinate where the event will be generated
            button (str): A string indicating which mouse button to press/release. One of 'left', 'right' or 'middle'
            eventType (str): A string indicating the event type. One of 'press' or 'release'

        > Returns
            None

        > Example
            # this example could demonstrate a drag and drop of a file

            # press the left mouse button at 100, 100
            Macro.mouse_event(100, 100, 'left', 'press')
            # move the cursor to 400, 400
            Macro.move_cursor_to(400, 400)
            # then, release the mouse
            Macro.mouse_event(400, 400, 'left', 'press')
        """
        buttonToNo = {'left':1, 'right':2, 'middle':3 }
        controller.generateMouseEvent(x, y, 'b' + str(buttonToNo[button]) + ('p' if eventType == 'press' else 'r'))
예제 #8
0
    def test_image_video_mix(self):
        files = ["1sec_simpsons_trailer.mp4", "flat_colour2_640x480.png",
                 "flat_colour4_1600x1200.jpg", "flat_colour1_640x480.png",
                 "flat_colour3_320x180.png", "flat_colour5_1600x1200.jpg"]
        samples = self.import_media_multiple(files)
        seektime = self.search_by_text("0:00:00.000", self.pitivi, roleName="text")
        timeline = self.get_timeline()
        tpos = timeline.position

        #One video, one image
        for sample in samples[1:]:
            self.insert_clip(sample)
            self.insert_clip(samples[0])

        end = self.search_clip_end(30, seektime, timeline)
        cend = end / 11.139
        dogtail.rawinput.absoluteMotion(tpos[0] + cend - 2, tpos[1] + 30)
        registry.generateKeyboardEvent(dogtail.rawinput.keyNameToKeyCode("Shift_L"), None, KEY_PRESS)
        dogtail.rawinput.press(tpos[0] + cend - 2, tpos[1] + 30)
        sleep(0.5)
        dogtail.rawinput.absoluteMotion(tpos[0] + cend - 40, tpos[1] + 30)
        sleep(0.5)
        dogtail.rawinput.release(tpos[0] + cend - 40, tpos[1] + 30)
        registry.generateKeyboardEvent(dogtail.rawinput.keyNameToKeyCode("Shift_L"), None, KEY_RELEASE)
        self.nextb.click()
        self.assertNotEqual(seektime.text, "0:00:11.139")
예제 #9
0
    def import_media_multiple(self, files):
        dogtail.rawinput.pressKey("Esc")  # Ensure the welcome dialog is closed
        self.import_button.click()

        import_dialog = self.pitivi.child(name="Select One or More Files",
                                          roleName="file chooser",
                                          recursive=False)

        path_toggle = import_dialog.child(name="Type a file name",
                                          roleName="toggle button")
        if not path_toggle.checked:
            path_toggle.click()

        dir_path = os.path.realpath(__file__).split(
            "dogtail_scripts/")[0] + "samples/"
        import_dialog.child(roleName='text').text = dir_path
        time.sleep(0.2)
        dogtail.rawinput.pressKey("Enter")

        # We are now in the samples directory, select various items.
        # We use Ctrl click to select multiple items. However, since the first
        # row of the filechooser is always selected by default, we must not use
        # ctrl when selecting the first item of our list, in order to deselect.
        ctrl_code = dogtail.rawinput.keyNameToKeyCode("Control_L")
        file_list = import_dialog.child(name="Files", roleName="table")
        first = True
        for f in files:
            time.sleep(0.5)
            file_list.child(name=f).click()
            if first:
                registry.generateKeyboardEvent(ctrl_code, None, KEY_PRESS)
                first = False
        registry.generateKeyboardEvent(ctrl_code, None, KEY_RELEASE)
        import_dialog.button('Add').click()

        current_search_text = self.medialibrary.child(
            name="media_search_entry", roleName="text").text.lower()
        if current_search_text != "":
            # Failure to find some icons might be because of search filtering.
            # The following avoids searching for files that can't be found.
            for f in files:
                if current_search_text not in f.lower():
                    files.remove(f)
        # Check if non-filtered items are now visible in the media library.
        samples = []
        for i in range(5):
            # The time it takes for icons to appear is unpredictable,
            # therefore we try up to 5 times to look for them
            icons = self.medialibrary.findChildren(
                GenericPredicate(roleName="icon"))
            for icon in icons:
                for f in files:
                    if icon.text == f:
                        samples.append(icon)
                        files.remove(f)
            if len(files) == 0:
                break
            time.sleep(0.5)
        return samples
예제 #10
0
파일: common.py 프로젝트: Jactry/pitivi
    def import_media_multiple(self, files):
        dogtail.rawinput.pressKey("Esc")  # Ensure the welcome dialog is closed
        self.import_button.click()

        import_dialog = self.pitivi.child(name="Select One or More Files",
                                          roleName="file chooser", recursive=False)

        path_toggle = import_dialog.child(
            name="Type a file name", roleName="toggle button")
        if not path_toggle.checked:
            path_toggle.click()

        dir_path = os.path.realpath(__file__).split(
            "dogtail_scripts/")[0] + "samples/"
        import_dialog.child(roleName='text').text = dir_path
        time.sleep(0.2)
        dogtail.rawinput.pressKey("Enter")

        # We are now in the samples directory, select various items.
        # We use Ctrl click to select multiple items. However, since the first
        # row of the filechooser is always selected by default, we must not use
        # ctrl when selecting the first item of our list, in order to deselect.
        ctrl_code = dogtail.rawinput.keyNameToKeyCode("Control_L")
        file_list = import_dialog.child(name="Files", roleName="table")
        first = True
        for f in files:
            time.sleep(0.5)
            file_list.child(name=f).click()
            if first:
                registry.generateKeyboardEvent(ctrl_code, None, KEY_PRESS)
                first = False
        registry.generateKeyboardEvent(ctrl_code, None, KEY_RELEASE)
        import_dialog.button('Add').click()

        current_search_text = self.medialibrary.child(
            name="media_search_entry", roleName="text").text.lower()
        if current_search_text != "":
            # Failure to find some icons might be because of search filtering.
            # The following avoids searching for files that can't be found.
            for f in files:
                if current_search_text not in f.lower():
                    files.remove(f)
        # Check if non-filtered items are now visible in the media library.
        samples = []
        for i in range(5):
            # The time it takes for icons to appear is unpredictable,
            # therefore we try up to 5 times to look for them
            icons = self.medialibrary.findChildren(
                GenericPredicate(roleName="icon"))
            for icon in icons:
                for f in files:
                    if icon.text == f:
                        samples.append(icon)
                        files.remove(f)
            if len(files) == 0:
                break
            time.sleep(0.5)
        return samples
예제 #11
0
def click(x, y, button=1, check=True):
    """
    Synthesize a mouse button click at (x,y)
    """
    if check:
        checkCoordinates(x, y)
    logger.log("Mouse button %s click at (%s,%s)" % (button, x, y))
    registry.generateMouseEvent(x, y, name='b%sc' % button)
    doDelay(config.actionDelay)
예제 #12
0
def press(x, y, button=1, check=True):
    """
    Synthesize a mouse button press at (x,y)
    """
    if check:
        checkCoordinates(x, y)
    logger.log("Mouse button %s press at (%s,%s)" % (button, x, y))
    registry.generateMouseEvent(x, y, name='b%sp' % button)
    doDelay()
예제 #13
0
def release(x, y, button=1, check=True):
    """
    Synthesize a mouse button release at (x,y)
    """
    if check:
        checkCoordinates(x, y)
    logger.log("Mouse button %s release at (%s,%s)" % (button, x, y))
    registry.generateMouseEvent(x, y, name='b%sr' % button)
    doDelay()
예제 #14
0
파일: rawinput.py 프로젝트: Lorquas/dogtail
def click(x, y, button=1, check=True):
    """
    Synthesize a mouse button click at (x,y)
    """
    if check:
        checkCoordinates(x, y)
    logger.log("Mouse button %s click at (%s,%s)" % (button, x, y))
    registry.generateMouseEvent(x, y, 'b%sc' % button)
    doDelay(config.actionDelay)
예제 #15
0
파일: rawinput.py 프로젝트: Lorquas/dogtail
def release(x, y, button=1, check=True):
    """
    Synthesize a mouse button release at (x,y)
    """
    if check:
        checkCoordinates(x, y)
    logger.log("Mouse button %s release at (%s,%s)" % (button, x, y))
    registry.generateMouseEvent(x, y, 'b%sr' % button)
    doDelay()
예제 #16
0
def doubleClick(x, y, button=1, check=True):
    """
    Synthesize a mouse button double-click at (x,y)
    """
    if check:
        checkCoordinates(x, y)
    logger.log("Mouse button %s doubleclick at (%s,%s)" % (button, x, y))
    registry.generateMouseEvent(x, y, name='b%sd' % button)
    doDelay()
예제 #17
0
파일: rawinput.py 프로젝트: Lorquas/dogtail
def doubleClick(x, y, button=1, check=True):
    """
    Synthesize a mouse button double-click at (x,y)
    """
    if check:
        checkCoordinates(x, y)
    logger.log("Mouse button %s doubleclick at (%s,%s)" % (button, x, y))
    registry.generateMouseEvent(x, y, 'b%sd' % button)
    doDelay()
예제 #18
0
파일: rawinput.py 프로젝트: Lorquas/dogtail
def pressKey(keyName):
    """
    Presses (and releases) the key specified by keyName.
    keyName is the English name of the key as seen on the keyboard. Ex: 'enter'
    Names are looked up in Gdk.KEY_ If they are not found there, they are
    looked up by uniCharToKeySym().
    """
    keySym = keyNameToKeySym(keyName)
    registry.generateKeyboardEvent(keySym, None, KEY_SYM)
    doTypingDelay()
예제 #19
0
def pressKey(keyName):
    """
    Presses (and releases) the key specified by keyName.
    keyName is the English name of the key as seen on the keyboard. Ex: 'enter'
    Names are looked up in Gdk.KEY_ If they are not found there, they are
    looked up by uniCharToKeySym().
    """
    keySym = keyNameToKeySym(keyName)
    registry.generateKeyboardEvent(keySym, None, KEY_SYM)
    doTypingDelay()
예제 #20
0
def relativeMotion(x, y, mouseDelay=None):
    """
    Synthetize a relative motion from actual position.
    Note: Does not check if the end coordinates are positive.
    """
    logger.log("Mouse relative motion of (%s,%s)" % (x, y))
    registry.generateMouseEvent(x, y, name='rel')
    if mouseDelay:
        doDelay(mouseDelay)
    else:
        doDelay()
예제 #21
0
def relativeMotion(x, y, mouseDelay=None):
    """
    Synthetize a relative motion from actual position.
    Note: Does not check if the end coordinates are positive.
    """
    logger.log("Mouse relative motion of (%s,%s)" % (x, y))
    registry.generateMouseEvent(x, y, name='rel')
    if mouseDelay:
        doDelay(mouseDelay)
    else:
        doDelay()
예제 #22
0
def absoluteMotion(x, y, mouseDelay=None, check=True):
    """
    Synthesize mouse absolute motion to (x,y)
    """
    if check:
        checkCoordinates(x, y)
    logger.log("Mouse absolute motion to (%s,%s)" % (x, y))
    registry.generateMouseEvent(x, y, name='abs')
    if mouseDelay:
        doDelay(mouseDelay)
    else:
        doDelay()
예제 #23
0
 def ripple_roll(self, from_percent, to_percent):
     dogtail.rawinput.click(self.getTimelineX(from_percent), self.getTimelineY(0))
     sleep(0.1)
     registry.generateKeyboardEvent(dogtail.rawinput.keyNameToKeyCode("Shift_L"), None, KEY_PRESS)
     try:
         dogtail.rawinput.press(self.getTimelineX(from_percent), self.getTimelineY(0))
         dogtail.rawinput.absoluteMotion(self.getTimelineX(to_percent), self.getTimelineY(0))
         sleep(0.1)
         dogtail.rawinput.release(self.getTimelineX(to_percent), self.getTimelineY(0))
     finally:
         registry.generateKeyboardEvent(dogtail.rawinput.keyNameToKeyCode("Shift_L"), None, KEY_RELEASE)
     sleep(0.1)
예제 #24
0
파일: rawinput.py 프로젝트: Lorquas/dogtail
def absoluteMotion(x, y, mouseDelay=None, check=True):
    """
    Synthesize mouse absolute motion to (x,y)
    """
    if check:
        checkCoordinates(x, y)
    logger.log("Mouse absolute motion to (%s,%s)" % (x, y))
    registry.generateMouseEvent(x, y, 'abs')
    if mouseDelay:
        doDelay(mouseDelay)
    else:
        doDelay()
예제 #25
0
 def scroll_and_click(elf,
                      context,
                      value,
                      double=False,
                      enter=False,
                      hold_control=False):
     (base, scrollbar, nbparents) = context
     base.grab_focus()
     y = 0
     ok = False
     print("Click on '%s'" % value)
     x = base.child(value, retry=False)
     disapeared = False
     if x is None:
         raise ValueError(value + ' not found')
     for i in range(nbparents):
         x = x.parent
     while y < 6000 and not ok:
         print("· Scroll to %d" % y)
         scrollbar.value = y
         y += 50
         ok = True
         time.sleep(0.5)
         try:
             if hold_control:
                 registry.generateKeyboardEvent(control_code, None,
                                                KEY_PRESS)
                 time.sleep(0.2)
             if double:
                 x.doubleClick()
             else:
                 x.click()
                 if enter:
                     time.sleep(0.2)
                     dogtail.rawinput.pressKey('\n')
             if hold_control:
                 time.sleep(0.2)
                 registry.generateKeyboardEvent(control_code, None,
                                                KEY_RELEASE)
             disapeared = len(
                 base.findChildren(
                     dogtail.predicate.GenericPredicate(value))) == 0
         except:
             ok = False
         if not (disapeared or x.selected):
             ok = False
     if ok:
         print("Success!")
         time.sleep(0.5)
     else:
         raise ValueError(value + ' could not be clicked')
예제 #26
0
 def key_down(self, key):
     """
     This is a more specific function than keyboard(). It can send specific
     key-pressed events, in case you want to do keyboard combinations, like Alt+F4
     The argument can only be a string. If you want to send (e.g.) Alt+F4 then you
     should call it as:
     key_down("Alt")
     key_down("F4")
     time.sleep(0.2)
     key_up("Alt")
     key_up("F4")
     """
     if key in key_list:
         controller.generateKeyboardEvent(key_codes[key_list.index(key)], None, KEY_PRESS)
예제 #27
0
    def reclaimScripts(self):
        """Compares the list of known scripts to the list of known apps,
        deleting any scripts as necessary.
        """

        from pyatspi import Registry

        try:
            desktop = Registry.getDesktop(0)
        except:
            debug.printException(debug.LEVEL_FINEST)
            return

        appList = self.appScripts.keys()
        appList = filter(lambda a: a!= None and a not in desktop, appList)
        for app in appList:
            appScript = self.appScripts.pop(app)
            _eventManager.deregisterScriptListeners(appScript)
            del appScript

            try:
                toolkitScripts = self.toolkitScripts.pop(app)
            except KeyError:
                pass
            else:
                for toolkitScript in toolkitScripts.values():
                    _eventManager.deregisterScriptListeners(toolkitScript)
                    del toolkitScript

            del app
예제 #28
0
    def reclaimScripts(self):
        """Compares the list of known scripts to the list of known apps,
        deleting any scripts as necessary.
        """

        from pyatspi import Registry

        try:
            desktop = Registry.getDesktop(0)
        except:
            debug.printException(debug.LEVEL_FINEST)
            return

        appList = list(self.appScripts.keys())
        appList = [a for a in appList if a != None and a not in desktop]
        for app in appList:
            appScript = self.appScripts.pop(app)
            del appScript

            try:
                toolkitScripts = self.toolkitScripts.pop(app)
            except KeyError:
                pass
            else:
                for toolkitScript in list(toolkitScripts.values()):
                    del toolkitScript

            del app
예제 #29
0
    def reclaimScripts(self):
        """Compares the list of known scripts to the list of known apps,
        deleting any scripts as necessary.
        """

        from pyatspi import Registry

        try:
            desktop = Registry.getDesktop(0)
        except:
            debug.printException(debug.LEVEL_FINEST)
            return

        appList = list(self.appScripts.keys())
        appList = [a for a in appList if a != None and a not in desktop]
        for app in appList:
            appScript = self.appScripts.pop(app)
            del appScript

            try:
                toolkitScripts = self.toolkitScripts.pop(app)
            except KeyError:
                pass
            else:
                for toolkitScript in list(toolkitScripts.values()):
                    del toolkitScript

            del app
예제 #30
0
    def move_cursor_to(x, y):
        """
        > Description
            Moves the cursor to the x, y coordinates

        > Parameters
            x (int): the x coordinate to move the cursor to
            y (int): the y coordinate to move the cursor to

        > Returns
            None

        > Example
            # move the cursor to 100, 100
            Macro.move_cursor_to(100, 100)
        """
        controller.generateMouseEvent(x, y, MOUSE_ABS)
예제 #31
0
    def keyboard(key):
        """
        > Description
            Type some text or special keys, like Backspaces, Returns etc

            For all the available keys look into `Macro.KEY_LIST`

        > Parameters
            key (string/list): If the `key` is a string, then it is simpy typed out. If it is a list of strings, every string in the list will be typed out. If a string in the list starts with `@@` then it is recognized as a special key and it is not typed out as is

        > Returns
            None

        > Example
            sentence = 'alex is awesome'

            # types out 'alex is awesome'
            Macro.keyboard(sentence)

            # types out '@@BackSpace'
            Macro.keyboard('@@BackSpace')

            # sends a backspace (deletes a character)
            Macro.keyboard(['@@BackSpace'])

            # types out 'alex is awesome' and then proceeds to go to the next line
            Macro.keyboard([sentence, '@@Return'])
        """
        if type(key) is str:
            for i in key:
                Macro.__generate(i)
        elif type(key) in [tuple, list]:
            for inner_str in key:
                if inner_str.startswith('@@'):
                    inner_str = inner_str[2:]
                    if inner_str in Macro.KEY_LIST:
                        controller.generateKeyboardEvent(
                            Macro.KEY_LIST[inner_str], None, KEY_PRESS)
                        time.sleep(0.01)
                        controller.generateKeyboardEvent(
                            Macro.KEY_LIST[inner_str], None, KEY_RELEASE)
                    else:
                        print 'Annotated key \'' + inner_str + '\' does not exist in my key list'
                else:
                    for i in inner_str:
                        Macro.__generate(i)
예제 #32
0
    def move_cursor_to(x, y):
        """
        > Description
            Moves the cursor to the x, y coordinates

        > Parameters
            x (int): the x coordinate to move the cursor to
            y (int): the y coordinate to move the cursor to

        > Returns
            None

        > Example
            # move the cursor to 100, 100
            Macro.move_cursor_to(100, 100)
        """
        controller.generateMouseEvent(x, y, MOUSE_ABS)
예제 #33
0
    def middle_click_to(x, y):
        """
        > Description
            Middle clicks the mouse at x, y

        > Parameters
            x (int): the x coordinate to middle click to
            y (int): the y coordinate to middle click to

        > Returns
            None

        > Example
            # middle click to 100, 100
            Macro.middle_click_to(100, 100)
        """
        if(x >= 0 and y >= 0):
            controller.generateMouseEvent(x, y, 'b2c')
예제 #34
0
    def right_click_to(x, y):
        """
        > Description
            Right clicks the mouse at x, y

        > Parameters
            x (int): the x coordinate to right click to
            y (int): the y coordinate to right click to

        > Returns
            None

        > Example
            # right click to 100, 100
            Macro.right_click_to(100, 100)
        """
        if(x >= 0 and y >= 0):
            controller.generateMouseEvent(x, y, 'b3c')
예제 #35
0
    def middle_click_to(x, y):
        """
        > Description
            Middle clicks the mouse at x, y

        > Parameters
            x (int): the x coordinate to middle click to
            y (int): the y coordinate to middle click to

        > Returns
            None

        > Example
            # middle click to 100, 100
            Macro.middle_click_to(100, 100)
        """
        if (x >= 0 and y >= 0):
            controller.generateMouseEvent(x, y, 'b2c')
예제 #36
0
    def right_click_to(x, y):
        """
        > Description
            Right clicks the mouse at x, y

        > Parameters
            x (int): the x coordinate to right click to
            y (int): the y coordinate to right click to

        > Returns
            None

        > Example
            # right click to 100, 100
            Macro.right_click_to(100, 100)
        """
        if (x >= 0 and y >= 0):
            controller.generateMouseEvent(x, y, 'b3c')
예제 #37
0
    def keyboard(key):
        """
        > Description
            Type some text or special keys, like Backspaces, Returns etc

            For all the available keys look into `Macro.KEY_LIST`

        > Parameters
            key (string/list): If the `key` is a string, then it is simpy typed out. If it is a list of strings, every string in the list will be typed out. If a string in the list starts with `@@` then it is recognized as a special key and it is not typed out as is

        > Returns
            None

        > Example
            sentence = 'alex is awesome'

            # types out 'alex is awesome'
            Macro.keyboard(sentence)

            # types out '@@BackSpace'
            Macro.keyboard('@@BackSpace')

            # sends a backspace (deletes a character)
            Macro.keyboard(['@@BackSpace'])

            # types out 'alex is awesome' and then proceeds to go to the next line
            Macro.keyboard([sentence, '@@Return'])
        """
        if type(key) is str:
            for i in key:
               Macro. __generate(i)
        elif type(key) in [tuple, list]:
            for inner_str in key:
                if inner_str.startswith('@@'):
                    inner_str = inner_str[2:]
                    if inner_str in Macro.KEY_LIST:
                        controller.generateKeyboardEvent(Macro.KEY_LIST[inner_str], None, KEY_PRESS)
                        time.sleep(0.01)
                        controller.generateKeyboardEvent(Macro.KEY_LIST[inner_str], None, KEY_RELEASE)
                    else:
                        print 'Annotated key \'' + inner_str + '\' does not exist in my key list'
                else:
                    for i in inner_str:
                       Macro. __generate(i)
예제 #38
0
 def ripple_roll(self, from_percent, to_percent):
     dogtail.rawinput.click(self.getTimelineX(from_percent),
                            self.getTimelineY(0))
     sleep(0.1)
     registry.generateKeyboardEvent(
         dogtail.rawinput.keyNameToKeyCode("Shift_L"), None, KEY_PRESS)
     try:
         dogtail.rawinput.press(self.getTimelineX(from_percent),
                                self.getTimelineY(0))
         dogtail.rawinput.absoluteMotion(self.getTimelineX(to_percent),
                                         self.getTimelineY(0))
         sleep(0.1)
         dogtail.rawinput.release(self.getTimelineX(to_percent),
                                  self.getTimelineY(0))
     finally:
         registry.generateKeyboardEvent(
             dogtail.rawinput.keyNameToKeyCode("Shift_L"), None,
             KEY_RELEASE)
     sleep(0.1)
예제 #39
0
파일: rawinput.py 프로젝트: Lorquas/dogtail
def keyCombo(comboString):
    """
    Generates the appropriate keyboard events to simulate a user pressing the
    specified key combination.

    comboString is the representation of the key combo to be generated.
    e.g. '<Control><Alt>p' or '<Control><Shift>PageUp' or '<Control>q'
    """
    strings = []
    for s in comboString.split('<'):
        if s:
            for S in s.split('>'):
                if S:
                    S = keyNameAliases.get(S.lower(), S)
                    strings.append(S)
    for s in strings:
        if not hasattr(Gdk, s):
            if not hasattr(Gdk, 'KEY_' + s):
                raise ValueError("Cannot find key %s" % s)
    modifiers = strings[:-1]
    finalKey = strings[-1]
    for modifier in modifiers:

        code = keyNameToKeyCode(modifier)
        registry.generateKeyboardEvent(code, None, KEY_PRESS)
    code = keyNameToKeyCode(finalKey)
    registry.generateKeyboardEvent(code, None, KEY_PRESSRELEASE)
    for modifier in modifiers:
        code = keyNameToKeyCode(modifier)
        registry.generateKeyboardEvent(code, None, KEY_RELEASE)
    doDelay()
예제 #40
0
def keyCombo(comboString):
    """
    Generates the appropriate keyboard events to simulate a user pressing the
    specified key combination.

    comboString is the representation of the key combo to be generated.
    e.g. '<Control><Alt>p' or '<Control><Shift>PageUp' or '<Control>q'
    """
    strings = []
    for s in comboString.split('<'):
        if s:
            for S in s.split('>'):
                if S:
                    S = keyNameAliases.get(S.lower(), S)
                    strings.append(S)
    for s in strings:
        if not hasattr(Gdk, s):
            if not hasattr(Gdk, 'KEY_' + s):
                raise ValueError("Cannot find key %s" % s)
    modifiers = strings[:-1]
    finalKey = strings[-1]
    for modifier in modifiers:
        code = keyNameToKeyCode(modifier)
        registry.generateKeyboardEvent(code, None, KEY_PRESS)
    code = keyNameToKeyCode(finalKey)
    registry.generateKeyboardEvent(code, None, KEY_PRESSRELEASE)
    for modifier in modifiers:
        code = keyNameToKeyCode(modifier)
        registry.generateKeyboardEvent(code, None, KEY_RELEASE)
    doDelay()
예제 #41
0
    def test_ripple_roll(self):
        self.insertTwoClipsAndSeekToEnd()
        timecode_widget = self.viewer.child(name="timecode_entry").child(
            roleName="text")
        self.assertEqual(timecode_widget.text, DURATION_OF_TWO_CLIPS)
        tpos = self.timeline.position
        end = self.search_clip_end(30, timecode_widget, self.timeline)

        dogtail.rawinput.absoluteMotion(tpos[0] + end / 2 - 2, tpos[1] + 30)
        registry.generateKeyboardEvent(
            dogtail.rawinput.keyNameToKeyCode("Control_L"), None, KEY_PRESS)
        dogtail.rawinput.press(tpos[0] + end / 2 - 2, tpos[1] + 30)
        sleep(0.5)
        dogtail.rawinput.absoluteMotion(tpos[0] + end / 2 - 100, tpos[1] + 30)
        sleep(0.5)
        dogtail.rawinput.release(tpos[0] + end / 2 - 100, tpos[1] + 30)
        registry.generateKeyboardEvent(
            dogtail.rawinput.keyNameToKeyCode("Control_L"), None, KEY_RELEASE)
        self.goToEnd_button.click()
        self.assertNotEqual(timecode_widget.text, DURATION_OF_TWO_CLIPS,
                            "Not rippled, but trimmed")

        # Check if adding an effect causes a regression in behavior
        self.effectslibrary.click()
        self.clipproperties.click()
        center = lambda obj: (obj.position[0] + obj.size[0] / 2, obj.position[
            1] + obj.size[1] / 2)
        table = self.clipproperties.child(roleName="table")
        effect_from_library = self.search_by_text("Agingtv",
                                                  self.effectslibrary,
                                                  roleName="table cell",
                                                  exactMatchOnly=False)
        self.improved_drag(center(effect_from_library), center(table))
        self.goToEnd_button.click()
        seekbefore = timecode_widget.text
        # Try ripple and roll
        dogtail.rawinput.absoluteMotion(tpos[0] + end / 2 - 102, tpos[1] + 30)
        registry.generateKeyboardEvent(
            dogtail.rawinput.keyNameToKeyCode("Control_L"), None, KEY_PRESS)
        dogtail.rawinput.press(tpos[0] + end / 2 - 102, tpos[1] + 30)
        sleep(0.5)
        dogtail.rawinput.absoluteMotion(tpos[0] + end / 2 - 200, tpos[1] + 30)
        sleep(0.5)
        dogtail.rawinput.release(tpos[0] + end / 2 - 200, tpos[1] + 30)
        registry.generateKeyboardEvent(
            dogtail.rawinput.keyNameToKeyCode("Control_L"), None, KEY_RELEASE)
        self.goToEnd_button.click()
        self.assertNotEqual(timecode_widget.text, seekbefore,
                            "Not rippled after adding effect")
예제 #42
0
def absoluteMotionWithTrajectory(source_x,
                                 source_y,
                                 dest_x,
                                 dest_y,
                                 mouseDelay=None,
                                 check=True):
    """
    Synthetize mouse absolute motion with trajectory. The 'trajectory' means that the whole motion
    is divided into several atomic movements which are synthetized separately.
    """
    if check:
        checkCoordinates(source_x, source_y)
        checkCoordinates(dest_x, dest_y)
    logger.log("Mouse absolute motion with trajectory to (%s,%s)" %
               (dest_x, dest_y))

    dx = float(dest_x - source_x)
    dy = float(dest_y - source_y)
    max_len = max(abs(dx), abs(dy))
    if max_len == 0:
        # actually, no motion requested
        return
    dx /= max_len
    dy /= max_len
    act_x = float(source_x)
    act_y = float(source_y)

    for _ in range(0, int(max_len)):
        act_x += dx
        act_y += dy
        if mouseDelay:
            doDelay(mouseDelay)
        registry.generateMouseEvent(int(act_x), int(act_y), name='abs')

    if mouseDelay:
        doDelay(mouseDelay)
    else:
        doDelay()
예제 #43
0
    def __generate(i):
        inShiftKeyList = i in Macro.SHIFT_KEY_LIST
        if not (i in Macro.KEY_LIST or inShiftKeyList):
            print 'Cannot type the character \'' + i +'\''

        needShift = inShiftKeyList or i.isupper()

        if needShift:
            controller.generateKeyboardEvent(Macro.KEY_LIST['Shift'], None, KEY_PRESS)

        controller.generateKeyboardEvent((Macro.SHIFT_KEY_LIST if inShiftKeyList else Macro.KEY_LIST)[i], None, KEY_PRESS)
        time.sleep(0.01)
        controller.generateKeyboardEvent((Macro.SHIFT_KEY_LIST if inShiftKeyList else Macro.KEY_LIST)[i], None, KEY_RELEASE)

        if needShift:
            controller.generateKeyboardEvent(Macro.KEY_LIST['Shift'], None, KEY_RELEASE)
예제 #44
0
    def key_up(key):
        """
        > Description
            Hold a specific key up, useful when you want to do key combinations, like Alt + Shift to change the current keyboard layout

        > Parameters
            key (string): The key to hold up

        > Returns
            None

        > Example
            # send Alt + F4 to the current application
            Macro.key_down('Alt')
            Macro.key_down('F4')

            time.sleep(0.2)

            Macro.key_up('Alt')
            Macro.key_up('F4')
        """
        if key in Macro.KEY_LIST:
            controller.generateKeyboardEvent(Macro.KEY_LIST[key], None, KEY_RELEASE)
예제 #45
0
    def test_riple_roll(self):
        self.help_test_insertEndFast()
        seektime = self.search_by_text("0:00:02.455", self.pitivi, roleName="text")
        timeline = self.get_timeline()
        tpos = timeline.position
        end = self.search_clip_end(30, seektime, timeline)

        dogtail.rawinput.absoluteMotion(tpos[0] + end / 2 - 2, tpos[1] + 30)
        registry.generateKeyboardEvent(dogtail.rawinput.keyNameToKeyCode("Control_L"), None, KEY_PRESS)
        dogtail.rawinput.press(tpos[0] + end / 2 - 2, tpos[1] + 30)
        sleep(0.5)
        dogtail.rawinput.absoluteMotion(tpos[0] + end / 2 - 100, tpos[1] + 30)
        sleep(0.5)
        dogtail.rawinput.release(tpos[0] + end / 2 - 100, tpos[1] + 30)
        registry.generateKeyboardEvent(dogtail.rawinput.keyNameToKeyCode("Control_L"), None, KEY_RELEASE)
        self.nextb.click()
        self.assertNotEqual(seektime.text, "0:00:02.455", "Not ripled, but trimed")

        #Regresion test of adding effect
        #Add effect
        tab = self.pitivi.tab("Effect Library")
        tab.click()
        conftab = self.pitivi.tab("Clip configuration")
        conftab.click()
        center = lambda obj: (obj.position[0] + obj.size[0] / 2, obj.position[1] + obj.size[1] / 2)
        table = conftab.child(roleName="table")
        icon = self.search_by_text("Agingtv ", tab, roleName="icon")
        self.improved_drag(center(icon), center(table))
        self.nextb.click()
        seekbefore = seektime.text
        #Try riple and roll
        dogtail.rawinput.absoluteMotion(tpos[0] + end / 2 - 102, tpos[1] + 30)
        registry.generateKeyboardEvent(dogtail.rawinput.keyNameToKeyCode("Control_L"), None, KEY_PRESS)
        dogtail.rawinput.press(tpos[0] + end / 2 - 102, tpos[1] + 30)
        sleep(0.5)
        dogtail.rawinput.absoluteMotion(tpos[0] + end / 2 - 200, tpos[1] + 30)
        sleep(0.5)
        dogtail.rawinput.release(tpos[0] + end / 2 - 200, tpos[1] + 30)
        registry.generateKeyboardEvent(dogtail.rawinput.keyNameToKeyCode("Control_L"), None, KEY_RELEASE)
        self.nextb.click()
        self.assertNotEqual(seektime.text, seekbefore, "Not ripled affter adding effect")
예제 #46
0
 def keyboard(self, key):
     """
     Types the tuple 'key' to the screen. For example you can say:
     ["Alex was in a bad mood lately", "Return", "A", "B", "1", "2", "comma"] and it will try to print:
     Alex was in a bad mood lately
     AB12,
     A simple string rather than a tuple may as well be passed to this function.
     """
     for i in key:
         if i in key_list:
             controller.generateKeyboardEvent(key_codes[key_list.index(i)], None, KEY_PRESS)
             time.sleep(0.01)
             controller.generateKeyboardEvent(key_codes[key_list.index(i)], None, KEY_RELEASE)
         else:
             for j in i:
                 if j in key_list:
                     controller.generateKeyboardEvent(key_codes[key_list.index(j)], None, KEY_PRESS)
                     time.sleep(0.01)
                     controller.generateKeyboardEvent(key_codes[key_list.index(j)], None, KEY_RELEASE)
                 else:
                     print "Unkown character to be sent as event:", j
예제 #47
0
    def test_ripple_roll(self):
        self.insertTwoClipsAndSeekToEnd()
        timecode_widget = self.viewer.child(name="timecode_entry").child(roleName="text")
        self.assertEqual(timecode_widget.text, DURATION_OF_TWO_CLIPS)
        tpos = self.timeline.position
        end = self.search_clip_end(30, timecode_widget, self.timeline)

        dogtail.rawinput.absoluteMotion(tpos[0] + end / 2 - 2, tpos[1] + 30)
        registry.generateKeyboardEvent(dogtail.rawinput.keyNameToKeyCode("Control_L"), None, KEY_PRESS)
        dogtail.rawinput.press(tpos[0] + end / 2 - 2, tpos[1] + 30)
        sleep(0.5)
        dogtail.rawinput.absoluteMotion(tpos[0] + end / 2 - 100, tpos[1] + 30)
        sleep(0.5)
        dogtail.rawinput.release(tpos[0] + end / 2 - 100, tpos[1] + 30)
        registry.generateKeyboardEvent(dogtail.rawinput.keyNameToKeyCode("Control_L"), None, KEY_RELEASE)
        self.goToEnd_button.click()
        self.assertNotEqual(timecode_widget.text, DURATION_OF_TWO_CLIPS, "Not rippled, but trimmed")

        # Check if adding an effect causes a regression in behavior
        self.effectslibrary.click()
        self.clipproperties.click()
        center = lambda obj: (obj.position[0] + obj.size[0] / 2, obj.position[1] + obj.size[1] / 2)
        table = self.clipproperties.child(roleName="table")
        effect_from_library = self.search_by_text(
            "Agingtv", self.effectslibrary, roleName="table cell", exactMatchOnly=False
        )
        self.improved_drag(center(effect_from_library), center(table))
        self.goToEnd_button.click()
        seekbefore = timecode_widget.text
        # Try ripple and roll
        dogtail.rawinput.absoluteMotion(tpos[0] + end / 2 - 102, tpos[1] + 30)
        registry.generateKeyboardEvent(dogtail.rawinput.keyNameToKeyCode("Control_L"), None, KEY_PRESS)
        dogtail.rawinput.press(tpos[0] + end / 2 - 102, tpos[1] + 30)
        sleep(0.5)
        dogtail.rawinput.absoluteMotion(tpos[0] + end / 2 - 200, tpos[1] + 30)
        sleep(0.5)
        dogtail.rawinput.release(tpos[0] + end / 2 - 200, tpos[1] + 30)
        registry.generateKeyboardEvent(dogtail.rawinput.keyNameToKeyCode("Control_L"), None, KEY_RELEASE)
        self.goToEnd_button.click()
        self.assertNotEqual(timecode_widget.text, seekbefore, "Not rippled after adding effect")
예제 #48
0
    def __generate(i):
        inShiftKeyList = i in Macro.SHIFT_KEY_LIST
        if not (i in Macro.KEY_LIST or inShiftKeyList):
            print 'Cannot type the character \'' + i + '\''

        needShift = inShiftKeyList or i.isupper()

        if needShift:
            controller.generateKeyboardEvent(Macro.KEY_LIST['Shift'], None,
                                             KEY_PRESS)

        controller.generateKeyboardEvent(
            (Macro.SHIFT_KEY_LIST if inShiftKeyList else Macro.KEY_LIST)[i],
            None, KEY_PRESS)
        time.sleep(0.01)
        controller.generateKeyboardEvent(
            (Macro.SHIFT_KEY_LIST if inShiftKeyList else Macro.KEY_LIST)[i],
            None, KEY_RELEASE)

        if needShift:
            controller.generateKeyboardEvent(Macro.KEY_LIST['Shift'], None,
                                             KEY_RELEASE)
예제 #49
0
    def reclaimScripts(self):
        """Compares the list of known scripts to the list of known apps,
        deleting any scripts as necessary.
        """

        from pyatspi import Registry

        try:
            desktop = Registry.getDesktop(0)
        except:
            debug.printException(debug.LEVEL_FINEST)
            return

        appList = self.scripts.keys()
        appList = filter(lambda a: a!= None and a not in desktop, appList)
        for app in appList:
            script = self.scripts.pop(app)
            _eventManager.deregisterListeners(script)
            del app
            del script
예제 #50
0
def holdKey(keyName):
    code = keyNameToKeyCode(keyName)
    registry.generateKeyboardEvent(code, None, KEY_PRESS)
    doDelay()
예제 #51
0
파일: main.py 프로젝트: 3demax/Clicky
 def point(self):
     x, y = self.get_center()
     registry.generateMouseEvent(x, y, 'abs')
예제 #52
0
파일: main.py 프로젝트: 3demax/Clicky
 def double_click(self, button=1):
     self.widow_hide()
     x, y = self.get_center()
     registry.generateMouseEvent(x, y, 'b%sd' % button)
예제 #53
0
파일: main.py 프로젝트: 3demax/Clicky
 def double_click(self, button = 1):
     self.widow_hide()
     x,y = self.get_center()
     registry.generateMouseEvent(x, y, 'b%sd' % button)
예제 #54
0
파일: main.py 프로젝트: 3demax/Clicky
 def point(self):
     x,y = self.get_center()
     registry.generateMouseEvent(x, y, 'abs')
예제 #55
0
 def run_event_loop(self):
     debug('starting at-spi loop')
     Registry.start(gil=False)
예제 #56
0
def releaseKey(keyName):
    code = keyNameToKeyCode(keyName)
    registry.generateKeyboardEvent(code, None, KEY_RELEASE)
    doDelay()
예제 #57
0
def point(x, y, check=True):
    if check:
        checkCoordinates(x, y)
    logger.log("Pointing mouse cursor at (%s,%s)" % (x, y))
    registry.generateMouseEvent(x, y, 'abs')
    doDelay(config.actionDelay)