Changeset 2429

Show
Ignore:
Timestamp:
10/12/08 08:55:18 (6 weeks ago)
Author:
pvagner
Message:

* some enhancements for keyboard support by Aleksey:
* While the keyboard help is turned on NVDA can speak all the keys including the key modifiers.
* Tweaked anouncing of the scripts description while the keyboard help is turned on.
* added ability to translate keynames.

Location:
trunk/source
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/source/keyUtils.py

    r2177 r2429  
    107107                time.sleep(0.01) 
    108108                wx.Yield() 
     109 
     110localizedKeyLabels={ 
     111        'back': _("backspace"), 
     112        'capital': _("caps lock"), 
     113        'control': _("ctrl"), 
     114        'alt': _("alt"), 
     115        'shift': _("shift"), 
     116        'win': _("windows"), 
     117        'return': _("enter"), 
     118        'extendedreturn': _("numpad enter"), 
     119        'escape': _("escape"), 
     120        'space': _("space"), 
     121        'extendedprior': _("page up"), 
     122        'extendednext': _("page down"), 
     123        'extendedend': _("end"), 
     124        'extendedhome': _("home"), 
     125        'extendeddelete': _("delete"), 
     126        'extendedleft': _("left arrow"), 
     127        'extendedright': _("right arrow"), 
     128        'extendedup': _("up arrow"), 
     129        'extendeddown': _("down arrow"), 
     130        'extendedapps': _("applications"), 
     131        'extendednumlock': _("num lock"), 
     132        'extendedsnapshot': _("snapshot"), 
     133        'scroll': _("scrol lock"), 
     134        'left': _("numpad left"), 
     135        'right': _("numpad right"), 
     136        'up': _("numpad up"), 
     137        'down': _("numpad down"), 
     138        'prior': _("numpad page up"), 
     139        'next': _("numpad page down"), 
     140        'end': _("numpad end"), 
     141        'home': _("numpad home"), 
     142        'extendeddivide': _("numpad slash"), 
     143        'multiply': _("numpad star"), 
     144        'subtract': _("numpad minus"), 
     145        'add': _("numpad plus"), 
     146        'lcontrol': _("left control"), 
     147        'extendedrcontrol': _("right control"), 
     148        'extendedlwin': _("left windows"), 
     149        'lshift': _("left shift"), 
     150        'extendedrshift': _("right shift"), 
     151        'lmenu': _("left alt"), 
     152        'extendedrmenu': _("right alt"), 
     153        'extendedrwin': _("right windows") 
     154} 
  • trunk/source/keyboardHandler.py

    r2272 r2429  
    1313import vkCodes 
    1414import speech 
    15 from keyUtils import key, keyName, sendKey 
     15from keyUtils import key, keyName, sendKey, localizedKeyLabels 
    1616import scriptHandler 
    1717import globalVars 
     
    7878@ctypes.CFUNCTYPE(ctypes.c_int,ctypes.c_int,ctypes.c_int,ctypes.c_int,ctypes.c_int) 
    7979def internal_keyDownEvent(vkCode,scanCode,extended,injected): 
    80         """Event called by pyHook when it receives a keyDown. It sees if there is a script tied to this key and if so executes it. It also handles the speaking of characters, words and command keys. 
     80        """Event called by keyHook when it receives a keyDown. It sees if there is a script tied to this key and if so executes it. It also handles the speaking of characters, words and command keys. 
    8181""" 
    8282        try: 
     
    112112                if isNVDAModifierKey(vkCode,extended): 
    113113                        NVDAModifierKey=(vkCode,extended) 
    114                         return False 
    115                 if vkCode in [winUser.VK_CONTROL,winUser.VK_LCONTROL,winUser.VK_RCONTROL,winUser.VK_SHIFT,winUser.VK_LSHIFT,winUser.VK_RSHIFT,winUser.VK_MENU,winUser.VK_LMENU,winUser.VK_RMENU,winUser.VK_LWIN,winUser.VK_RWIN]: 
     114                        if not globalVars.keyboardHelp: 
     115                                return False 
     116                if not globalVars.keyboardHelp and vkCode in [winUser.VK_CONTROL,winUser.VK_LCONTROL,winUser.VK_RCONTROL,winUser.VK_SHIFT,winUser.VK_LSHIFT,winUser.VK_RSHIFT,winUser.VK_MENU,winUser.VK_LMENU,winUser.VK_RMENU,winUser.VK_LWIN,winUser.VK_RWIN]: 
    116117                        return True 
    117118                modifierList=[] 
    118119                if NVDAModifierKey: 
    119120                        modifierList.append("nvda") 
    120                 if winUser.getKeyState(winUser.VK_CONTROL)&32768: 
     121                if not vkCode in [winUser.VK_CONTROL,winUser.VK_LCONTROL,winUser.VK_RCONTROL] and winUser.getKeyState(winUser.VK_CONTROL)&32768: 
    121122                        modifierList.append("control") 
    122                 if winUser.getKeyState(winUser.VK_SHIFT)&32768: 
     123                if not vkCode in [winUser.VK_SHIFT,winUser.VK_LSHIFT,winUser.VK_RSHIFT] and winUser.getKeyState(winUser.VK_SHIFT)&32768: 
    123124                        modifierList.append("shift") 
    124                 if winUser.getKeyState(winUser.VK_MENU)&32768: 
     125                if not vkCode in [winUser.VK_MENU,winUser.VK_LMENU,winUser.VK_RMENU] and winUser.getKeyState(winUser.VK_MENU)&32768: 
    125126                        modifierList.append("alt") 
    126                 if winUser.getKeyState(winUser.VK_LWIN)&32768: 
     127                if not vkCode in [winUser.VK_LWIN,winUser.VK_RWIN] and winUser.getKeyState(winUser.VK_LWIN)&32768: 
    127128                        modifierList.append("win") 
    128                 if winUser.getKeyState(winUser.VK_RWIN)&32768: 
     129                if not vkCode in [winUser.VK_LWIN,winUser.VK_RWIN] and winUser.getKeyState(winUser.VK_RWIN)&32768: 
    129130                        modifierList.append("win") 
    130131                if len(modifierList) > 0: 
     
    133134                        modifiers=None 
    134135                mainKey=vkName 
     136                if not mainKey: 
     137                        mainKey=winUser.getKeyNameText(scanCode,extended) 
    135138                if extended==1: 
    136139                        mainKey="extended%s"%mainKey 
     
    138141                if log.isEnabledFor(log.IO): log.io("key press: %s"%keyName(keyPress)) 
    139142                if globalVars.keyboardHelp or (config.conf["keyboard"]["speakCommandKeys"] and not ( not keyPress[0] and config.conf["keyboard"]["speakTypedCharacters"])): 
    140                         labelList=[] 
    141                         if keyPress[0] is not None: 
    142                                 labelList.extend(keyPress[0]) 
    143                         ch=ctypes.windll.user32.MapVirtualKeyW(vkCode,winUser.MAPVK_VK_TO_CHAR) 
    144                         if ch>32: 
    145                                 labelList.append(unichr(ch)) 
    146                         else: 
    147                                 labelList.append(keyPress[1]) 
     143                        labelList = [] 
     144                        if modifiers: 
     145                                for mod in modifiers:  
     146                                        if localizedKeyLabels.has_key(mod):  
     147                                                labelList.append(localizedKeyLabels[mod])  
     148                                        else:  
     149                                                labelList.append(mod) 
     150                        if not isNVDAModifierKey(vkCode,extended): 
     151                                ch=ctypes.windll.user32.MapVirtualKeyW(vkCode,winUser.MAPVK_VK_TO_CHAR) 
     152                                if localizedKeyLabels.has_key(keyPress[1]): 
     153                                        labelList.append(localizedKeyLabels[keyPress[1]]) 
     154                                elif ch>=32 and not mainKey.startswith('numpad') and not mainKey in ('extendeddivide', 'multiply', 'subtract', 'add', 'extendedreturn', 'decimal'): 
     155                                        labelList.append(unichr(ch)) 
     156                                else: 
     157                                        labelList.append(keyPress[1]) 
    148158                        queueHandler.queueFunction(queueHandler.eventQueue,speech.speakMessage,"+".join(labelList)) 
    149                 if (mainKey in ('extendeddivide', 'multiply', 'subtract', 'add', 'extendedreturn')) and (bool(winUser.getKeyState(winUser.VK_NUMLOCK)&1)): 
     159                if not globalVars.keyboardHelp and (mainKey in ('extendeddivide', 'multiply', 'subtract', 'add', 'extendedreturn')) and (bool(winUser.getKeyState(winUser.VK_NUMLOCK)&1)): 
    150160                        return True 
    151161                script=scriptHandler.findScript(keyPress) 
    152162                if script: 
    153163                        scriptName=scriptHandler.getScriptName(script) 
    154                         scriptLocation=scriptHandler.getScriptLocation(script) 
    155                         scriptDescription=scriptHandler.getScriptDescription(script) 
    156164                        if globalVars.keyboardHelp and scriptName!="keyboardHelp": 
    157                                 queueHandler.queueFunction(queueHandler.eventQueue,speech.speakMessage,"%s"%scriptName.replace('_',' ')) 
    158                                 queueHandler.queueFunction(queueHandler.eventQueue,speech.speakMessage,_("Description: %s")%scriptDescription) 
    159                                 queueHandler.queueFunction(queueHandler.eventQueue,speech.speakMessage,_("Location: %s")%scriptLocation) 
     165                                scriptDescription = scriptHandler.getScriptDescription(script) 
     166                                if scriptDescription: queueHandler.queueFunction(queueHandler.eventQueue,speech.speakMessage,_("Description: %s")%scriptDescription) 
     167                                queueHandler.queueFunction(queueHandler.eventQueue,speech.speakMessage,_("Location: %s")%scriptHandler.getScriptLocation(script)) 
    160168                        else: 
    161169                                scriptHandler.queueScript(script,keyPress) 
  • trunk/source/winUser.py

    r2177 r2429  
    7474WM_GETTEXT=13 
    7575WM_GETTEXTLENGTH=14 
     76WM_PAINT=0x000F 
    7677#Clipboard formats 
    7778CF_TEXT=1 
     
    377378def getKeyboardLayout(idThread=0): 
    378379        return user32.GetKeyboardLayout(idThread) 
     380 
     381def updateWindow(hwnd): 
     382        return user32.UpdateWindow(hwnd) 
     383 
     384def invalidateRect(hwnd): 
     385        return user32.InvalidateRect(hwnd,None,False) 
     386 
     387def getKeyNameText(scanCode,extended): 
     388        buf=create_unicode_buffer(32) 
     389        user32.GetKeyNameTextW((scanCode<<16)|(extended<<24),buf,31) 
     390        return buf.value