def gotResults_bumpMouse(self, words, fullResults):
        """ usage: <x-axis increment> <y-axis increment> bump <integer
        multiplier> """

        # register required displacement integer 's\s
        x_disp = int(words[0])
        y_disp = int(words[1])
        # do we have a multiplier?
        mult = 1
        if len(words) > 4:
            mult = int(words[4])
        logger.error( "mult:%d" % (mult))
        # get current position
        x, y = natlink.getCursorPos()
        logger.error("x:%d y:%d" % (x,y))
        # coordinate calculated using row and column pixel offset * multiplier 
        if int(words[0]) != 0:
            x = x + x_disp*mult
        if int(words[1]) != 0:
            y = y + y_disp*mult

        logger.error("x:%d y:%d drag" % (x,y))
        # get the equivalent event code of the type of mouse event to perform
        # leftclick, rightclick, rightdouble-click (currently left click)
        event = self.kmap['leftclick']
        # play events down click and then release (for left double click
        # increment from left button up event which produces no action
        # then when incremented, performs the double-click)
        natlink.playEvents([(wm_mousemove, x, y), (event, x, y), (event + 1, x, y)])
Ejemplo n.º 2
0
def buttonClick(btnName='left', count=1, modifiers=None):
    """performs a button (double) click of the mouse
    
    without parameters: a single left click
    accepted values:
     - btnName: 'left', 'right' or 'middle', or 1, 2, 3
     - count: 1 or 2 or 3 (3 not fully tested)
     -  modifiers: 'shift', 'ctrl', 'alt', 'menu' ('alt' and 'menu' are identical)
            (see function getModifierKeyCodes below)
            (if you want more modifiers, separate by "+" or " ", eg. "shift+ctrl")
    """
    x, y = natlink.getCursorPos()
    
    unimacroButtons = {1:'left', 2:'right', 3:'middle'}
    if btnName in [1,2,3]:
        btnName = unimacroButtons[btnName]
        
    singleLookup = { 
        'left':  [(wm_lbuttondown,x,y),(wm_lbuttonup,x,y)],
        'right': [(wm_rbuttondown,x,y),(wm_rbuttonup,x,y)],
        'middle':[(wm_mbuttondown,x,y),(wm_mbuttonup,x,y)] }
    doubleLookup = {
        'left':  [(wm_lbuttondblclk,x,y),(wm_lbuttonup,x,y)],
        'right': [(wm_rbuttondblclk,x,y),(wm_rbuttonup,x,y)],
        'middle':[(wm_mbuttondblclk,x,y),(wm_mbuttonup,x,y)] }

    try:
        single = singleLookup[btnName]  # KeyError means invalid button name
        double = doubleLookup[btnName]
    except KeyError:
        raise ValueError('buttonClick, invalid "btnName": %s'% btnName)
        
    events = [] # collect all events in a list
    if modifiers:
        try:
            keycodes = getModifierKeyCodes(modifiers)
        except KeyError:
            raise ValueError('buttonClick, invalid "modifiers": %s'% repr(modifiers))
        for k in keycodes:
            events.append( (wm_keydown, k) )
        # print "modifiers keycodes: %s"% keycodes
        
    if count == 1:
        events.extend( single )
    elif count == 2:
        events.extend( single )
        events.extend( double )
    elif count == 3:
        events.extend( single )
        events.extend( single )
        events.extend( single )
    else:
        raise ValueError( 'buttonClick, invalid "count": %s'% count )

    if modifiers:
        for k in keycodes:
            events.append( (wm_keyup, k) )
    if events:
        # print 'buttonClick events: %s'% events
        natlink.playEvents(events)
