Skip to content

Commit 20ccf78

Browse files
authored
Merge fd7fef7 into bf96860
2 parents bf96860 + fd7fef7 commit 20ccf78

3 files changed

Lines changed: 74 additions & 0 deletions

File tree

source/globalCommands.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,46 @@ 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+
)
274+
def script_scrollMouseWheelUp(self, gesture):
275+
mouseHandler.scrollMouseWheel(winUser.WHEEL_DELTA, isVertical=True)
276+
277+
@script(
278+
description=_(
279+
# Translators: Input help mode message for mouse wheel scroll down command.
280+
"Scrolls down the mouse wheel at the current mouse position"
281+
),
282+
category=SCRCAT_MOUSE
283+
)
284+
def script_scrollMouseWheelDown(self, gesture):
285+
mouseHandler.scrollMouseWheel(-winUser.WHEEL_DELTA, True)
286+
287+
@script(
288+
description=_(
289+
# Translators: Input help mode message for mouse wheel scroll left command.
290+
"Scrolls left the mouse wheel at the current mouse position"
291+
),
292+
category=SCRCAT_MOUSE
293+
)
294+
def script_scrollMouseWheelLeft(self, gesture):
295+
mouseHandler.scrollMouseWheel(-winUser.WHEEL_DELTA, isVertical=False)
296+
297+
@script(
298+
description=_(
299+
# Translators: Input help mode message for mouse wheel scroll right command.
300+
"Scrolls right the mouse wheel at the current mouse position"
301+
),
302+
category=SCRCAT_MOUSE
303+
)
304+
def script_scrollMouseWheelRight(self, gesture):
305+
mouseHandler.scrollMouseWheel(winUser.WHEEL_DELTA, isVertical=False)
306+
267307
@script(
268308
description=_(
269309
# Translators: Input help mode message for report current selection command.

source/mouseHandler.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,3 +379,33 @@ 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 the scroll direction and amount.
387+
More details on mouse events can be found at:
388+
https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-mousewheel
389+
390+
:param scrollSteps: The number of steps to scroll. Each step should correspond to a fraction or multiple
391+
of WHEEL_DELTA, which is typically set to 120. This defines the standard increment
392+
or decrement in scroll position.
393+
:param isVertical: Determines the direction of the scroll; vertical if True, horizontal if False.
394+
:return: None
395+
"""
396+
if not isinstance(scrollSteps, int):
397+
raise TypeError(f"'scrollSteps' should be an integer. Type received: {type(scrollSteps).__name__}")
398+
return
399+
if scrollSteps == 0:
400+
return
401+
scrollEvent = winUser.MOUSEEVENTF_WHEEL if isVertical else winUser.MOUSEEVENTF_HWHEEL
402+
sign = -1 if scrollSteps < 0 else 1
403+
totalSteps = abs(scrollSteps)
404+
maxSteps = winUser.WHEEL_DELTA
405+
# Decompose the scroll operation into smaller deltas to accommodate applications
406+
# that may not process deltas larger than the standard efficiently.
407+
while totalSteps > 0:
408+
scrollStep = min(totalSteps, maxSteps)
409+
scrollData = sign * scrollStep
410+
executeMouseEvent(scrollEvent, 0, 0, scrollData)
411+
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 | none | none | none | Scrolls up the mouse wheel at the current mouse position |
768+
| Mouse wheel scroll down | none | none | 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)