Example #1
0
    def testPreTests(self):
        # make sure that NatSpeak is loaded into memory
        testForException = self.doTestForException
        # these function should all fail before natConnect is called
        testForException(natlink.NatError, "natlink.playString('')")
        testForException(natlink.NatError, "natlink.getCurrentModule()")
        testForException(natlink.NatError, "natlink.getCurrentUser()")
        testForException(natlink.NatError, "natlink.getMicState()")
        testForException(natlink.NatError, "natlink.setMicState('off')")
        testForException(natlink.NatError, "natlink.execScript('')")
        testForException(natlink.NatError, "natlink.recognitionMimic('')")
        testForException(natlink.NatError, "natlink.playEvents([])")
        testForException(natlink.NatError, "natlink.inputFromFile('test.wav')")
        testForException(natlink.NatError, "natlink.setTimerCallback(None)")
        testForException(natlink.NatError, "natlink.getTrainingMode()")
        testForException(natlink.NatError,
                         "natlink.startTraining('calibrate')")
        testForException(natlink.NatError, "natlink.finishTraining()")
        testForException(natlink.NatError, "natlink.getAllUsers()")
        testForException(natlink.NatError, "natlink.openUser('testUser')")
        testForException(natlink.NatError, "natlink.saveUser()")
        testForException(natlink.NatError, "natlink.getUserTraining()")
        testForException(natlink.NatError, "natlink.waitForSpeech(0)")
        testForException(natlink.NatError, "natlink.GramObj().load('')")
        testForException(natlink.NatError, "natlink.DictObj()")

        # these functions should all work before natConnect is called
        natlink.displayText('', 0)
        natlink.getClipboard()
        natlink.getCallbackDepth()
        natlink.getCursorPos()
        natlink.getScreenSize()
        natlink.setBeginCallback(None)
        natlink.setChangeCallback(None)
        natlink.isNatSpeakRunning()