Ejemplo n.º 3
0
    def gotResults_bumpMouse(self, words, fullResults):
        """ usage: <x-axis increment> <y-axis increment> bump <integer
        multiplier> """

        # register required displacement integer 's\s
        x_disp = int(words[0])
        y_disp = int(words[1])
        # do we have a multiplier?
        mult = 1
        if len(words) > 4:
            mult = int(words[4])
        logger.error("mult:%d" % (mult))
        # get current position
        x, y = natlink.getCursorPos()
        logger.error("x:%d y:%d" % (x, y))
        # coordinate calculated using row and column pixel offset * multiplier
        if int(words[0]) != 0:
            x = x + x_disp * mult
        if int(words[1]) != 0:
            y = y + y_disp * mult

        logger.error("x:%d y:%d drag" % (x, y))
        # get the equivalent event code of the type of mouse event to perform
        # leftclick, rightclick, rightdouble-click (currently left click)
        event = self.kmap['leftclick']
        # play events down click and then release (for left double click
        # increment from left button up event which produces no action
        # then when incremented, performs the double-click)
        natlink.playEvents([(wm_mousemove, x, y), (event, x, y),
                            (event + 1, x, y)])
Ejemplo n.º 4
0
 def drag(self, dragDirection='up', startPos=None, dist=4):
     displacement = self.dispMap[dragDirection]
     call_Dragon('RememberPoint', '', [])
     x, y = natlink.getCursorPos()
     newx,newy = self.getDragPoints(x,y,displacement,dragDirection)
     natlink.playEvents([(wm_mousemove, newx, newy)])
     call_Dragon('DragToPoint', 'i', [])
Ejemplo n.º 5
0
 def click(self,
           clickType='leftclick',
           x=None,
           y=None,
           appName='iphoneWin'):
     # get the equivalent event code of the type of mouse event to perform
     # leftclick, rightclick, rightdouble-click (see kmap)
     event = self.kmap[clickType]
     # play events down click and then release (for left double click
     # increment from left button up event which produces no action
     # then when incremented, performs the double-click)
     # if coordinates are not supplied, just click
     if getattr(event, 'conjugate'):
         if not (x or y):
             x, y = natlink.getCursorPos()
         # apply vertical offset dependent on presence of "personal hotspot"
         # bar across the top of the screen
         y += self.windows.appDict[appName].vert_offset
         logging.debug('clicking at: %d, %d' % (x, y))
         natlink.playEvents([(wm_mousemove, x, y), (event, x, y),
                             (event + 1, x, y)])
     else:
         logging.error(' incorrect click look up for the event %s' %
                       str(clickType))
         # default to
         natlink.recognitionMimic(['mouse', 'click'])
Ejemplo n.º 6
0
 def drag(self, dragDirection='up', startPos=None, dist=4):
     displacement = self.dispMap[dragDirection]
     call_Dragon('RememberPoint', '', [])
     x, y = natlink.getCursorPos()
     newx, newy = self.getDragPoints(x, y, displacement, dragDirection)
     natlink.playEvents([(wm_mousemove, newx, newy)])
     call_Dragon('DragToPoint', 'i', [])
Ejemplo n.º 7
0
    def cancelMode(self):
        debugPrint('cancelMode')
        natlink.setTrayIcon()

        if self.inTimer:
            natlinktimer.setTimerCallback(self.onTimer, 0)
            self.inTimer = 0
            if self.drag:
                debugPrint('switch of dragging')
                xPos, yPos = natlink.getCursorPos()
                if self.drag == 2:
                    natlink.playEvents([(natlinkutils.wm_rbuttonup, xPos, yPos)
                                        ])
                else:
                    natlink.playEvents([(natlinkutils.wm_lbuttonup, xPos, yPos)
                                        ])
                self.drag = 0
            elif self.state == 'searching':
                self.stopSearch()

        self.state = ''
        self.minorState = ''
        self.curDir = ''
        self.Count = 0
        self.mouseSteps = 10
        self.inside = 0
        self.insideCommand = 0
        self.waiting = 0
        self.drag = 0
        self.repeatFlag = 0
        self.hadRepeat = 0
        self.repeatStuff = None
        self.lastResults = []
        self.activateSet(normalSet, exclusive=0)
