@@ -99,6 +99,27 @@ def getNVDAModifierKeys():
9999 keys .append (vkCodes .byName ["capslock" ])
100100 return keys
101101
102+
103+ def shouldUseToUnicodeEx (focus = None ):
104+ "Returns whether to use ToUnicodeEx to determine typed characters."
105+ if not focus :
106+ focus = api .getFocusObject ()
107+ from NVDAObjects .behaviors import KeyboardHandlerBasedTypedCharSupport
108+ return (
109+ # This is only possible in Windows 10 1607 and above
110+ winVersion .isWin10 (1607 )
111+ and ( # Either of
112+ # We couldn't inject in-process, and its not a legacy console window without keyboard support.
113+ # console windows have their own specific typed character support.
114+ (not focus .appModule .helperLocalBindingHandle and focus .windowClassName != 'ConsoleWindowClass' )
115+ # or the focus is within a UWP app, where WM_CHAR never gets sent
116+ or focus .windowClassName .startswith ('Windows.UI.Core' )
117+ #Or this is a console with keyboard support, where WM_CHAR messages are doubled
118+ or isinstance (focus , KeyboardHandlerBasedTypedCharSupport )
119+ )
120+ )
121+
122+
102123def internal_keyDownEvent (vkCode ,scanCode ,extended ,injected ):
103124 """Event called by winInputHook when it receives a keyDown.
104125 """
@@ -197,23 +218,12 @@ def internal_keyDownEvent(vkCode,scanCode,extended,injected):
197218 # #6017: handle typed characters in Win10 RS2 and above where we can't detect typed characters in-process
198219 # This code must be in the 'finally' block as code above returns in several places yet we still want to execute this particular code.
199220 focus = api .getFocusObject ()
200- from NVDAObjects .behaviors import KeyboardHandlerBasedTypedCharSupport
201221 if (
202- # This is only possible in Windows 10 1607 and above
203- winVersion .isWin10 (1607 )
222+ shouldUseToUnicodeEx (focus )
204223 # And we only want to do this if the gesture did not result in an executed action
205224 and not gestureExecuted
206225 # and not if this gesture is a modifier key
207226 and not isNVDAModifierKey (vkCode ,extended ) and not vkCode in KeyboardInputGesture .NORMAL_MODIFIER_KEYS
208- and ( # Either of
209- # We couldn't inject in-process, and its not a legacy console window without keyboard support.
210- # console windows have their own specific typed character support.
211- (not focus .appModule .helperLocalBindingHandle and focus .windowClassName != 'ConsoleWindowClass' )
212- # or the focus is within a UWP app, where WM_CHAR never gets sent
213- or focus .windowClassName .startswith ('Windows.UI.Core' )
214- #Or this is a console with keyboard support, where WM_CHAR messages are doubled
215- or isinstance (focus , KeyboardHandlerBasedTypedCharSupport )
216- )
217227 ):
218228 keyStates = (ctypes .c_byte * 256 )()
219229 for k in range (256 ):
0 commit comments