Пример #1
0
 def script_mouseCursorInfo(self, gesture):
     if scriptHandler.getLastScriptRepeatCount() == 2:
         ui.message(
             _("Window in %d, %d. Width %d, height %d") %
             api.getForegroundObject().location)
         return
     if scriptHandler.getLastScriptRepeatCount() == 1:
         if not self.objectToDrag:
             ui.message(_("without selection for drag and drop"))
             return
         speech.speakObject(self.objectToDrag,
                            reason=controlTypes.REASON_MOUSE)
         ui.message(_(" marked for drag and drop"))
         x, y = self.dragFromPosition
         if api.getDesktopObject().objectFromPoint(x,
                                                   y) != self.objectToDrag:
             ui.message(_("(inaccessible from here)"))
         return
     fg = api.getForegroundObject()
     x, y = win32api.GetCursorPos()
     ui.message(_("Mouse cursor is on %d, %d above ") % (x, y))
     mouse = api.getDesktopObject().objectFromPoint(x, y)
     speech.speakObject(mouse, reason=controlTypes.REASON_MOUSE)
     if fg.appModule.appModuleName != mouse.appModule.appModuleName:
         ui.message(_("(outside of the active window)"))
     if winUser.getKeyState(winUser.VK_LBUTTON) & 32768:
         ui.message(_("Left button locked"))
     if winUser.getKeyState(winUser.VK_RBUTTON) & 32768:
         ui.message(_("Right button locked"))
     ui.message(_("%s cursor") % mouseHandler.curMouseShape)
Пример #2
0
	def send(self):
		keys = []
		for vk, ext in self.generalizedModifiers:
			if vk == VK_WIN:
				if winUser.getKeyState(winUser.VK_LWIN) & 32768 or winUser.getKeyState(winUser.VK_RWIN) & 32768:
					# Already down.
					continue
				vk = winUser.VK_LWIN
			elif winUser.getKeyState(vk) & 32768:
				# Already down.
				continue
			keys.append((vk, ext))
		keys.append((self.vkCode, self.isExtended))

		if winUser.getKeyState(self.vkCode) & 32768:
			# This key is already down, so send a key up for it first.
			winUser.keybd_event(self.vkCode, 0, self.isExtended + 2, 0)

		# Send key down events for these keys.
		for vk, ext in keys:
			winUser.keybd_event(vk, 0, ext, 0)
		# Send key up events for the keys in reverse order.
		for vk, ext in reversed(keys):
			winUser.keybd_event(vk, 0, ext + 2, 0)

		if not queueHandler.isPendingItems(queueHandler.eventQueue):
			time.sleep(0.01)
			wx.Yield()
Пример #3
0
    def send(self):
        keys = []
        for vk, ext in self.generalizedModifiers:
            if vk == VK_WIN:
                if winUser.getKeyState(
                        winUser.VK_LWIN) & 32768 or winUser.getKeyState(
                            winUser.VK_RWIN) & 32768:
                    # Already down.
                    continue
                vk = winUser.VK_LWIN
            elif winUser.getKeyState(vk) & 32768:
                # Already down.
                continue
            keys.append((vk, 0, ext))
        keys.append((self.vkCode, self.scanCode, self.isExtended))

        with ignoreInjection():
            if winUser.getKeyState(self.vkCode) & 32768:
                # This key is already down, so send a key up for it first.
                winUser.keybd_event(self.vkCode, self.scanCode,
                                    self.isExtended + 2, 0)

            # Send key down events for these keys.
            for vk, scan, ext in keys:
                winUser.keybd_event(vk, scan, ext, 0)
            # Send key up events for the keys in reverse order.
            for vk, scan, ext in reversed(keys):
                winUser.keybd_event(vk, scan, ext + 2, 0)

            if not queueHandler.isPendingItems(queueHandler.eventQueue):
                # We want to guarantee that by the time that
                # this function returns,the keyboard input generated
                # has been injected and NVDA has received and processed it.
                time.sleep(0.01)
                wx.Yield()