Ejemplo n.º 8
0
 def gotResults_start(self, words, fullResults):
     # execute a control-left drag down 30 pixels
     x, y = natlink.getCursorPos()
     natlink.playEvents([(wm_keydown, vk_control, 1),
                         (wm_lbuttondown, x, y), (wm_mousemove, x, y + 30),
                         (wm_lbuttonup, x, y + 30),
                         (wm_keyup, vk_control, 1)])
Ejemplo n.º 9
0
 def gotResults_start(self,words,fullResults):
     # execute a control-left drag down 30 pixels
     x,y = natlink.getCursorPos()
     natlink.playEvents( [ (wm_keydown,vk_control,1),
                           (wm_lbuttondown,x,y),
                           (wm_mousemove,x,y+30),
                           (wm_lbuttonup,x,y+30),
                           (wm_keyup,vk_control,1) ] )
Ejemplo n.º 10
0
 def moveMouse(self,direction,count):
     xPos,yPos = natlink.getCursorPos()
     if direction == 'up': yPos = yPos - count
     elif direction == 'down': yPos = yPos + count
     elif direction == 'left': xPos = xPos - count
     elif direction == 'right': xPos = xPos + count
     xSize,ySize = natlink.getScreenSize()
     if xPos < 0: xPos = 0
     if xPos >= xSize: xPos = xSize - 1
     if yPos < 0: yPos = 0
     if yPos >= ySize: yPos = ySize - 1
     natlink.playEvents([(wm_mousemove,xPos,yPos)])
Ejemplo n.º 11
0
def mbDonumber(number, modifier=None):
    events = []
    if modifier:
        events.append (modifiers[modifier][0])
    for n in number:
        code = getKeyCode(n)
        events.append((natut.wm_keydown, code, 1))
        events.append((natut.wm_keyup, code, 1))
    if modifier:
        events.append (modifiers[modifier][1])
##    print 'events',events
    natlink.playEvents(events)
Ejemplo n.º 12
0
 def moveMouse(self, direction, count):
     xPos, yPos = natlink.getCursorPos()
     if direction == 'up': yPos = yPos - count
     elif direction == 'down': yPos = yPos + count
     elif direction == 'left': xPos = xPos - count
     elif direction == 'right': xPos = xPos + count
     xSize, ySize = natlink.getScreenSize()
     if xPos < 0: xPos = 0
     if xPos >= xSize: xPos = xSize - 1
     if yPos < 0: yPos = 0
     if yPos >= ySize: yPos = ySize - 1
     natlink.playEvents([(natlinkutils.wm_mousemove, xPos, yPos)])
Ejemplo n.º 13
0
 def gotResults_startMousing(self, words, fullResults):
     self.activateSet(['mousing'], exclusive=1)
     debugPrint('start mousing %s' % repr(words))
     if self.hasCommon(words, ["MUIS", 'MOUSE']):
         self.state = 'mousing'
     if self.hasCommon(words, ["SLEEP", 'DRAG']):
         self.state = 'dragging'
         xPos, yPos = natlink.getCursorPos()
         if self.hasCommon(words, ["SNELMENU", 'RIGHT']):
             self.drag = 2
             natlink.playEvents([(natlinkutils.wm_rbuttondown, xPos, yPos)])
         else:
             self.drag = 1
             natlink.playEvents([(natlinkutils.wm_lbuttondown, xPos, yPos)])
Ejemplo n.º 14
0
def mbDonumber(number, modifier=None):
    events = []
    if modifier:
        events.append (modifiers[modifier][0])
    for n in number:
        code = getKeyCode(n)
        events.append((natut.wm_keydown, code, 1))
        events.append((natut.wm_keyup, code, 1))
    if modifier:
        events.append (modifiers[modifier][1])
    try:
        natlink.playEvents(events)
    except natlink.NatError:
        print "=================="
        print "Error playing events in firefox browsing, doNumber: %s"% repr(events)
 def gotResults_repeatKey(self, words, fullResults):
     num = int(words[3])
     key = self.kmap[str(words[2])]
     # assumed only standard keys (not system keys) will want to be repeated
     #  this requires wm_key(down|up)
     [natlink.playEvents([(wm_keydown, key, 1), (wm_keyup, key, 1)]) for i
      in range(num)]
