Skip to content

Commit 7707b57

Browse files
committed
add a check to disable toggle beeping if toggle keys in ease of access is enabled, since this feature can be enabled on the system but doesn't work very well for NVDA with laptop keyboard layout.
update readme with new sections. update sconstruct to generate english readme from addonReadme.md file
1 parent 1d78bfd commit 7707b57

File tree

6 files changed

+166
-15
lines changed

6 files changed

+166
-15
lines changed

addon/globalPlugins/beepKeyboard.py

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
# Released under GPL 2
66
#globalPlugins/beepKeyboard.py
77

8-
import api, codecs, config, globalPluginHandler, gui, keyboardHandler, tones, ui, winUser, wx, addonHandler
8+
import api, codecs, config, globalPluginHandler, gui, keyboardHandler, tones, ui, winreg, winUser, wx, addonHandler
99
addonHandler.initTranslation()
1010

11+
# config schema
1112
confspec = {
1213
"beepUpperWithCapsLock": "boolean(default=True)",
1314
"beepCharacterWithShift": "boolean(default=False)",
@@ -19,23 +20,36 @@
1920
"shiftedCharactersTone": "int_list(default=list(6000,10,25))",
2021
"customCharactersTone": "int_list(default=list(6000,10,25))",
2122
"capsLockUpperTone": "int_list(default=list(3000,40,50))",
22-
"toggleOffTone": "int_list(default=list(1000,40,50))",
23+
"toggleOffTone": "int_list(default=list(500,40,50))",
2324
"toggleOnTone": "int_list(default=list(2000, 40, 50))"
2425
}
2526
config.conf.spec["beepKeyboard"] = confspec
2627

28+
# Constants.
29+
REG_TOGGLE_KEYS = r"Control Panel\Accessibility\ToggleKeys"
30+
REG_KEY = "Flags"
31+
REG_VALUE_ON = 63
32+
33+
# global variables
34+
ignoreToggleKeys = False
35+
2736
def beep(l):
2837
""" it receives a list with three arguments to beep: [pitch, length, volume]"""
29-
if not (config.conf['beepKeyboard']['disableBeepingOnPasswordFields'] and api.getFocusObject().isProtected): tones.beep(*l, right=l[-1])
38+
if not (config.conf['beepKeyboard']['disableBeepingOnPasswordFields'] and api.getFocusObject().isProtected):
39+
tones.beep(*l, right=l[-1])
3040

3141
#saves the original _reportToggleKey function
3242
origReportToggleKey = keyboardHandler.KeyboardInputGesture._reportToggleKey
43+
3344
# alternate function to report state key.
3445
def _reportToggleKey(self):
35-
if winUser.getKeyState(self.vkCode) & 1:
36-
beep(config.conf['beepKeyboard']['toggleOnTone'])
37-
else: beep(config.conf['beepKeyboard']['toggleOffTone'])
38-
if config.conf['beepKeyboard']['announceToggleStatus'] or (config.conf['beepKeyboard']['disableBeepingOnPasswordFields'] and api.getFocusObject().isProtected): origReportToggleKey(self)
46+
global ignoreToggleKeys
47+
if not ignoreToggleKeys:
48+
if winUser.getKeyState(self.vkCode) & 1:
49+
beep(config.conf['beepKeyboard']['toggleOnTone'])
50+
else: beep(config.conf['beepKeyboard']['toggleOffTone'])
51+
if ignoreToggleKeys or config.conf['beepKeyboard']['announceToggleStatus'] or (config.conf['beepKeyboard']['disableBeepingOnPasswordFields'] and api.getFocusObject().isProtected):
52+
origReportToggleKey(self)
3953

4054
class BeepKeyboardSettingsPanel(gui.SettingsPanel):
4155
# Translators: This is the label for the beepKeyboard settings category in NVDA Settings screen.
@@ -165,6 +179,17 @@ def __init__(self):
165179
gui.settingsDialogs.NVDASettingsDialog.categoryClasses.append(BeepKeyboardSettingsPanel)
166180
config.post_configProfileSwitch.register(self.handleConfigProfileSwitch)
167181

182+
def checkEaseAccessToggleKeys(self):
183+
global ignoreToggleKeys
184+
# disables sounds for toggle keys if native system toggle keys is enabled.
185+
try:
186+
r = winreg.OpenKey(winreg.HKEY_CURRENT_USER, REG_TOGGLE_KEYS, 0, winreg.KEY_READ)
187+
v, _ = winreg.QueryValueEx(r, REG_KEY)
188+
if int(v) == REG_VALUE_ON: ignoreToggleKeys = True
189+
else: ignoreToggleKeys = False
190+
except:
191+
ignoreToggleKeys = False
192+
168193
def event_typedCharacter(self, obj, nextHandler, ch):
169194
nextHandler()
170195
if config.conf['beepKeyboard']['beepUpperWithCapsLock'] and winUser.getKeyState(winUser.VK_CAPITAL)&1 and ch.isupper():
@@ -174,9 +199,13 @@ def event_typedCharacter(self, obj, nextHandler, ch):
174199
elif ch in self.beepForCharacters: beep(config.conf['beepKeyboard']['customCharactersTone'])
175200