Example #2
0
    def testPreTests(self):
        # make sure that NatSpeak is loaded into memory
        testForException = self.doTestForException
        # these function should all fail before natConnect is called
        testForException( natlink.NatError, "natlink.playString('')" )
        testForException( natlink.NatError, "natlink.getCurrentModule()" )
        testForException( natlink.NatError, "natlink.getCurrentUser()" )
        testForException( natlink.NatError, "natlink.getMicState()" )
        testForException( natlink.NatError, "natlink.setMicState('off')" )
        testForException( natlink.NatError, "natlink.execScript('')" )
        testForException( natlink.NatError, "natlink.recognitionMimic('')" )
        testForException( natlink.NatError, "natlink.playEvents([])" )
        testForException( natlink.NatError, "natlink.inputFromFile('test.wav')" )
        testForException( natlink.NatError, "natlink.setTimerCallback(None)" )
        testForException( natlink.NatError, "natlink.getTrainingMode()" )
        testForException( natlink.NatError, "natlink.startTraining('calibrate')" )
        testForException( natlink.NatError, "natlink.finishTraining()" )
        testForException( natlink.NatError, "natlink.getAllUsers()" )
        testForException( natlink.NatError, "natlink.openUser('testUser')" )
        testForException( natlink.NatError, "natlink.saveUser()" )
        testForException( natlink.NatError, "natlink.getUserTraining()" )
        testForException( natlink.NatError, "natlink.waitForSpeech(0)" )
        testForException( natlink.NatError, "natlink.GramObj().load('')" )
        testForException( natlink.NatError, "natlink.DictObj()" )

        # these functions should all work before natConnect is called
        natlink.displayText('',0)
        natlink.getClipboard()
        natlink.getCallbackDepth()
        natlink.getCursorPos()
        natlink.getScreenSize()
        natlink.setBeginCallback(None)
        natlink.setChangeCallback(None)
        natlink.isNatSpeakRunning()
    def tttest_getPositions(self):
        """test setting and getting positions in all possible ways
        
        use action RMP to go to the wanted position.
        
        then each time get a position
        (absolute/relative, absorrel, screen, active window or client area (0, 1, 5),
        and relative to one of the corners (0, 1, 2, 3))
        setting it again and see if same position is found
        
        get with: getMousePosition
        set with: doMouse
        """
        #absorrel = 0 # absolute
        #which = 0 # whole screen
        #corner = 0 # top left
        action("RMP(5, 0.3, 0.4, noclick)"
               )  # relative in foreground window, tune to your testing!

        initialPosition = natlink.getCursorPos()
        for absorrel in (0, 1):
            for which in (0, 1, 5):
                for cornerPos in range(4):
                    #absorrel, which, cornerPos = 1, 0, 0
                    #absorrel = 1
                    # each test, little shifting for relative allowed
                    if absorrel:
                        epsilon = 0  # relative, position may shift a bit...
                    else:
                        epsilon = 0  # absolute, caculations must fit
                    if absorrel == 0 and which == 0 and cornerPos > 0:
                        print 'invalid combination to test: absorrel: %s, which: %s, cornerPos: %s' % (
                            absorrel, which, cornerPos)
                        continue
                    initialPosition = natlink.getCursorPos()

                    mousePos = natlinkutilsqh.getMousePosition(
                        absorrel, which, cornerPos)
                    if mousePos is None:
                        self.fail(
                            'getMousePosition in test suite should not result in None (absorrel: %s, which: %s, cornerPos: %s)'
                            % (absorrel, which, cornerPos))
                    x, y = mousePos
                    natlinkutilsqh.doMouse(absorrel,
                                           which,
                                           x,
                                           y,
                                           mouse="noclick")
                    finalPosition = natlink.getCursorPos()
                    log('command: %s, %s, %s, %s, initial: %s, final: %s' %
                        (absorrel, which, x, y, repr(initialPosition),
                         repr(finalPosition)))
                    self.assert_equal(
                        initialPosition,
                        finalPosition,
                        "position of mouse after simple action should be the same\n"
                        "absorrel: %s, which: %s, cornerPos: %s" %
                        (absorrel, which, cornerPos),
                        epsilon=epsilon)
 def rule_gettaskordocumentposition(self, words):
     """
     #commands for recording taskbar position (global)
     #or the document position (program specific)
     get (task|document) position ({taskdoccount})
     """
     # getting the task positions (use with 1 and with another number)
     # position mouse on task number or clock and speak the command
     # first time only, or after changes of taskbar position
     count = self.getNumberFromSpoken(words[-1])
     doTaskbar = self.hasCommon(words[1], 'task')
     doDocument = self.hasCommon(words[2], 'document')
     if count not in self.taskdocCounts:
         print '_tasks, gettaskordocumentposition: no valid count (%s): ', count
         return
     if doTaskbar:
         x, y = natlink.getCursorPos()
         if count == 1:
             print 'setting mouseX1: ', x
             print 'setting mouseY1: ', y
             setPosition('mousex1', x)
             setPosition('mousey1', y)
         else:
             mousex1 = getPosition('mousex1')
             mousey1 = getPosition('mousey1')
             
             mouseXdiff = int((x - mousex1 )/(count-1))
             mouseYdiff = int((y - mousey1 )/(count-1))
             print 'setting mouseXdiff: ', mouseXdiff
             print 'setting mouseYdiff: ', mouseYdiff
             setPosition('mousexdiff', mouseXdiff)
             setPosition('mouseydiff', mouseYdiff)
     elif doDocument:
         prog, title, topchild, windowHandle = natqh.getProgInfo()
         if not prog:
             print '_tasks, gettaskordocumentposition: no program in foreground, so cannot get document position for program: %s (title:%s)'% (prog, title)
             return
         x, y = natlink.getCursorPos()
         if count == 1:
             print 'setting mouseX1: ', x
             print 'setting mouseY1: ', y
             setPosition('mousex1', x, prog=prog)
             setPosition('mousey1', y, prog=prog)
         else:
             mousex1 = getPosition('mousex1', prog=prog)
             mousey1 = getPosition('mousey1', prog=prog)
             
             mouseXdiff = int((x - mousex1 )/(count-1))
             mouseYdiff = int((y - mousey1 )/(count-1))
             print 'setting mouseXdiff: ', mouseXdiff
             print 'setting mouseYdiff: ', mouseYdiff
             setPosition('mousexdiff', mouseXdiff, prog=prog)
             setPosition('mouseydiff', mouseYdiff, prog=prog)
     else:
         print 'invalid word in in gettaskordocumentposition: %s'% words
         return
 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'])
Example #6
0
def mouse_position(kind=None):
    left, top = anchor(kind)
    x, y = natlink.getCursorPos()
    if not kind or kind == "absolute":
        return "%d,%d" % (x - left, y - top)
    else:
        return "%s,%d,%d" % (kind, x - left, y - top)
