forked from Mdlglobal-atlassian-net/nvda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheaseOfAccess.py
93 lines (85 loc) · 2.8 KB
/
easeOfAccess.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#easeOfAccess.py
#A part of NonVisual Desktop Access (NVDA)
#Copyright (C) 2014 NV Access Limited
#This file is covered by the GNU General Public License.
#See the file COPYING for more details.
"""Utilities for working with the Windows Ease of Access Center.
"""
import winreg
import ctypes
import winUser
from winVersion import winVersion
# Windows >= Vista
isSupported = winVersion.major >= 6
# Windows >= 8
canConfigTerminateOnDesktopSwitch = isSupported and (winVersion.major, winVersion.minor) >= (6, 2)
ROOT_KEY = r"Software\Microsoft\Windows NT\CurrentVersion\Accessibility"
APP_KEY_NAME = "nvda_nvda_v1"
APP_KEY_PATH = r"%s\ATs\%s" % (ROOT_KEY, APP_KEY_NAME)
def isRegistered():
try:
winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, APP_KEY_PATH, 0,
winreg.KEY_READ | winreg.KEY_WOW64_64KEY)
return True
except WindowsError:
return False
def notify(signal):
if not isRegistered():
return
with winreg.CreateKey(winreg.HKEY_CURRENT_USER, r"Software\Microsoft\Windows NT\CurrentVersion\AccessibilityTemp") as rkey:
winreg.SetValueEx(rkey, APP_KEY_NAME, None, winreg.REG_DWORD, signal)
keys = []
# The user might be holding unwanted modifiers.
for vk in winUser.VK_SHIFT, winUser.VK_CONTROL, winUser.VK_MENU:
if winUser.getAsyncKeyState(vk) & 32768:
keys.append((vk, False))
keys.append((0x5B, True)) # leftWindows
keys.append((0x55, True)) # u
inputs = []
# Release unwanted keys and press desired keys.
for vk, desired in keys:
input = winUser.Input(type=winUser.INPUT_KEYBOARD)
input.ii.ki.wVk = vk
if not desired:
input.ii.ki.dwFlags = winUser.KEYEVENTF_KEYUP
inputs.append(input)
# Release desired keys and press unwanted keys.
for vk, desired in reversed(keys):
input = winUser.Input(type=winUser.INPUT_KEYBOARD)
input.ii.ki.wVk = vk
if desired:
input.ii.ki.dwFlags = winUser.KEYEVENTF_KEYUP
inputs.append(input)
winUser.SendInput(inputs)
def willAutoStart(hkey):
try:
k = winreg.OpenKey(hkey, ROOT_KEY, 0,
winreg.KEY_READ | winreg.KEY_WOW64_64KEY)
return (APP_KEY_NAME in
winreg.QueryValueEx(k, "Configuration")[0].split(","))
except WindowsError:
return False
def setAutoStart(hkey, enable):
k = winreg.OpenKey(hkey, ROOT_KEY, 0,
winreg.KEY_READ | winreg.KEY_WRITE | winreg.KEY_WOW64_64KEY)
try:
conf = winreg.QueryValueEx(k, "Configuration")[0].split(",")
except WindowsError:
conf = []
else:
if not conf[0]:
# "".split(",") returns [""], so remove the empty string.
del conf[0]
changed = False
if enable and APP_KEY_NAME not in conf:
conf.append(APP_KEY_NAME)
changed = True
elif not enable:
try:
conf.remove(APP_KEY_NAME)
changed = True
except ValueError:
pass
if changed:
winreg.SetValueEx(k, "Configuration", None, winreg.REG_SZ,
",".join(conf))