176201
def setExternalReportToggleStatus(self, flag):
202+
global ignoreToggleKeys
177203
if flag:
178-
keyboardHandler.KeyboardInputGesture._reportToggleKey = _reportToggleKey
179-
else: keyboardHandler.KeyboardInputGesture._reportToggleKey = origReportToggleKey
204+
self.checkEaseAccessToggleKeys()
205+
if not ignoreToggleKeys:
206+
keyboardHandler.KeyboardInputGesture._reportToggleKey = _reportToggleKey
207+
return
208+
keyboardHandler.KeyboardInputGesture._reportToggleKey = origReportToggleKey
180209

181210
def handleConfigProfileSwitch(self):
182211
self.setExternalReportToggleStatus(config.conf['beepKeyboard']['beepToggleKeyChanges'])
@@ -187,4 +216,4 @@ def terminate(self):
187216
super(GlobalPlugin, self).terminate()
188217
self.setExternalReportToggleStatus(False)
189218
gui.settingsDialogs.NVDASettingsDialog.categoryClasses.remove(BeepKeyboardSettingsPanel)
190-
config.post_configProfileSwitch.unregister(self.handleConfigProfileSwitch)
219+
config.post_configProfileSwitch.unregister(self.handleConfigProfileSwitch)

addonReadme.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Beep keyboard NVDA Add-on #
2+
This add-on allows the user to configure NVDA to beeps with some keyboard events.
3+
4+
Copyright (C) 2019 David CM <[email protected]>
5+
6+
This package is distributed under the terms of the GNU General Public License, version 2 or later.
7+
8+
## Features
9+
This add-on provides the following features you can use to adapt NVDA keyboard behavior:
10+
11+
* Beep for uppercases when caps lock is on: if this feature is enabled, NVDA will beep when you typing an uppercase and caps lock is on. Don't make any more uppercase mistakes!
12+
* Beep for typed characters when shift is pressed: with this feature NVDA will beep if you type a character with shift key pressed.
13+
* Beep for toggle keys changes: with this feature, NVDA will beep higher if a toggle key goes on, and lower tone if it goes off. Please note that Windows has a toggle keis beep function built-in on Ease of Access Center. This native feature works well if you don't use laptop keyboard layout setting.
14+
* Announce toggle keys changes: just when "Beep for toggle keys changes" is on. You can enable or disable NVDA to announce toggle key status.
15+
* Beep for specified characters: NVDA will beep for all characters that you set in advanced settings.
16+
* Disable beeping on password fields: this feature is enabled by default to aboid security risks. Disable it if you want to hear beeps on password fields.
17+
## Requirements
18+
You need NVDA 2018.2 or later.
19+
20+
## Installation
21+
Just install it as a NVDA add-on.
22+
23+
## Usage
24+
To enable or disable features, go to NVDA settings and select beep keyboard category. In that category you can configure all supported features by this add-on.
25+
"Beep for uppercases when caps lock is on" is enabled by default.
26+
If you need more settings, open the advanced settings dialog that contains the following options:
27+
28+
* Ignored characters with shift pressed: all characters here will be ignored to beeping when shift is pressed. Escape Sequences are allowed, e.g. "\t" for tab, "\r" for carriage return.
29+
* Beep always for the following characters: set here all characters that you want NVDA beeps for. Escape Sequences are allowed, e.g. "\t" for tab, "\r" for carriage return.
30+
* Select tone to configure: you can configure parameters for all tones. Select one here, and set the parameters in the next text boxes. When change selection, NVDA will beep for the current selected tone with the current parameters set in the dialog.
31+
* Tone pitch: tone pitch for the current selected tone.
32+
* Tone length: tone length for the current selected tone.
33+
* Tone volume: tone volume for the current selected tone.
34+
* Test tone: this button lets you to play a test with the current set parameters.
35+
* Press OK button to save settings or cancel to discard.
36+
37+
## Issues and suggestions reports.
38+
Please report your issues and suggestions on the github repository of this project:
39+
[Beep keyboard on GitHub](https://github.com/davidacm/beepKeyboard)
40+
41+
You can get the latest release in that repository.

beepKeyboard.code-workspace

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"folders": [
3+
{
4+
"path": "."
5+
}
6+
],
7+
"settings": {
8+
"editor.accessibilitySupport": "on",
9+
"python.linting.enabled": true,
10+
"python.linting.maxNumberOfProblems": 10000,
11+
"python.linting.flake8Args": [
12+
"--config=..\\..\\nvda\\tests\\lint\\flake8.ini",
13+
"--use-flake8-tabs=true"
14+
],
15+
"python.linting.flake8Enabled": true,
16+
"python.linting.pylintEnabled": false,
17+
"python.autoComplete.extraPaths": [
18+
"addon",
19+
"../../nvda/source",
20+
"../../nvda/include/comtypes",
21+
"../../nvda/include/configobj/src",
22+
"../../nvda/include/pyserial",
23+
"../../nvda/include/wxPython",
24+
"../../nvda/miscDeps/python"
25+
],
26+
"files.insertFinalNewline": true,
27+
"files.trimFinalNewlines": true,
28+
"editor.insertSpaces": false,
29+
"python.testing.unittestArgs": [
30+
"-v",
31+
"-s",
32+
"tests.unit",
33+
"-p",
34+
"test_*.py"
35+
],
36+
"python.testing.pytestEnabled": false,
37+
"python.testing.nosetestsEnabled": false,
38+
"python.testing.unittestEnabled": false
39+
}
40+
41+
}

