|
1 | 1 | # -*- coding: UTF-8 -*- |
2 | | -# keyboardHandler.py |
3 | 2 | # A part of NonVisual Desktop Access (NVDA) |
4 | 3 | # This file is covered by the GNU General Public License. |
5 | 4 | # See the file COPYING for more details. |
|
8 | 7 | """Keyboard support""" |
9 | 8 |
|
10 | 9 | import ctypes |
11 | | -import sys |
12 | 10 | import time |
13 | 11 | import re |
14 | 12 | import typing |
|
19 | 17 | Any, |
20 | 18 | ) |
21 | 19 |
|
22 | | -import wx |
23 | 20 | import winVersion |
24 | 21 | import winUser |
25 | 22 | import vkCodes |
|
28 | 25 | import ui |
29 | 26 | from keyLabels import localizedKeyLabels |
30 | 27 | from logHandler import log |
31 | | -import queueHandler |
32 | 28 | import config |
33 | 29 | from config.configFlags import NVDAKey |
34 | 30 | import api |
|
41 | 37 | import threading |
42 | 38 |
|
43 | 39 | if typing.TYPE_CHECKING: |
| 40 | + from NVDAObjects import NVDAObject # noqa: F401 |
44 | 41 | from watchdog import WatchdogObserver |
45 | 42 |
|
46 | 43 | _watchdogObserver: typing.Optional["WatchdogObserver"] = None |
@@ -136,20 +133,30 @@ def getNVDAModifierKeys() -> List[Tuple[int, Optional[bool]]]: |
136 | 133 | return keys |
137 | 134 |
|
138 | 135 |
|
139 | | -def shouldUseToUnicodeEx(focus=None): |
| 136 | +def shouldUseToUnicodeEx(focus: Optional["NVDAObject"] = None): |
140 | 137 | "Returns whether to use ToUnicodeEx to determine typed characters." |
141 | 138 | if not focus: |
142 | 139 | focus = api.getFocusObject() |
| 140 | + from NVDAObjects.window import Window |
143 | 141 | from NVDAObjects.behaviors import KeyboardHandlerBasedTypedCharSupport |
144 | 142 | return ( |
145 | 143 | # This is only possible in Windows 10 1607 and above |
146 | 144 | winVersion.getWinVer() >= winVersion.WIN10_1607 |
147 | 145 | and ( # Either of |
148 | 146 | # We couldn't inject in-process, and its not a legacy console window without keyboard support. |
149 | 147 | # console windows have their own specific typed character support. |
150 | | - (not focus.appModule.helperLocalBindingHandle and focus.windowClassName != 'ConsoleWindowClass') |
| 148 | + ( |
| 149 | + not focus.appModule.helperLocalBindingHandle |
| 150 | + and ( |
| 151 | + not isinstance(focus, Window) |
| 152 | + or focus.windowClassName != 'ConsoleWindowClass' |
| 153 | + ) |
| 154 | + ) |
151 | 155 | # or the focus is within a UWP app, where WM_CHAR never gets sent |
152 | | - or focus.windowClassName.startswith('Windows.UI.Core') |
| 156 | + or ( |
| 157 | + isinstance(focus, Window) |
| 158 | + and focus.windowClassName.startswith('Windows.UI.Core') |
| 159 | + ) |
153 | 160 | # Or this is a console with keyboard support, where WM_CHAR messages are doubled |
154 | 161 | or isinstance(focus, KeyboardHandlerBasedTypedCharSupport) |
155 | 162 | ) |
|
0 commit comments