Skip to content

Commit cf58231

Browse files
committed
1 parent a585d04 commit cf58231

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

pydirectinput/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
MOUSEEVENTF_MIDDLEDOWN = 0x0020
3232
MOUSEEVENTF_MIDDLEUP = 0x0040
3333
MOUSEEVENTF_MIDDLECLICK = MOUSEEVENTF_MIDDLEDOWN + MOUSEEVENTF_MIDDLEUP
34+
MOUSEEVENTF_WHEEL = 0x0800
3435

3536
# KeyBdInput Flags
3637
KEYEVENTF_EXTENDEDKEY = 0x0001
@@ -374,6 +375,22 @@ def tripleClick(x=None, y=None, interval=0.0, button=LEFT, duration=0.0, tween=N
374375

375376
# Missing feature: scroll functions
376377

378+
#A negative number of clicks will scroll down and a positive number will scroll up
379+
@_genericPyDirectInputChecks
380+
def scroll(clicks=0, delay=0):
381+
if clicks >= 0:
382+
direction = 1
383+
else:
384+
direction = -1
385+
clicks = abs(clicks)
386+
387+
for i in range(clicks):
388+
extra = ctypes.c_ulong(0)
389+
ii_ = Input_I()
390+
ii_.mi = MouseInput(0, 0, ctypes.c_ulong(direction*120), MOUSEEVENTF_WHEEL, 0, ctypes.pointer(extra))
391+
x = Input(ctypes.c_ulong(0), ii_)
392+
SendInput(1, ctypes.pointer(x), ctypes.sizeof(x))
393+
time.sleep(delay)
377394

378395
# Ignored parameters: duration, tween, logScreenshot
379396
# PyAutoGUI uses ctypes.windll.user32.SetCursorPos(x, y) for this, which might still work fine in DirectInput

0 commit comments

Comments
 (0)