Example #7
0
    def rule_gettaskposition(self, words):
        """
        #commands for recording taskbar positions:
        get task position {taskcount}
        """
        # getting the task positions (use with 1 and with another number)
        # position mouse on task number or clock and speak the command
        # june 2016: removed the obsolete clock commands.
        # first time only, or after changes of taskbar position
        count = self.getNumberFromSpoken(words[-1])
        x, y = natlink.getCursorPos()
        if count in self.taskCounts:
            print '%s, setting task position: %s' % (self.name, count)
        else:
            print '%s, not a valid "count" for setting task position: %s' % (
                self.name, count)
            return
        if count == 1:
            print 'setting mouseX1: ', x
            print 'setting mouseY1: ', y
            setPosition('mousex1', x)
            setPosition('mousey1', y)
        else:
            mousex1 = getPosition('mousex1')
            mousey1 = getPosition('mousey1')

            mouseXdiff = int((x - mousex1) / (count - 1))
            mouseYdiff = int((y - mousey1) / (count - 1))
            print 'setting mouseXdiff: ', mouseXdiff
            print 'setting mouseYdiff: ', mouseYdiff
            setPosition('mousexdiff', mouseXdiff)
            setPosition('mouseydiff', mouseYdiff)
 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', [])
Example #9
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)
    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)])
 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', [])
Example #12
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)
Example #13
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)])
Example #14
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)])
Example #15
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) ] )
 def tttest_getOutsideWindow(self):
     """try to position on the taskbar and get the position
     """
     
     action("RMP(5, 1, 0.5, noclick)") # relative in foreground window, tune to your testing!
     action("MP(2, 500, 0, noclick)")   # move a bit to the right
     initialPosition = natlink.getCursorPos()
     mousePos = natlinkutilsqh.getMousePosition() # abs, screen, corner not relevant
     if mousePos is None:
         self.fail("could not get mouse position")
     x, y = mousePos
     absorrel, which = 0, 0
     natlinkutilsqh.doMouse(absorrel, which, x, y, mouse="noclick")
     finalPosition = natlink.getCursorPos()
     log('command outside window(?): %s, %s, %s, %s, initial: %s, final: %s'% (absorrel, which, x, y, repr(initialPosition), repr(finalPosition)))
     self.assert_equal(initialPosition, finalPosition, "position of mouse after move outside the current window should be the same\n"
             "absorrel: %s, which: %s"% (absorrel, which))
Example #17
0
 def gotResults_mousefix(self, words, fullResults):
     fix = 0
     xPos, yPos = natlink.getCursorPos()
     if self.hasCommon(words, ['vast', 'omlaag', 'Down', 'Fix']):
         action('MDOWN')
     elif self.hasCommon(words, ['los', 'omhoog', 'Up', 'Release']):
         action('ENDMOUSE')
     else:
         print '_general, mousefix, invalid keywords: %s' % words
Example #18
0
 def gotResults_mousefix(self,words,fullResults):
     fix = 0
     xPos,yPos = natlink.getCursorPos()
     if self.hasCommon(words, ['vast', 'omlaag', 'Down', 'Fix']):
         action('MDOWN')
     elif self.hasCommon(words, ['los', 'omhoog', 'Up', 'Release']):
         action('ENDMOUSE')
     else:
         print '_general, mousefix, invalid keywords: %s'% words
Example #19
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)])
Example #20
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)])
Example #21
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)])
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" )
Example #23
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")
 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'])
Example #25
0
    def rule_getdocumentposition(self, words):
        """
        #commands for recording a document position, application specific
        get document position {documentcount}
        """
        # getting the task positions (use with 1 and with another number)
        # position mouse on task number or clock and speak the command
        # first time only, or after changes of taskbar position
        prog, title, topchild, classname, hndle = natqh.getProgInfo()
        if not prog:
            print(
                '%s, no valid program for setting document position: %s (title:%s)'
                % (self.name, prog, title))
            return
        count = self.getNumberFromSpoken(words[-1])
        x, y = natlink.getCursorPos()
        if count in self.documentCounts:
            print('%s, setting document position %s for program: %s' %
                  (self.name, count, prog))
        else:
            print(
                '%s, cannot set document position "%s" for program: %s (invalid count)'
                % (self.name, count, prog))
            return
        if count == 1:
            print('setting mouseX1: ', x)
            print('setting mouseY1: ', y)
            setPosition('mousex1', x, prog=prog)
            setPosition('mousey1', y, prog=prog)
        else:
            mousex1 = getPosition('mousex1', prog=prog)
            mousey1 = getPosition('mousey1', prog=prog)

            mouseXdiff = int((x - mousex1) / (count - 1))
            mouseYdiff = int((y - mousey1) / (count - 1))
            print('setting mouseXdiff: ', mouseXdiff)
            print('setting mouseYdiff: ', mouseYdiff)
            setPosition('mousexdiff', mouseXdiff, prog=prog)
            setPosition('mouseydiff', mouseYdiff, prog=prog)
