Skip to content

Commit 2777ea2

Browse files
authored
Merge f0dd7fe into 935e802
2 parents 935e802 + f0dd7fe commit 2777ea2

8 files changed

Lines changed: 56 additions & 2 deletions

File tree

projectDocs/dev/developerGuide/developerGuide.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,6 +1361,7 @@ For examples of how to define and use new extension points, please see the code
13611361

13621362
| Type |Extension Point |Description|
13631363
|---|---|---|
1364+
|`Decider` |`decide_handleRawKey` |Notifies when a raw keyboard event is received, before any NVDA processing, allowing other code to decide if it should be handled.|
13641365
|`Decider` |`decide_executeGesture` |Notifies when a gesture is about to be executed, allowing other code to decide if it should be.|
13651366

13661367
### logHandler {#logHandlerExtPts}
@@ -1382,6 +1383,7 @@ For examples of how to define and use new extension points, please see the code
13821383
|`Action` |`speechCanceled` |Triggered when speech is canceled.|
13831384
|`Action` |`pre_speechCanceled` |Triggered before speech is canceled.|
13841385
|`Action` |`pre_speech` |Triggered before NVDA handles prepared speech.|
1386+
|`Action` |`post_speechPaused` |Triggered when speech is paused or resumed.|
13851387
|`Filter` |`filter_speechSequence` |Allows components or add-ons to filter speech sequence before it passes to the synth driver.|
13861388

13871389
### synthDriverHandler {#synthDriverHandlerExtPts}

source/inputCore.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,22 @@ def __eq__(self, other: Any) -> bool:
452452
return NotImplemented
453453

454454

455+
decide_handleRawKey = extensionPoints.Decider()
456+
"""
457+
Notifies when a raw keyboard event is received, before any NVDA processing.
458+
Handlers can decide whether the key should be processed by NVDA and/or passed to the OS.
459+
:param vkCode: The virtual key code
460+
:type vkCode: int
461+
:param scanCode: The scan code
462+
:type scanCode: int
463+
:param extended: Whether this is an extended key
464+
:type extended: bool
465+
:param pressed: Whether this is a key press or release
466+
:type pressed: bool
467+
:return: True to allow normal processing, False to block the key
468+
:rtype: bool
469+
"""
470+
455471
decide_executeGesture = extensionPoints.Decider()
456472
"""
457473
Notifies when a gesture is about to be executed,

source/keyboardHandler.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,13 @@ def shouldUseToUnicodeEx(focus: Optional["NVDAObject"] = None):
165165

166166
def internal_keyDownEvent(vkCode, scanCode, extended, injected):
167167
"""Event called by winInputHook when it receives a keyDown."""
168+
if not inputCore.decide_handleRawKey.decide(
169+
vkCode=vkCode,
170+
scanCode=scanCode,
171+
extended=extended,
172+
pressed=True,
173+
):
174+
return False
168175
gestureExecuted = False
169176
try:
170177
global \
@@ -313,6 +320,13 @@ def internal_keyDownEvent(vkCode, scanCode, extended, injected):
313320

314321
def internal_keyUpEvent(vkCode, scanCode, extended, injected):
315322
"""Event called by winInputHook when it receives a keyUp."""
323+
if not inputCore.decide_handleRawKey.decide(
324+
vkCode=vkCode,
325+
scanCode=scanCode,
326+
extended=extended,
327+
pressed=False,
328+
):
329+
return False
316330
try:
317331
global \
318332
lastNVDAModifier, \

source/speech/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
spellTextInfo,
6464
splitTextIndentation,
6565
)
66-
from .extensions import speechCanceled
66+
from .extensions import speechCanceled, post_speechPaused
6767
from .priorities import Spri
6868

6969
from .types import (
@@ -142,6 +142,7 @@
142142
"spellTextInfo",
143143
"splitTextIndentation",
144144
"speechCanceled",
145+
"post_speechPaused",
145146
]
146147

147148
import synthDriverHandler

source/speech/extensions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@
2222
Handlers are called without arguments.
2323
"""
2424

25+
post_speechPaused = Action()
26+
"""
27+
Notifies when speech is paused.
28+
29+
:param switch: True if speech is paused, False if speech is resumed.
30+
:type switch: bool
31+
"""
32+
2533
pre_speech = Action()
2634
"""
2735
Notifies when code attempts to speak text.

source/speech/speech.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from textUtils import unicodeNormalize
2828
from textUtils.uniscribe import splitAtCharacterBoundaries
2929
from . import manager
30-
from .extensions import speechCanceled, pre_speechCanceled, pre_speech
30+
from .extensions import speechCanceled, post_speechPaused, pre_speechCanceled, pre_speech
3131
from .extensions import filter_speechSequence
3232
from .commands import (
3333
# Commands that are used in this file.
@@ -211,6 +211,7 @@ def cancelSpeech():
211211

212212
def pauseSpeech(switch):
213213
getSynth().pause(switch)
214+
post_speechPaused.notify(switch=switch)
214215
_speechState.isPaused = switch
215216
_speechState.beenCanceled = False
216217

tests/unit/test_speech.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
_getSpellingSpeechAddCharMode,
1717
_getSpellingSpeechWithoutCharMode,
1818
cancelSpeech,
19+
pauseSpeech,
1920
speechCanceled,
21+
post_speechPaused,
2022
)
2123
from speech.commands import (
2224
BeepCommand,
@@ -591,3 +593,10 @@ def test_speechCanceledExtensionPoint(self):
591593
speechCanceled,
592594
):
593595
cancelSpeech()
596+
597+
def test_post_speechPausedExtensionPoint(self):
598+
with actionTester(self, post_speechPaused, switch=True):
599+
pauseSpeech(True)
600+
601+
with actionTester(self, post_speechPaused, switch=False):
602+
pauseSpeech(False)

user_docs/en/changes.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ Add-ons will need to be re-tested and have their manifest updated.
105105
* Added the [VS Code workspace configuration for NVDA](https://nvaccess.org/nvaccess/vscode-nvda) as a git submodule. (#17003)
106106
* In the `brailleTables` module, a `getDefaultTableForCurrentLang` function has been added (#17222, @nvdaes)
107107
* Retrieving the `labeledBy` property now works for UIA elements supporting the corresponding `LabeledBy` UIA property. (#17442, @michaelweghorn)
108+
* Added the following extension points (#17428):
109+
* `inputCore.decide_handleRawKey`: called on each keypress
110+
* `speech.extensions.post_speechPaused`: called when speech is paused or unpaused
108111

109112
#### API Breaking Changes
110113

0 commit comments

Comments
 (0)