Пример #4
0
	def send(self):
		global ignoreInjected
		keys = []
		for vk, ext in self.generalizedModifiers:
			if vk == VK_WIN:
				if winUser.getKeyState(winUser.VK_LWIN) & 32768 or winUser.getKeyState(winUser.VK_RWIN) & 32768:
					# Already down.
					continue
				vk = winUser.VK_LWIN
			elif winUser.getKeyState(vk) & 32768:
				# Already down.
				continue
			keys.append((vk, 0, ext))
		keys.append((self.vkCode, self.scanCode, self.isExtended))

		try:
			ignoreInjected=True
			if winUser.getKeyState(self.vkCode) & 32768:
				# This key is already down, so send a key up for it first.
				winUser.keybd_event(self.vkCode, self.scanCode, self.isExtended + 2, 0)

			# Send key down events for these keys.
			for vk, scan, ext in keys:
				winUser.keybd_event(vk, scan, ext, 0)
			# Send key up events for the keys in reverse order.
			for vk, scan, ext in reversed(keys):
				winUser.keybd_event(vk, scan, ext + 2, 0)

			if not queueHandler.isPendingItems(queueHandler.eventQueue):
				time.sleep(0.01)
				wx.Yield()
		finally:
			ignoreInjected=False
Пример #5
0
	def script_toggleRightMouseButton(self,gesture):
		if winUser.getKeyState(winUser.VK_RBUTTON)&32768:
			ui.message(_("right mouse button unlock"))
			winUser.mouse_event(winUser.MOUSEEVENTF_RIGHTUP,0,0,None,None)
		else:
			ui.message(_("right mouse button lock"))
			winUser.mouse_event(winUser.MOUSEEVENTF_RIGHTDOWN,0,0,None,None)
Пример #6
0
    def __init__(self):
        global speakers
        speakers = getVolumeObject()
        super(globalPluginHandler.GlobalPlugin, self).__init__()
        volLevel = config.conf["sharedComputer"]["volumeLevel"]
        volMode = config.conf["sharedComputer"]["volumeCorrectionChoice"]
        if volMode < 2:
            wx.CallAfter(self.changeVolumeLevel, volLevel, volMode)
        self.numLockState = winUser.getKeyState(winUser.VK_NUMLOCK)
        self.handleConfigProfileSwitch()
        try:
            config.configProfileSwitched.register(
                self.handleConfigProfileSwitch)
        except AttributeError:
            pass

        # Gui
        self.prefsMenu = gui.mainFrame.sysTrayIcon.preferencesMenu
        self.settingsItem = self.prefsMenu.Append(
            wx.ID_ANY,
            # Translators: name of the entry in the preferences menu.
            _("Shared Comp&uter..."))
        gui.mainFrame.sysTrayIcon.Bind(wx.EVT_MENU, self.onSettings,
                                       self.settingsItem)
        # first installation: open dialog automatically
        if not config.conf["sharedComputer"].isSet("volumeCorrectionChoice"):
            wx.CallAfter(self.onSettings, None)
Пример #7
0
 def dragAndDrop(self, hIndex1, hIndex2):
     if self.columns[0].windowText != self.folder:
         #TRANSLATORS: the folder content has changed while this dialog was opened
         ui.message(
             _("Folder has changed, return to %s to manage columns or restart this dialog"
               ) % self.folder[:-22])
         return False
     self.Hide()
     try:
         x = self.columns[hIndex1].location[
             0] + self.columns[hIndex1].location[2] / 2
         y = self.columns[hIndex1].location[
             1] + self.columns[hIndex1].location[3] / 2
     except TypeError:
         return False
     if api.getDesktopObject().objectFromPoint(x,
                                               y) != self.columns[hIndex1]:
         return False
     winUser.setCursorPos(x, y)
     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)
     x = self.columns[hIndex2].location[0] + self.columns[hIndex2].location[
         2] + 1
     y = self.columns[hIndex2].location[
         1] + self.columns[hIndex2].location[3] / 2
     winUser.setCursorPos(x, y)
     winUser.mouse_event(winUser.MOUSEEVENTF_LEFTUP, 0, 0, None, None)
     tmp = self.columns[hIndex1]
     self.columns[hIndex1] = self.columns[hIndex2]
     self.columns[hIndex2] = tmp
     self.update()
     return True
