Skip to content

Commit

Permalink
Merge b6e2b8b into f01453f
Browse files Browse the repository at this point in the history
  • Loading branch information
codeofdusk authored Dec 3, 2019
2 parents f01453f + b6e2b8b commit 3e6b3e2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
8 changes: 8 additions & 0 deletions source/brailleInput.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from baseObject import AutoPropertyObject
import keyLabels


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

def handleGainFocus(self, obj):
""" Clear all state when the focus changes.
Expand Down
34 changes: 22 additions & 12 deletions source/keyboardHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,27 @@ def getNVDAModifierKeys():
keys.append(vkCodes.byName["capslock"])
return keys


def shouldUseToUnicodeEx(focus=None):
"Returns whether to use ToUnicodeEx to determine typed characters."
if not focus:
focus=api.getFocusObject()
from NVDAObjects.behaviors import KeyboardHandlerBasedTypedCharSupport
return (
# This is only possible in Windows 10 1607 and above
winVersion.isWin10(1607)
and ( # Either of
# We couldn't inject in-process, and its not a legacy console window without keyboard support.
# console windows have their own specific typed character support.
(not focus.appModule.helperLocalBindingHandle and focus.windowClassName!='ConsoleWindowClass')
# or the focus is within a UWP app, where WM_CHAR never gets sent
or focus.windowClassName.startswith('Windows.UI.Core')
#Or this is a console with keyboard support, where WM_CHAR messages are doubled
or isinstance(focus, KeyboardHandlerBasedTypedCharSupport)
)
)


def internal_keyDownEvent(vkCode,scanCode,extended,injected):
"""Event called by winInputHook when it receives a keyDown.
"""
Expand Down Expand Up @@ -197,23 +218,12 @@ def internal_keyDownEvent(vkCode,scanCode,extended,injected):
# #6017: handle typed characters in Win10 RS2 and above where we can't detect typed characters in-process
# This code must be in the 'finally' block as code above returns in several places yet we still want to execute this particular code.
focus=api.getFocusObject()
from NVDAObjects.behaviors import KeyboardHandlerBasedTypedCharSupport
if (
# This is only possible in Windows 10 1607 and above
winVersion.isWin10(1607)
shouldUseToUnicodeEx(focus)
# And we only want to do this if the gesture did not result in an executed action
and not gestureExecuted
# and not if this gesture is a modifier key
and not isNVDAModifierKey(vkCode,extended) and not vkCode in KeyboardInputGesture.NORMAL_MODIFIER_KEYS
and ( # Either of
# We couldn't inject in-process, and its not a legacy console window without keyboard support.
# console windows have their own specific typed character support.
(not focus.appModule.helperLocalBindingHandle and focus.windowClassName!='ConsoleWindowClass')
# or the focus is within a UWP app, where WM_CHAR never gets sent
or focus.windowClassName.startswith('Windows.UI.Core')
#Or this is a console with keyboard support, where WM_CHAR messages are doubled
or isinstance(focus, KeyboardHandlerBasedTypedCharSupport)
)
):
keyStates=(ctypes.c_byte*256)()
for k in range(256):
Expand Down

0 comments on commit 3e6b3e2

Please sign in to comment.