Ejemplo n.º 16
0
def mbDonumber(number, modifier=None):
    events = []
    if modifier:
        events.append(modifiers[modifier][0])
    for n in number:
        code = getKeyCode(n)
        events.append((natut.wm_keydown, code, 1))
        events.append((natut.wm_keyup, code, 1))
    if modifier:
        events.append(modifiers[modifier][1])
    try:
        natlink.playEvents(events)
    except natlink.NatError:
        print "=================="
        print "Error playing events in firefox browsing, doNumber: %s" % repr(
            events)
Ejemplo n.º 17
0
def buttonClick(btnName='left',count=1):
    x, y = natlink.getCursorPos()
    singleLookup = { 
        'left':  [(wm_lbuttondown,x,y),(wm_lbuttonup,x,y)],
        'right': [(wm_rbuttondown,x,y),(wm_rbuttonup,x,y)],
        'moddle':[(wm_mbuttondown,x,y),(wm_mbuttonup,x,y)] }
    doubleLookup = {
        'left':  [(wm_lbuttondblclk,x,y),(wm_lbuttonup,x,y)],
        'right': [(wm_rbuttondblclk,x,y),(wm_rbuttonup,x,y)],
        'middle':[(wm_mbuttondblclk,x,y),(wm_mbuttonup,x,y)] }

    single = singleLookup[btnName]  # KeyError means invalid button name
    double = doubleLookup[btnName]

    if count == 1: natlink.playEvents( single )
    elif count == 2: natlink.playEvents( single + double )
    else: raise ValueError( "invalid count" )
Ejemplo n.º 18
0
 def gotResults_repeatKey(self, words, fullResults):
     num = int(words[3])
     key = self.kmap[str(words[2])]
     # assumed only standard keys (not system keys) will want to be repeated
     #  this requires wm_key(down|up)
     [
         natlink.playEvents([(wm_keydown, key, 1), (wm_keyup, key, 1)])
         for i in range(num)
     ]
Ejemplo n.º 19
0
def buttonClick(btnName='left', count=1):
    x, y = natlink.getCursorPos()
    singleLookup = {
        'left': [(wm_lbuttondown, x, y), (wm_lbuttonup, x, y)],
        'right': [(wm_rbuttondown, x, y), (wm_rbuttonup, x, y)],
        'moddle': [(wm_mbuttondown, x, y), (wm_mbuttonup, x, y)]
    }
    doubleLookup = {
        'left': [(wm_lbuttondblclk, x, y), (wm_lbuttonup, x, y)],
        'right': [(wm_rbuttondblclk, x, y), (wm_rbuttonup, x, y)],
        'middle': [(wm_mbuttondblclk, x, y), (wm_mbuttonup, x, y)]
    }

    single = singleLookup[btnName]  # KeyError means invalid button name
    double = doubleLookup[btnName]

    if count == 1: natlink.playEvents(single)
    elif count == 2: natlink.playEvents(single + double)
    else: raise ValueError("invalid count")
Ejemplo n.º 20
0
 def click(self, clickType='leftclick', x=None, y=None, appName='iphoneWin'):
     # get the equivalent event code of the type of mouse event to perform
     # leftclick, rightclick, rightdouble-click (see kmap)
     event = self.kmap[clickType]
     # play events down click and then release (for left double click
     # increment from left button up event which produces no action
     # then when incremented, performs the double-click)
     # if coordinates are not supplied, just click
     if getattr(event, 'conjugate'):
         if not (x or y):
             x, y = natlink.getCursorPos()
         # apply vertical offset dependent on presence of "personal hotspot"
         # bar across the top of the screen
         y += self.windows.appDict[appName].vert_offset
         logging.debug('clicking at: %d, %d'% (x,y))
         natlink.playEvents(
             [(wm_mousemove, x, y), (event, x, y), (event + 1, x, y)])
     else:
         logging.error(' incorrect click look up for the event %s'% str(clickType))
         # default to
         natlink.recognitionMimic(['mouse', 'click'])