Пример #8
0
 def event_gainFocus(self):
     if winUser.getKeyState(
             KeyboardInputGesture.fromName("Control").vkCode) in (0, 1):
         try:
             self.states.remove(controlTypes.STATE_SELECTED)
         except KeyError:
             pass
     if not self.name:
         self.name = " "
     self.reportHeaders = config.conf['documentFormatting'][
         'reportTableHeaders']
     if versionInfo.version_year * 100 + versionInfo.version_major >= 201802:
         config.conf['documentFormatting'][
             'reportTableHeaders'] = True if config.conf['calibre'][
                 'reportTableHeaders'] == "st" else False
     if self.columnHeaderText and (
         (versionInfo.version_year * 100 + versionInfo.version_major <
          201802
          and config.conf['documentFormatting']['reportTableHeaders']) or
         (versionInfo.version_year * 100 + versionInfo.version_major >=
          201802 and config.conf['calibre']['reportTableHeaders'] == "cl")):
         # Reporting table headers at classic style (used in previous versions of NVDA or in new versions if read only column headers is selected in preferences)
         if not self.inTitleColumn and not self.inAuthorColumn:
             self.description = self.columnHeaderText
     speakObject(self, controlTypes.REASON_CARET)
     braille.handler.handleGainFocus(self)
Пример #9
0
 def dragAndDrop(self, drop_x, drop_y):
     self.kbFinish()
     x, y = self.dragFromPosition
     if api.getDesktopObject().objectFromPoint(x, y) != self.objectToDrag:
         self.error(_("Cannot find the object marked."))
         return
     win32api.SetCursorPos((x, y))
     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)
     ui.message(_("click in %d, %d") % win32api.GetCursorPos())
     sleep(1.0)
     ui.message(_("dragging"))
     sleep(0.5)
     win32api.SetCursorPos((drop_x, drop_y))
     obj = api.getDesktopObject().objectFromPoint(drop_x, drop_y)
     ui.message(_("moved to %d, %d") % win32api.GetCursorPos())
     sleep(0.5)
     winUser.mouse_event(winUser.MOUSEEVENTF_LEFTUP, 0, 0, None, None)
     sleep(1.0)
     x, y = self.dragFromPosition
     if api.getDesktopObject().objectFromPoint(x, y) != self.objectToDrag:
         ui.message(_("dropped on "))
         speech.speakObject(obj, reason=controlTypes.REASON_MOUSE)
     else:
         tones.beep(500, 100)
     self.objectToDrag = None
Пример #10
0
    def asyncSwitchWindowHandler(self, thisGestureCounter):
        global gestureCounter
        timeout = time.time() + 2
        yield 1
        # step 1. wait for all modifiers to be released
        while True:
            if time.time() > timeout:
                return
            if gestureCounter != thisGestureCounter:
                return
            status = [winUser.getKeyState(k) & 32768 for k in allModifiers]
            if not any(status):
                break
            yield 1

    # Step 2
    #for i in range(100):
        yield 50
        if gestureCounter != thisGestureCounter:
            return
        if True:
            focus = api.getFocusObject()
            if focus.appModule.appName == "explorer":
                if focus.windowClassName == "TaskListThumbnailWnd":
                    kbdEnter = keyboardHandler.KeyboardInputGesture.fromName(
                        "Enter")
                    kbdEnter.send()
                    tones.beep(100, 20)
                    return
Пример #11
0
 def event_typedCharacter(self, ch):
     speech.speakTypedCharacters(ch)
     import winUser
     if config.conf["keyboard"][
             "beepForLowercaseWithCapslock"] and ch.islower(
             ) and winUser.getKeyState(winUser.VK_CAPITAL) & 1:
         import tones
         tones.beep(3000, 40)
Пример #12
0
def _reportToggleKey(self):
    if winUser.getKeyState(self.vkCode) & 1:
        beep(config.conf['beepKeyboard']['toggleOnTone'])
    else:
        beep(config.conf['beepKeyboard']['toggleOffTone'])
    if config.conf['beepKeyboard']['announceToggleStatus'] or (
            config.conf['beepKeyboard']['disableBeepingOnPasswordFields']
            and api.getFocusObject().isProtected):
        origReportToggleKey(self)
Пример #13
0
 def event_typedCharacter(self, obj, nextHandler, ch):
     nextHandler()
     if config.conf['beepKeyboard'][
             'beepUpperWithCapsLock'] and winUser.getKeyState(
                 winUser.VK_CAPITAL) & 1 and ch.isupper():
         beep(config.conf['beepKeyboard']['capsLockUpperTone'])
     elif config.conf['beepKeyboard'][
             'beepCharacterWithShift'] and not winUser.getKeyState(
                 winUser.VK_CONTROL
             ) & 32768 and winUser.getKeyState(
                 winUser.VK_SHIFT
             ) & 32768 and ch not in self.ignoredCharactersForShift and not (
                 config.conf["keyboard"]["beepForLowercaseWithCapslock"]
                 and ch.islower()
                 and winUser.getKeyState(winUser.VK_CAPITAL) & 1):
         beep(config.conf['beepKeyboard']['shiftedCharactersTone'])
     elif ch in self.beepForCharacters:
         beep(config.conf['beepKeyboard']['customCharactersTone'])
