def event_gainFocus(self): if mouseHandler.lastMouseEventTime < time.time() - 0.2: # This focus change was not caused by a mouse event. # If the mouse is on another toolbar control, the notification area toolbar will rudely # bounce the focus back to the object under the mouse after a brief pause. # Moving the mouse to the focus object isn't a good solution because # sometimes, the focus can't be moved away from the object under the mouse. # Therefore, move the mouse out of the way. winUser.setCursorPos(0, 0) if self.role == controlTypes.ROLE_TOOLBAR: # Sometimes, the toolbar itself receives the focus instead of the focused child. # However, the focused child still has the focused state. for child in self.children: if child.hasFocus: # Redirect the focus to the focused child. eventHandler.executeEvent("gainFocus", child) return # We've really landed on the toolbar itself. # This was probably caused by moving the mouse out of the way in a previous focus event. # This previous focus event is no longer useful, so cancel speech. speech.cancelSpeech() if eventHandler.isPendingEvents("gainFocus"): return super(NotificationArea, self).event_gainFocus()
def _activateNVDAObject(self, obj): while obj and obj != self.rootNVDAObject: try: obj.doAction() break except: log.debugWarning("doAction failed") if controlTypes.STATE_OFFSCREEN in obj.states or controlTypes.STATE_INVISIBLE in obj.states: obj = obj.parent continue try: l, t, w, h = obj.location except TypeError: log.debugWarning("No location for object") obj = obj.parent continue if not w or not h: obj = obj.parent continue log.debugWarning("Clicking with mouse") x = l + w / 2 y = t + h / 2 oldX, oldY = winUser.getCursorPos() winUser.setCursorPos(x, y) mouseHandler.executeMouseEvent(winUser.MOUSEEVENTF_LEFTDOWN, 0, 0) mouseHandler.executeMouseEvent(winUser.MOUSEEVENTF_LEFTUP, 0, 0) winUser.setCursorPos(oldX, oldY) break
def script_showSelectionOptions(self, gesture): fakeSel = self.selection if fakeSel.isCollapsed: # Double click to access the toolbar; e.g. for annotations. try: p = fakeSel.pointAtStart except NotImplementedError: log.debugWarning("Couldn't get point to click") return log.debug("Double clicking") winUser.setCursorPos(p.x, p.y) winUser.mouse_event(winUser.MOUSEEVENTF_LEFTDOWN, 0, 0, None, None) winUser.mouse_event(winUser.MOUSEEVENTF_LEFTUP, 0, 0, None, None) winUser.mouse_event(winUser.MOUSEEVENTF_LEFTDOWN, 0, 0, None, None) winUser.mouse_event(winUser.MOUSEEVENTF_LEFTUP, 0, 0, None, None) return # The user makes a selection using browse mode virtual selection. # Update the selection in Kindle. # This will cause the options to appear. fakeSel.innerTextInfo.updateSelection() # The selection might have been adjusted to meet word boundaries, # so retrieve and report the selection from Kindle. # we can't just use self.makeTextInfo, as that will use our fake selection. realSel = self.rootNVDAObject.makeTextInfo(textInfos.POSITION_SELECTION) # Translators: Announces selected text. %s is replaced with the text. speech.speakSelectionMessage(_("selected %s"), realSel.text) # Remove our virtual selection and move the caret to the active end. fakeSel.innerTextInfo = realSel fakeSel.collapse(end=not self._lastSelectionMovedStart) self.selection = fakeSel
def mouseEvents(location, *events): x,y = int (location[0]+location[2]/2), int (location[1]+location[3]/2) #move the cursor winUser.setCursorPos (x,y) #simulation of pressing mouse button for event in events: winUser.mouse_event(event, 0, 0, None, None)
def moveMouseToNVDAObject(obj): """Moves the mouse to the given NVDA object's position""" location=obj.location if location and (len(location)==4): (left,top,width,height)=location x=(left+left+width)/2 y=(top+top+height)/2 winUser.setCursorPos(x,y)
def showGui(self): # The menu pops up at the location of the mouse, which means it pops up at an unpredictable location. # Therefore, move the mouse to the centre of the screen so that the menu will always pop up there. left, top, width, height = api.getDesktopObject().location x = width / 2 y = height / 2 winUser.setCursorPos(x, y) self.sysTrayIcon.onActivate(None)
def _setCaretOffset(self,offset): rects=self._textAndRects[1] if offset>=len(rects): raise RuntimeError("offset %d out of range") left,top,right,bottom=rects[offset] x=left #+(right-left)/2 y=top+(bottom-top)/2 oldX,oldY=winUser.getCursorPos() winUser.setCursorPos(x,y) winUser.mouse_event(winUser.MOUSEEVENTF_LEFTDOWN,0,0,None,None) winUser.mouse_event(winUser.MOUSEEVENTF_LEFTUP,0,0,None,None) winUser.setCursorPos(oldX,oldY)
def _setCaretOffset(self,offset): rects=self._storyFieldsAndRects[1] if offset>=len(rects): raise RuntimeError("offset %d out of range") left,top,right,bottom=rects[offset] x=left #+(right-left)/2 y=top+(bottom-top)/2 x,y=windowUtils.logicalToPhysicalPoint(self.obj.windowHandle,x,y) oldX,oldY=winUser.getCursorPos() winUser.setCursorPos(x,y) winUser.mouse_event(winUser.MOUSEEVENTF_LEFTDOWN,0,0,None,None) winUser.mouse_event(winUser.MOUSEEVENTF_LEFTUP,0,0,None,None) winUser.setCursorPos(oldX,oldY)
def activate(self): """Activate this position. For example, this might activate the object at this position or click the point at this position. @raise NotImplementedError: If not supported. """ if not self.obj.isInForeground: raise NotImplementedError import winUser p=self.pointAtStart oldX,oldY=winUser.getCursorPos() winUser.setCursorPos(p.x,p.y) winUser.mouse_event(winUser.MOUSEEVENTF_LEFTDOWN,0,0,None,None) winUser.mouse_event(winUser.MOUSEEVENTF_LEFTUP,0,0,None,None) winUser.setCursorPos(oldX,oldY)
def doAction(self,index=None): if not index: l=self.location if l: x=l[0] y=l[1] oldX,oldY=winUser.getCursorPos() winUser.setCursorPos(x,y) mouseHandler.executeMouseEvent(winUser.MOUSEEVENTF_LEFTDOWN,0,0) time.sleep(0.2) mouseHandler.executeMouseEvent(winUser.MOUSEEVENTF_LEFTUP,0,0) winUser.setCursorPos(oldX,oldY) return raise NotImplementedError
def mouseMove(self): if not self.checkNodeManager(): return False self.moveto() info = self.getTextInfo() obj = info.NVDAObjectAtStart try: (left, top, width, height) = obj.location except: ui.message(u"Impossible de déplacer la souris à cet emplacement") return False x = left + (width / 2) y = top + (height / 2) winUser.setCursorPos(x, y) mouseHandler.executeMouseMoveEvent(x, y)
def activate(self): """Activate this position. For example, this might activate the object at this position or click the point at this position. @raise NotImplementedError: If not supported. """ if not self.obj.isInForeground: raise NotImplementedError import mouseHandler import winUser p = self.pointAtStart oldX, oldY = winUser.getCursorPos() winUser.setCursorPos(p.x, p.y) mouseHandler.executeMouseEvent(winUser.MOUSEEVENTF_LEFTDOWN, 0, 0) mouseHandler.executeMouseEvent(winUser.MOUSEEVENTF_LEFTUP, 0, 0) winUser.setCursorPos(oldX, oldY)
def _activateNVDAObject(self, obj): try: obj.doAction() return except: pass log.debugWarning("could not programmatically activate field, trying mouse") l=obj.location if not l: log.debugWarning("no location for field") return oldX,oldY=winUser.getCursorPos() winUser.setCursorPos(*l.center) mouseHandler.doPrimaryClick() winUser.setCursorPos(oldX,oldY)
def mouseMove(self): if not self.nodeManager.isReady: return False self.moveto() info = self.nodeManager.treeInterceptor.makeTextInfo( textInfos.offsets.Offsets(self.offset, self.offset)) obj = info.NVDAObjectAtStart try: (left, top, width, height) = obj.location except: ui.message(u"Impossible de déplacer la souris à cet emplacement") return False x = left + (width / 2) y = top + (height / 2) winUser.setCursorPos(x, y) mouseHandler.executeMouseMoveEvent(x, y)
def doAction(self, index=None): if not index: l = self.location if l: x = l[0] y = l[1] oldX, oldY = winUser.getCursorPos() winUser.setCursorPos(x, y) mouseHandler.executeMouseEvent(winUser.MOUSEEVENTF_LEFTDOWN, 0, 0) time.sleep(0.2) mouseHandler.executeMouseEvent(winUser.MOUSEEVENTF_LEFTUP, 0, 0) winUser.setCursorPos(oldX, oldY) return raise NotImplementedError
def _activateNVDAObject(self, obj): try: obj.doAction() except: log.debugWarning("could not programmatically activate field, trying mouse") l=obj.location if l: x=(l[0]+l[2]/2) y=l[1]+(l[3]/2) oldX,oldY=winUser.getCursorPos() winUser.setCursorPos(x,y) winUser.mouse_event(winUser.MOUSEEVENTF_LEFTDOWN,0,0,None,None) winUser.mouse_event(winUser.MOUSEEVENTF_LEFTUP,0,0,None,None) winUser.setCursorPos(oldX,oldY) else: log.debugWarning("no location for field")
def script_clickButtonCancel (self,gesture): # Translators: the title of the dropbox preferences dialog, it is important to have the same capitalization/spelling as in the dropbox gui. If Dropbox hasn't been translated to your language yet, leave this blank or write the original text. if api.getFocusObject().windowText == u'DropboxTrayIcon' or api.getFocusObject().windowClassName == u'#32768' or api.getForegroundObject().name != _("Dropbox Preferences"): gesture.send() return cancelButton=api.getForegroundObject().simpleLastChild # Translators: the name of the dropbox preferences cancel button, it is important to have the same capitalization/spelling as in the dropbox gui. If Dropbox hasn't been translated to your language yet, leave this blank or write the original text. if cancelButton.name != _('Cancel'): cancelButton=cancelButton.simplePrevious if cancelButton.simplePrevious.name == _('Cancel') else None if cancelButton == None: ui.message(_("Cancel button not found")) gesture.send() else: (x,y,l,h) = cancelButton.IAccessibleObject.accLocation (0) winUser.setCursorPos (x,y) winUser.mouse_event(winUser.MOUSEEVENTF_LEFTDOWN,0,0,None,None) winUser.mouse_event (winUser.MOUSEEVENTF_LEFTUP,0,0,None,None)
def rightMouseButton(o): """ make a right click @param o the object to click on""" # We get the object idea because we cannot act to the object dirrectly IDChild =o.IAccessibleChildID # We have to get the parent, this is a particularity. o=o.parent # We get the shild object location which has IDChild as id (x,y,l,h)=o.IAccessibleObject.accLocation(IDChild) #We calculate the center of the shild object x,y=int (x+l/2),int (y+h/2) # We move the cursor winUser.setCursorPos (x,y) # We make the right click event winUser.mouse_event(winUser.MOUSEEVENTF_RIGHTDOWN,0,0,None,None) # Then, the release button event winUser.mouse_event(winUser.MOUSEEVENTF_RIGHTUP,0,0,None,None)
def _activateNVDAObject(self, obj): try: obj.doAction() return except: pass log.debugWarning("could not programmatically activate field, trying mouse") l=obj.location if not l: log.debugWarning("no location for field") return oldX,oldY=winUser.getCursorPos() winUser.setCursorPos(*l.center) mouseHandler.executeMouseEvent(winUser.MOUSEEVENTF_LEFTDOWN,0,0) mouseHandler.executeMouseEvent(winUser.MOUSEEVENTF_LEFTUP,0,0) winUser.setCursorPos(oldX,oldY)
def _activateNVDAObject(self, obj): try: obj.doAction() except: log.debugWarning("could not programmatically activate field, trying mouse") while obj and controlTypes.STATE_OFFSCREEN in obj.states and obj!=self.rootNVDAObject: obj=obj.parent l=obj.location if l: x=(l[0]+l[2]/2) y=l[1]+(l[3]/2) oldX,oldY=winUser.getCursorPos() winUser.setCursorPos(x,y) winUser.mouse_event(winUser.MOUSEEVENTF_LEFTDOWN,0,0,None,None) winUser.mouse_event(winUser.MOUSEEVENTF_LEFTUP,0,0,None,None) winUser.setCursorPos(oldX,oldY) else: log.debugWarning("no location for field")
def _setCaretOffset(self, offset): rects = self._storyFieldsAndRects[1] if offset >= len(rects): raise RuntimeError("offset %d out of range") rect = rects[offset] # Place the cursor at the left coordinate of the character, vertically centered. point = Point(rect.left, rect.center.y) try: point = point.toPhysical(self.obj.windowHandle) except RuntimeError: raise RuntimeError( "Conversion to physical coordinates failed when setting caret offset" ) oldX, oldY = winUser.getCursorPos() winUser.setCursorPos(*point) mouseHandler.executeMouseEvent(winUser.MOUSEEVENTF_LEFTDOWN, 0, 0) mouseHandler.executeMouseEvent(winUser.MOUSEEVENTF_LEFTUP, 0, 0) winUser.setCursorPos(oldX, oldY)
def _activateNVDAObject(self, obj): try: obj.doAction() return except: pass log.debugWarning("could not programmatically activate field, trying mouse") l=obj.location if not l: log.debugWarning("no location for field") return x=(l[0]+l[2]/2) y=l[1]+(l[3]/2) oldX,oldY=winUser.getCursorPos() winUser.setCursorPos(x,y) winUser.mouse_event(winUser.MOUSEEVENTF_LEFTDOWN,0,0,None,None) winUser.mouse_event(winUser.MOUSEEVENTF_LEFTUP,0,0,None,None) winUser.setCursorPos(oldX,oldY)
def script_doAction(self, gesture): obj = api.getNavigatorObject() if obj.parent == self: if obj.actionCount > 0: x = int(obj.location.left + obj.location.width / 2) y = int(obj.location.top + obj.location.height / 2) winUser.setCursorPos(x, y) if api.getDesktopObject().objectFromPoint(x, y) == obj: if winUser.getKeyState(winUser.VK_LBUTTON) & 32768: winUser.mouse_event(winUser.MOUSEEVENTF_LEFTUP, 0, 0, None, None) winUser.mouse_event(winUser.MOUSEEVENTF_LEFTDOWN, 0, 1, None, None) winUser.mouse_event(winUser.MOUSEEVENTF_LEFTUP, 0, 0, None, None) else: scriptHandler.executeScript(self.script_menu, None) else: beep(200, 80)
def script_moveMouseToNavigatorObject(self,gesture): obj=api.getNavigatorObject() try: p=api.getReviewPosition().pointAtStart except (NotImplementedError, LookupError): p=None if p: x=p.x y=p.y else: try: (left,top,width,height)=obj.location except: ui.message(_("object has no location")) return x=left+(width/2) y=top+(height/2) winUser.setCursorPos(x,y) mouseHandler.executeMouseMoveEvent(x,y)
def _activateNVDAObject(self, obj): try: obj.doAction() return except: pass log.debugWarning("could not programmatically activate field, trying mouse") l=obj.location if not l: log.debugWarning("no location for field") return x=(l[0]+l[2]/2) y=l[1]+(l[3]/2) oldX,oldY=winUser.getCursorPos() winUser.setCursorPos(x,y) mouseHandler.executeMouseEvent(winUser.MOUSEEVENTF_LEFTDOWN,0,0) mouseHandler.executeMouseEvent(winUser.MOUSEEVENTF_LEFTUP,0,0) winUser.setCursorPos(oldX,oldY)
def script_clickPinConsoleButton(self, gesture): self.get_pin_console_button() if self.pinConsoleButton != None: try: oldX, oldY = winUser.getCursorPos() winUser.setCursorPos(self.pinConsoleButton.location.left, self.pinConsoleButton.location.top) #perform Mouse Left-Click mouseHandler.executeMouseEvent(winUser.MOUSEEVENTF_LEFTDOWN, 0, 0) mouseHandler.executeMouseEvent(winUser.MOUSEEVENTF_LEFTUP, 0, 0) winUser.setCursorPos(oldX, oldY) if controlTypes.State.CHECKED in self.pinConsoleButton.states: ui.message(_("Pin Console") + " " + _("not checked")) else: ui.message(_("Pin Console") + " " + _("checked")) except: pass
def _activateNVDAObject(self, obj): while obj and obj != self.rootNVDAObject: try: obj.doAction() break except: log.debugWarning("doAction failed") if obj.hasIrrelevantLocation: # This check covers invisible, off screen and a None location log.debugWarning("No relevant location for object") obj = obj.parent continue location = obj.location if not location.width or not location.height: obj = obj.parent continue log.debugWarning("Clicking with mouse") oldX, oldY = winUser.getCursorPos() winUser.setCursorPos(*location.center) mouseHandler.doPrimaryClick() winUser.setCursorPos(oldX, oldY) break
def changePageTab (h,sens): """ Change the active tab @param h the handle of tab page @param sens : string, next or prior """ #index =getPageTabActive ()[-1] index=listPageTab.index(getPageTabActive(h)) if sens =="next": index+=1 else: index-=1 index %= len(listPageTab) (x, y, l, h) = NVDAObjects.IAccessible.getNVDAObjectFromEvent(h,-4,0).location x=x+(1,3,5,7,9)[index]*l/10 y=y+h/2 winUser.setCursorPos (x,y) winUser.mouse_event(winUser.MOUSEEVENTF_LEFTDOWN,0,0,None,None) winUser.mouse_event (winUser.MOUSEEVENTF_LEFTUP,0,0,None,None) #announces the new tab ui.message(listPageTab[index])
def script_touch_rightClick(self, gesture): self.etsDebugOutput("etouch: attempting to perform right-click") obj=api.getNavigatorObject() try: p=api.getReviewPosition().pointAtStart except (NotImplementedError, LookupError): p=None if p: x=p.x y=p.y else: try: (left,top,width,height)=obj.location except: # Translators: Reported when the object has no location for the mouse to move to it. ui.message(_("object has no location")) return x=left+(width/2) y=top+(height/2) self.etsDebugOutput("etouch: mouse point found at %s, %s"%(x, y)) winUser.setCursorPos(x,y) winUser.mouse_event(winUser.MOUSEEVENTF_RIGHTDOWN,0,0,None,None) winUser.mouse_event(winUser.MOUSEEVENTF_RIGHTUP,0,0,None,None)
def callback(column): speech.cancelSpeech() comboBox = self._getSearchEditComboBoxObject() api.setNavigatorObject(comboBox) review.setCurrentMode("screen", updateReviewPosition=True) info = api.getReviewPosition().copy() info.collapse() info.expand(textInfos.UNIT_LINE) baseInfo = info.copy() info.collapse(True) api.setReviewPosition(info) curObject = api.getNavigatorObject() if curObject.role == ROLE_LISTITEM: info = baseInfo.copy() info.collapse() api.setReviewPosition(info) curObject = api.getNavigatorObject() columnHeaders = curObject.parent.children columnObj = columnHeaders[column - 1] if columnObj is None: log.error("Cannot found stations list column object:%s" % column) return name = columnObj.name[1:] if columnObj.name[ 0] == "*" else columnObj.name ui.message(name) time.sleep(0.5) location = columnObj.location (l, t, w, h) = location i = int(l + w - 10) j = int(t + h / 2) import winUser winUser.setCursorPos(i, j) winUser.mouse_event(winUser.MOUSEEVENTF_RIGHTDOWN, 0, 0, None, None) winUser.mouse_event(winUser.MOUSEEVENTF_RIGHTUP, 0, 0, None, None)
def leftClick(x, y): winUser.setCursorPos(x, y) winUser.mouse_event(winUser.MOUSEEVENTF_LEFTDOWN, 0, 0, None, None) winUser.mouse_event(winUser.MOUSEEVENTF_LEFTUP, 0, 0, None, None)
def moveMouseToNVDAObject(obj): """Moves the mouse to the given NVDA object's position""" location = obj.location if location: winUser.setCursorPos(*location.center)
def jumpToTime(self, jumpTime, totalTime, startPlaying=False): printDebug("MainWindow: jumpToTime") mainWindow = self speech.cancelSpeech() oldSpeechMode = getSpeechMode() setSpeechMode_off() api.processPendingEvents() speech.cancelSpeech() if jumpTime is None or jumpTime == 0: setSpeechMode(oldSpeechMode) # Translators: message to the user to report no time change. queueHandler.queueFunction(queueHandler.eventQueue, speech.speakMessage, _("No change")) queueHandler.queueFunction(queueHandler.eventQueue, mainWindow.sayElapsedTime, True) queueHandler.queueFunction(queueHandler.eventQueue, mainWindow.reportMediaStates) return isPlaying = mainWindow.isPlaying() curTimeInSec = getTimeInSec(mainWindow.getCurrentTime()) if type(jumpTime) is int: jumpTimeInSec = jumpTime else: jumpTimeInSec = getTimeInSec(jumpTime) if abs(curTimeInSec - jumpTimeInSec) <= 2: # we are at time setSpeechMode(oldSpeechMode) queueHandler.queueFunction(queueHandler.eventQueue, mainWindow.sayElapsedTime) queueHandler.queueFunction(queueHandler.eventQueue, mainWindow.reportMediaStates) if not isPlaying and startPlaying: mainWindow.togglePlayOrPause() return if isPlaying: # pause playing mainWindow.togglePlayOrPause() time.sleep(0.2) totalTimeInSec = getTimeInSec(totalTime) (x, y) = self.calculatePosition(jumpTimeInSec, totalTimeInSec, isPlaying) leftClick(int(x), int(y)) api.processPendingEvents() time.sleep(0.2) winUser.setCursorPos(int(x), int(y - 20)) mouseHandler.executeMouseMoveEvent(x, y) speech.cancelSpeech() setSpeechMode(oldSpeechMode) # wait for new time api.processPendingEvents() i = 20 newCurTimeInSec = getTimeInSec(mainWindow.getCurrentTime()) while i > 0 and newCurTimeInSec == curTimeInSec: time.sleep(0.05) i = i - 1 if i == 0: # time out # Translators: message to the user to say that jump is not possible. queueHandler.queueFunction(queueHandler.eventQueue, speech.speakMessage, _("Jump is not possible")) queueHandler.queueFunction(queueHandler.eventQueue, mainWindow.sayElapsedTime) queueHandler.queueFunction(queueHandler.eventQueue, mainWindow.reportMediaStates) printDebug("MainWindow: jump is not completed") return newCurTimeInSec = getTimeInSec(mainWindow.getCurrentTime()) if newCurTimeInSec != jumpTimeInSec: self.adjustPosition(jumpTimeInSec, totalTimeInSec, x, y) if not startPlaying and isPlaying: mainWindow.togglePlayOrPause() queueHandler.queueFunction(queueHandler.eventQueue, mainWindow.reportMediaStates) return queueHandler.queueFunction(queueHandler.eventQueue, mainWindow.sayElapsedTime) if startPlaying: mainWindow.togglePlayOrPause() queueHandler.queueFunction(queueHandler.eventQueue, mainWindow.reportMediaStates)