Example #26
0
 def rule_gettaskposition(self, words):
     """
     #commands for recording taskbar and clock positions:
     'get task position' ({taskcount}|clock)
     """
     # getting the task positions (use with 1 and with another number)
     # position mouse on task number or clock and speak the command
     # first time only, or after changes of taskbar position
     count = self.getNumberFromSpoken(words[-1])
     x, y = natlink.getCursorPos()
     if count in self.taskCounts:
         print 'setting task position: ', count
     else:
         count = 0
     if count == 1:
         print 'setting mouseX1: ', x
         print 'setting mouseY1: ', y
         setPosition('mousex1', x)
         setPosition('mousey1', y)
     elif count:
         mousex1 = getPosition('mousex1')
         mousey1 = getPosition('mousey1')
         
         mouseXdiff = int((x - mousex1 )/(count-1))
         mouseYdiff = int((y - mousey1 )/(count-1))
         print 'setting mouseXdiff: ', mouseXdiff
         print 'setting mouseYdiff: ', mouseYdiff
         setPosition('mousexdiff', mouseXdiff)
         setPosition('mouseydiff', mouseYdiff)
     elif self.hasCommon(words,'clock'):
         print 'clock position:', x, y
         setPosition('clockx', x)
         setPosition('clocky', y)
     else:
         print 'invalid option in gettaskposition: %s'% words
         return
Example #27
0
    def rule_gettaskposition(self, words):
        """
        #commands for recording taskbar and clock positions:
        'get task position' ({taskcount}|clock)
        """
        # getting the task positions (use with 1 and with another number)
        # position mouse on task number or clock and speak the command
        # first time only, or after changes of taskbar position
        count = self.getNumberFromSpoken(words[-1])
        x, y = natlink.getCursorPos()
        if count in self.taskCounts:
            print 'setting task position: ', count
        else:
            count = 0
        if count == 1:
            print 'setting mouseX1: ', x
            print 'setting mouseY1: ', y
            setPosition('mousex1', x)
            setPosition('mousey1', y)
        elif count:
            mousex1 = getPosition('mousex1')
            mousey1 = getPosition('mousey1')

            mouseXdiff = int((x - mousex1) / (count - 1))
            mouseYdiff = int((y - mousey1) / (count - 1))
            print 'setting mouseXdiff: ', mouseXdiff
            print 'setting mouseYdiff: ', mouseYdiff
            setPosition('mousexdiff', mouseXdiff)
            setPosition('mouseydiff', mouseYdiff)
        elif self.hasCommon(words, 'clock'):
            print 'clock position:', x, y
            setPosition('clockx', x)
            setPosition('clocky', y)
        else:
            print 'invalid option in gettaskposition: %s' % words
            return
Example #28
0
def mouse_get():
    position = natlink.getCursorPos()
    return "%d,%d" % position
Example #29
0
 def gotResults_androidSC(self, words, fullResults):
     print 'Screen dimensions: ' + str(natlink.getScreenSize())
     print 'Mouse cursor position: ' + str(natlink.getCursorPos())
     print 'Entire recognition result: ' + str(fullResults)
     print 'Partial recognition result: ' + str(words)
 def gotResults_androidSC(self, words, fullResults):
     print 'Screen dimensions: ' + str(natlink.getScreenSize())
     print 'Mouse cursor position: ' + str(natlink.getCursorPos())
     print 'Entire recognition result: ' + str(fullResults)
     print 'Partial recognition result: ' + str(words)
Example #31
0
def position():
    return natlink.getCursorPos()
Example #32
0
def mouse_get_local():
    x, y = natlink.getCursorPos()
    name, title, hwnd = natlink.getCurrentModule()
    left, top, right, bottom = win32gui.GetWindowRect(hwnd)
    return "%d,%d" % (x - left, y - top)
Example #33
0
def mouse_get_y():
    return natlink.getCursorPos()[1]