buildVars.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# Translators: Long description to be shown for this add-on on add-on information from add-ons manager
2020
"addon_description" : _("""This add-on beeps with some keyboard events."""),
2121
# version
22-
"addon_version" : "1.3",
22+
"addon_version" : "1.6b",
2323
# Author(s)
2424
"addon_author" : u"David CM <[email protected]>",
2525
# URL for the add-on documentation support
@@ -29,7 +29,7 @@
2929
# Minimum NVDA version supported (e.g. "2018.3.0")
3030
"addon_minimumNVDAVersion" : "2018.3.0",
3131
# Last NVDA version supported/tested (e.g. "2018.4.0", ideally more recent than minimum version)
32-
"addon_lastTestedNVDAVersion" : "2019.3.0",
32+
"addon_lastTestedNVDAVersion" : "2020.2.0",
3333
# Add-on update channel (default is stable or None)
3434
"addon_updateChannel" : None,
3535
}

readme.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,46 @@ Copyright (C) 2019 David CM <[email protected]>
55

66
This package is distributed under the terms of the GNU General Public License, version 2 or later.
77

8+
## Download.
9+
The latest release is available to [download in this link](https://davidacm.github.io/getlatest/gh/davidacm/beepKeyboard)
10+
11+
# Contributing to this project.
12+
### Donations.
13+
If you like my project or this software is useful for you in your daily life and you would like to contribute in some way, you can donate via paypal in the
14+
[donate link.](https://paypal.me/davicm)
15+
16+
let me know if you want to write a message or promote a link in the collaboration section.
17+
18+
### fixing bugs and new features.
19+
If you want to fix a bug or add new feature, You will need to fork this repository.
20+
21+
#### Forking the repository.
22+
If this is your first contribution, you will first need to "fork" the BeepKeyboard repository on GitHub:
23+
24+
1. Fork this repo in your github account.
25+
2. Clone your forked repo locally: "git clone yourRepoUrl".
26+
3. Add this repo in your forked repo from the command line:
27+
"git remote add davidacm https://github.com/davidacm/beepKeyboard.git".
28+
4. fetch my branches:
29+
"git fetch davidacm".
30+
5. Switch to the local master branch: "git checkout master".
31+
6. Set the local master to use the davidacm master as its upstream:
32+
"git branch -u davidacm/master".
33+
34+
#### Steps before coding.
35+
You must use a separate "topic" branch for each issue or feature. All code should usually be based on the latest commit in the official master branch at the time you start the work.
36+
So, before begin to work, do the following:
37+
38+
1. Remember the steps of "Forking the repository" section.
39+
2. Checkout to master branch: "git checkout master".
40+
3. Update the local master: "git pull".
41+
4. Create a new branch based on the updated master branch: "git checkout -b YourNewBranch".
42+
5. write your code.
43+
6. Add your work to be commited (clean unwanted files first): git "add ."
44+
7. create a commit: "git commit" and write the commit message.
45+
8. push your branch in your repository: "git push". if the branch doesn't exist, git will tell you how to deal with this.
46+
9. Request a pull request on my repository.
47+
848
## Features
949
This add-on provides the following features you can use to adapt NVDA keyboard behavior:
1050

@@ -32,4 +72,4 @@ This package is distributed under the terms of the GNU General Public License, v
3272
* Tone length: tone length for the current selected tone.
3373
* Tone volume: tone volume for the current selected tone.
3474
* Test tone: this button lets you to play a test with the current set parameters.
35-
* Press OK button to save settings or cancel to discard.
75+
* Press OK button to save settings or cancel to discard.

sconstruct

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ def createAddonHelp(dir):
9797
cssPath = os.path.join(docsDir, "style.css")
9898
cssTarget = env.Command(cssPath, "style.css", Copy("$TARGET", "$SOURCE"))
9999
env.Depends(addon, cssTarget)
100-
if os.path.isfile("readme.md"):
100+
if os.path.isfile("addonReadme.md"):
101101
readmePath = os.path.join(docsDir, "en", "readme.md")
102-
readmeTarget = env.Command(readmePath, "readme.md", Copy("$TARGET", "$SOURCE"))
102+
readmeTarget = env.Command(readmePath, "addonReadme.md", Copy("$TARGET", "$SOURCE"))
103103
env.Depends(addon, readmeTarget)
104104

105105
def createAddonBundleFromPath(path, dest):

0 commit comments

Comments
 (0)