Пример #14
0
	def terminate(self):
		if winUser.getKeyState(winUser.VK_NUMLOCK) != self.numLockState:
			KeyboardInputGesture.fromName("numLock").send()
		try:
			config.configProfileSwitched.unregister(self.handleConfigProfileSwitch)
		except AttributeError: # This is for backward compatibility
			pass
		try:
			self.prefsMenu.RemoveItem(self.settingsItem)
		except: # Compatible with Python 2 and 3
			pass
Пример #15
0
	def event_typedCharacter(self,ch):
		if config.conf["documentFormatting"]["reportSpellingErrors"] and config.conf["keyboard"]["alertForSpellingErrors"] and (
			# Not alpha, apostrophe or control.
			ch.isspace() or (ch >= u" " and ch not in u"'\x7f" and not ch.isalpha())
		):
			# Reporting of spelling errors is enabled and this character ends a word.
			self._reportErrorInPreviousWord()
		speech.speakTypedCharacters(ch)
		import winUser
		if config.conf["keyboard"]["beepForLowercaseWithCapslock"] and ch.islower() and winUser.getKeyState(winUser.VK_CAPITAL)&1:
			import tones
			tones.beep(3000,40)
Пример #16
0
	def event_typedCharacter(self,ch):
		if config.conf["documentFormatting"]["reportSpellingErrors"] and config.conf["keyboard"]["alertForSpellingErrors"] and (
			# Not alpha, apostrophe or control.
			ch.isspace() or (ch >= u" " and ch not in u"'\x7f" and not ch.isalpha())
		):
			# Reporting of spelling errors is enabled and this character ends a word.
			self._reportErrorInPreviousWord()
		speech.speakTypedCharacters(ch)
		import winUser
		if config.conf["keyboard"]["beepForLowercaseWithCapslock"] and ch.islower() and winUser.getKeyState(winUser.VK_CAPITAL)&1:
			import tones
			tones.beep(3000,40)
Пример #17
0
    def event_typedCharacter(self, ch):
        speech.speakTypedCharacters(ch)
        import winUser

        if (
            config.conf["keyboard"]["beepForLowercaseWithCapslock"]
            and ch.islower()
            and winUser.getKeyState(winUser.VK_CAPITAL) & 1
        ):
            import tones

            tones.beep(3000, 40)
Пример #18
0
 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)
Пример #19
0
 def __init__(self, modifiers, vkCode, scanCode, isExtended):
     #: The keyboard layout in which this gesture was created.
     #: @type: str
     self.layout = config.conf["keyboard"]["keyboardLayout"]
     self.modifiers = modifiers = set(modifiers)
     # Don't double up if this is a modifier key repeat.
     modifiers.discard((vkCode, isExtended))
     if vkCode in (winUser.VK_DIVIDE, winUser.VK_MULTIPLY,
                   winUser.VK_SUBTRACT, winUser.VK_ADD
                   ) and winUser.getKeyState(winUser.VK_NUMLOCK) & 1:
         # Some numpad keys have the same vkCode regardless of numlock.
         # For these keys, treat numlock as a modifier.
         modifiers.add((winUser.VK_NUMLOCK, False))
     self.generalizedModifiers = set(
         (self.NORMAL_MODIFIER_KEYS.get(mod) or mod, extended)
         for mod, extended in modifiers)
     self.vkCode = vkCode
     self.scanCode = scanCode
     self.isExtended = isExtended
     super(KeyboardInputGesture, self).__init__()