Ejemplo n.º 21
0
    def gotResults_windowFocus(self, words, fullResults):
        """ Vertical taskbar window titles are spreadstarting from 150 pixels
        from the taskbar. Each subsequent icon is roughly 25 pixels
        between.this is assumed the same between subsequent rows.  If 'from
        bottom'modifier supplied to command string, calculate the offset from
        the first window title. This technique is an alternative to be able to
        determine a phrase that would be recognised as a window title (e.g.
        explicitly setting each programs window title)
        TODO: need to fix, inaccurate when counting from bottom. Windows not
        filtered properly? (Extra "Windows" which do not have physical
        component). EDIT: 291013 - modified to perform close"""

        # Detect the optional word to specify offset for variable component
        if words[1] == 'on':
            repeat_modifier_offset = 3
        else:
            repeat_modifier_offset = 2
        # screen dimensions (excluding taskbar)
        x, y = natlink.getScreenSize()
        # number of pixels between top of screen and top row of taskbar icons
        row_initial = TB_ROW_INITIAL  #35 #75
        # number of pixels between left side of taskbar and first column of icons
        col_initial = TB_COL_INITIAL  #14
        # separation between subsequent rows
        row_sep = TB_ROW_SEP  #23 #32
        # coordinate calculated, vertical offset is from top, horizontal offset
        # from the left edge of the taskbar (maximum horizontal value of the
        # screen visible size (which excludes taskbar)) calculated earlier.
        x, y = x + col_initial, row_initial  # initial position
        # argument to pass to callback contains words used in voice command
        # (this is also a recognised top-level window?) And dictionary of
        # strings: handles. (Window title: window handle)
        # selecting index from bottom window title on taskbar
        # enumerate all top-level windows and send handles to callback
        wins = {}
        try:
            # Windows dictionary returned assecond element of tuple
            wins = self.windows.winDiscovery(skipTitle=' '.join(words))[1]
            #logger.debug('enumerate Windows: %s'% wins)
        except:
            logger.error('cannot enumerate Windows')
            logger.error(tb.format_exc())
            return

        # after visible taskbar application windows have been added to
        # dictionary (second element of wins tuple), we can calculate
        # relative offset from last taskbar title.
        total_windows = len(wins)
        # print('Number of taskbar applications: {0};'.format( total_windows))
        # print wins.keys()
        # enumerate child windows of visible desktop top-level windows.
        # we want to use the dictionary component of wins and create a map of
        # parent to child Window handles.
        if words[4:5]:
            # get desired index "from bottom" (negative index)
            from_bottom_modifier = int(words[repeat_modifier_offset])
            # maximum number of increments is total_Windows -1
            relative_offset = total_windows - from_bottom_modifier  #- 1
        else:
            # get the index of window title required, add x vertical offsets
            # to get right vertical coordinate(0-based)
            relative_offset = int(words[repeat_modifier_offset]) - 1
        if 0 > relative_offset or relative_offset >= total_windows:
            print(
                'Specified taskbar index out of range. '
                '{0} window titles listed.'.format(total_windows))
            return 1
        y = y + (row_sep * relative_offset)
        # move mouse to 00 first then separate mouse movement from click events
        # this seems to avoid occasional click failure
        natlink.playEvents([
            (wm_mousemove, x, y),
        ])
        if words[0] == 'close':
            event = self.kmap['rightclick']
            natlink.playEvents([(event, x, y), (event + 1, x, y)])
            natlink.playString('{up}{enter}')
        else:
            event = self.kmap['leftclick']
            natlink.playEvents([(event, x, y), (event + 1, x, y)])
    def gotResults_windowFocus(self, words, fullResults):
        """ Vertical taskbar window titles are spreadstarting from 150 pixels
        from the taskbar. Each subsequent icon is roughly 25 pixels
        between.this is assumed the same between subsequent rows.  If 'from
        bottom'modifier supplied to command string, calculate the offset from
        the first window title. This technique is an alternative to be able to
        determine a phrase that would be recognised as a window title (e.g.
        explicitly setting each programs window title)
        TODO: need to fix, inaccurate when counting from bottom. Windows not
        filtered properly? (Extra "Windows" which do not have physical
        component). EDIT: 291013 - modified to perform close"""

        # Detect the optional word to specify offset for variable component
        if words[1] == 'on':
            repeat_modifier_offset = 3
        else:
            repeat_modifier_offset = 2
        # screen dimensions (excluding taskbar)
        x, y = natlink.getScreenSize()
        # number of pixels between top of screen and top row of taskbar icons
        row_initial = TB_ROW_INITIAL #35 #75
        # number of pixels between left side of taskbar and first column of icons
        col_initial = TB_COL_INITIAL #14
        # separation between subsequent rows
        row_sep = TB_ROW_SEP #23 #32
        # coordinate calculated, vertical offset is from top, horizontal offset
        # from the left edge of the taskbar (maximum horizontal value of the
        # screen visible size (which excludes taskbar)) calculated earlier.
        x, y = x + col_initial, row_initial  # initial position
        # argument to pass to callback contains words used in voice command
        # (this is also a recognised top-level window?) And dictionary of
        # strings: handles. (Window title: window handle)
        # selecting index from bottom window title on taskbar
        # enumerate all top-level windows and send handles to callback
        wins={}
        try:
            # Windows dictionary returned assecond element of tuple
            wins=self.windows.winDiscovery(skipTitle=' '.join(words))[1]
            #logger.debug('enumerate Windows: %s'% wins)
        except:
            logger.error('cannot enumerate Windows')
            logger.error(tb.format_exc())
            return

        # after visible taskbar application windows have been added to
        # dictionary (second element of wins tuple), we can calculate
        # relative offset from last taskbar title.
        total_windows = len(wins)
        # print('Number of taskbar applications: {0};'.format( total_windows))
        # print wins.keys()
        # enumerate child windows of visible desktop top-level windows.
        # we want to use the dictionary component of wins and create a map of
        # parent to child Window handles.
        if words[4:5]:
            # get desired index "from bottom" (negative index)
            from_bottom_modifier = int(words[ repeat_modifier_offset])
            # maximum number of increments is total_Windows -1
            relative_offset = total_windows - from_bottom_modifier #- 1
        else:
            # get the index of window title required, add x vertical offsets
            # to get right vertical coordinate(0-based)
            relative_offset = int(words[repeat_modifier_offset]) - 1
        if 0 > relative_offset or relative_offset >= total_windows:
            print('Specified taskbar index out of range. '
                  '{0} window titles listed.'.format(total_windows))
            return 1
        y = y + (row_sep *  relative_offset)
        # move mouse to 00 first then separate mouse movement from click events
        # this seems to avoid occasional click failure
        natlink.playEvents([(wm_mousemove, x, y),])
        if words[0] == 'close':
            event = self.kmap['rightclick']
            natlink.playEvents([(event, x, y), (event + 1, x, y)])
            natlink.playString('{up}{enter}')
        else:
            event = self.kmap['leftclick']
            natlink.playEvents([(event, x, y), (event + 1, x, y)])
 def gotResults_navigate(self,words,fullResults):
     key = self.kmap[str(words[1])]
     # this requires wm_key(down|up)
     natlink.playEvents([(wm_keydown, key, 1), (wm_keyup, key, 1)])