Skip to content

Commit ac5a0ac

Browse files
authored
Merge 13e40af into bf96860
2 parents bf96860 + 13e40af commit ac5a0ac

3 files changed

Lines changed: 75 additions & 0 deletions

File tree

source/globalCommands.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,48 @@ def script_toggleRightMouseButton(self,gesture):
264264
else:
265265
mouseHandler.lockRightMouseButton()
266266

267+
@script(
268+
description=_(
269+
# Translators: Input help mode message for mouse wheel scroll up command.
270+
"Scrolls up the mouse wheel at the current mouse position"
271+
),
272+
category=SCRCAT_MOUSE,
273+
gesture="kb:windows+pageUp"
274+
)
275+
def script_scrollMouseWheelUp(self, gesture):
276+
mouseHandler.scrollMouseWheel(winUser.WHEEL_DELTA, isVertical=True)
277+
278+
@script(
279+
description=_(
280+
# Translators: Input help mode message for mouse wheel scroll down command.
281+
"Scrolls down the mouse wheel at the current mouse position"
282+
),
283+
category=SCRCAT_MOUSE,
284+
gesture="kb:windows+pageDown"
285+
)
286+
def script_scrollMouseWheelDown(self, gesture):
287+
mouseHandler.scrollMouseWheel(-winUser.WHEEL_DELTA, True)
288+
289+
@script(
290+
description=_(
291+
# Translators: Input help mode message for mouse wheel scroll left command.
292+
"Scrolls left the mouse wheel at the current mouse position"
293+
),
294+
category=SCRCAT_MOUSE
295+
)
296+
def script_scrollMouseWheelLeft(self, gesture):
297+
mouseHandler.scrollMouseWheel(-winUser.WHEEL_DELTA, isVertical=False)
298+
299+
@script(
300+
description=_(
301+
# Translators: Input help mode message for mouse wheel scroll right command.
302+
"Scrolls right the mouse wheel at the current mouse position"
303+
),
304+
category=SCRCAT_MOUSE
305+
)
306+
def script_scrollMouseWheelRight(self, gesture):
307+
mouseHandler.scrollMouseWheel(winUser.WHEEL_DELTA, isVertical=False)
308+
267309
@script(
268310
description=_(
269311
# Translators: Input help mode message for report current selection command.

source/mouseHandler.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,3 +379,32 @@ def unlockRightMouseButton():
379379
# Translators: This is presented when the right mouse button lock is released (used for drag and drop).
380380
ui.message(_("Right mouse button unlock"))
381381
executeMouseEvent(winUser.MOUSEEVENTF_RIGHTUP, 0, 0)
382+
383+
384+
def scrollMouseWheel(scrollSteps: int, isVertical: bool = True) -> None:
385+
"""
386+
Scrolls the mouse wheel either vertically or horizontally, controlling scroll direction and amount.
387+
Consult https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-mousewheel for more about mouse events.
388+
@param scrollSteps: The number of steps to scroll. Each step should
389+
correspond to a fraction or multiple of WHEEL_DELTA, which is typically set to 120.
390+
This defines the standard increment or decrement in scroll position.
391+
@type scrollSteps: int
392+
@param isVertical: Specifies the direction of the scroll. True for vertical (default), False for horizontal.
393+
@type isVertical: bool
394+
"""
395+
if not isinstance(scrollSteps, int):
396+
log.error(f"'scrollSteps' should be an integer. Type received: {type(scrollSteps).__name__}")
397+
return
398+
if scrollSteps == 0:
399+
return
400+
scrollEvent = winUser.MOUSEEVENTF_WHEEL if isVertical else winUser.MOUSEEVENTF_HWHEEL
401+
sign = -1 if scrollSteps < 0 else 1
402+
totalSteps = abs(scrollSteps)
403+
maxSteps = winUser.WHEEL_DELTA
404+
# Decompose the scroll operation into smaller deltas to accommodate applications
405+
# that may not process deltas larger than the standard efficiently.
406+
while totalSteps > 0:
407+
scrollStep = min(totalSteps, maxSteps)
408+
scrollData = sign * scrollStep
409+
executeMouseEvent(scrollEvent, 0, 0, scrollData)
410+
totalSteps -= scrollStep

user_docs/en/userGuide.t2t

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,10 @@ Although a physical mouse or trackpad should be used to navigate with the mouse,
764764
| Left mouse button lock | shift+numpadDivide | NVDA+control+[ | none | Locks the left mouse button down. Press again to release it. To drag the mouse, press this key to lock the left button down and then move the mouse either physically or use one of the other mouse routing commands |
765765
| Right mouse click | numpadMultiply | NVDA+] | tap and hold | Clicks the right mouse button once, mostly used to open context menu at the location of the mouse. |
766766
| Right mouse button lock | shift+numpadMultiply | NVDA+control+] | none | Locks the right mouse button down. Press again to release it. To drag the mouse, press this key to lock the right button down and then move the mouse either physically or use one of the other mouse routing commands |
767+
| Mouse wheel scroll up | Windows+pageUP | Windows+pageUP | none | Scrolls up the mouse wheel at the current mouse position |
768+
| Mouse wheel scroll down | Windows+pageDown | Windows+pageDown | none | Scrolls down the mouse wheel at the current mouse position |
769+
| Mouse wheel scroll left | none | none | none | Scrolls left the mouse wheel at the current mouse position |
770+
| Mouse wheel scroll right | none | none | none | Scrolls right the mouse wheel at the current mouse position |
767771
| Move mouse to current navigator object | NVDA+numpadDivide | NVDA+shift+m | none | Moves the mouse to the location of the current navigator object and review cursor |
768772
| Navigate to the object under the mouse | NVDA+numpadMultiply | NVDA+shift+n | none | Set the navigator object to the object located at the position of the mouse |
769773
%kc:endInclude

0 commit comments

Comments
 (0)