Skip to content

Commit b56a230

Browse files
authored
Merge b2a4042 into f01453f
2 parents f01453f + b2a4042 commit b56a230

2 files changed

Lines changed: 30 additions & 12 deletions

File tree

source/brailleInput.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from baseObject import AutoPropertyObject
2323
import keyLabels
2424

25+
2526
"""Framework for handling braille input from the user.
2627
All braille input is represented by a {BrailleInputGesture}.
2728
Normally, all that is required is to create and execute a L{BrailleInputGesture},
@@ -399,6 +400,13 @@ def sendChars(self, chars: str):
399400
input.ii.ki.dwFlags = winUser.KEYEVENTF_UNICODE|direction
400401
inputs.append(input)
401402
winUser.SendInput(inputs)
403+
focusObj = api.getFocusObject()
404+
if keyboardHandler.shouldUseToUnicodeEx(focusObj):
405+
# #10569: When we use ToUnicodeEx to detect typed characters,
406+
# emulated keypresses aren't detected.
407+
# Send TypedCharacter events manually.
408+
for ch in chars:
409+
focusObj.event_typedCharacter(ch=ch)
402410

403411
def handleGainFocus(self, obj):
404412
""" Clear all state when the focus changes.

source/keyboardHandler.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
102123
def 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

Comments
 (0)