Пример #20
0
def _translate(self, endWord):
    """Translate buffered braille up to the cursor.
	Any text produced is sent to the system.
	@param endWord: C{True} if this is the end of a word, C{False} otherwise.
	@type endWord: bool
	@return: C{True} if translation produced text, C{False} if not.
	@rtype: bool
	"""
    assert not self.useContractedForCurrentFocus or endWord, "Must only translate contracted at end of word"
    if self.useContractedForCurrentFocus:
        # self.bufferText has been used by _reportContractedCell, so clear it.
        self.bufferText = ""
    oldTextLen = len(self.bufferText)
    pos = self.untranslatedStart + self.untranslatedCursorPos
    data = "".join([
        chr(cell | brailleInput.LOUIS_DOTS_IO_START)
        for cell in self.bufferBraille[:pos]
    ])
    mode = louis.dotsIO | louis.noUndefinedDots
    if (not self.currentFocusIsTextObj
            or self.currentModifiers) and self._table.contracted:
        mode |= louis.partialTrans
    self.bufferText = louis.backTranslate(getCurrentBrailleTables(
        True, brf=instanceGP.BRFMode),
                                          data,
                                          mode=mode)[0]
    newText = self.bufferText[oldTextLen:]
    if newText:
        # New text was generated by the cells just entered.
        if self.useContractedForCurrentFocus or self.currentModifiers:
            # For contracted braille, an entire word is sent at once.
            # Don't speak characters as this is sent.
            # Also, suppress typed characters when emulating a command gesture.
            speech._suppressSpeakTypedCharacters(len(newText))
        else:
            self._uncontSentTime = time.time()
        self.untranslatedStart = pos
        self.untranslatedCursorPos = 0
        if self.currentModifiers or not self.currentFocusIsTextObj:
            if len(newText) > 1:
                # Emulation of multiple characters at once is unsupported
                # Clear newText, so this function returns C{False} if not at end of word
                newText = ""
            else:
                self.emulateKey(newText)
        else:
            if config.conf["brailleExtender"][
                    "smartCapsLock"] and winUser.getKeyState(
                        winUser.VK_CAPITAL) & 1:
                tmp = []
                for ch in newText:
                    if ch.islower():
                        tmp.append(ch.upper())
                    else:
                        tmp.append(ch.lower())
                newText = ''.join(tmp)
            self.sendChars(newText)

    if endWord or (newText and
                   (not self.currentFocusIsTextObj or self.currentModifiers)):
        # We only need to buffer one word.
        # Clear the previous word (anything before the cursor) from the buffer.
        del self.bufferBraille[:pos]
        self.bufferText = ""
        self.cellsWithText.clear()
        if not instanceGP.modifiersLocked:
            self.currentModifiers.clear()
            instanceGP.clearMessageFlash()
        self.untranslatedStart = 0
        self.untranslatedCursorPos = 0

    if newText or endWord:
        self._updateUntranslated()
        return True

    return False
Пример #21
0
def isLeftMouseButtonLocked():
    """ Tests if the left mouse button is locked """
    return winUser.getKeyState(winUser.VK_LBUTTON) & 1 << 15
Пример #22
0
	def handleConfigProfileSwitch(self):
		activation = config.conf["sharedComputer"]["numLockActivationChoice"]
		if activation < 2 and winUser.getKeyState(winUser.VK_NUMLOCK) != activation:
			KeyboardInputGesture.fromName("numLock").send()
Пример #23
0
def isRightMouseButtonLocked():
    """ Tests if the right mouse button is locked """
    return winUser.getKeyState(winUser.VK_RBUTTON) & 1 << 15
Пример #24
0
 def _reportToggleKey(self):
     toggleState = winUser.getKeyState(self.vkCode) & 1
     key = self.mainKeyName
     ui.message(u"{key} {state}".format(
         key=localizedKeyLabels.get(key.lower(), key),
         state=_("on") if toggleState else _("off")))
Пример #25
0
	def __init__(self, modifiers, vkCode, scanCode, isExtended):
		#: The keyboard layout in which this gesture was created.
		#: @type: str
		self.layout = config.conf["keyboard"]["keyboardLayout"]
		self.modifiers = modifiers = set(modifiers)
		if vkCode in (winUser.VK_DIVIDE, winUser.VK_MULTIPLY, winUser.VK_SUBTRACT, winUser.VK_ADD) and winUser.getKeyState(winUser.VK_NUMLOCK) & 1:
			# Some numpad keys have the same vkCode regardless of numlock.
			# For these keys, treat numlock as a modifier.
			modifiers.add((winUser.VK_NUMLOCK, False))
		self.generalizedModifiers = set((self.NORMAL_MODIFIER_KEYS.get(mod) or mod, extended) for mod, extended in modifiers)
		self.vkCode = vkCode
		self.scanCode = scanCode
		self.isExtended = isExtended
		super(KeyboardInputGesture, self).__init__()
Пример #26
0
	def _reportToggleKey(self):
		toggleState = winUser.getKeyState(self.vkCode) & 1
		key = self.mainKeyName
		ui.message(u"{key} {state}".format(
			key=localizedKeyLabels.get(key, key),
			state=_("on") if toggleState else _("off")))