From 923e16b7e6d06ae80a7ee58c2e0891f991ba1402 Mon Sep 17 00:00:00 2001 From: A-DYB Date: Mon, 12 Apr 2021 23:23:08 -0400 Subject: [PATCH] Added scroll function --- pydirectinput/__init__.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pydirectinput/__init__.py b/pydirectinput/__init__.py index 52ee3d5..9951808 100644 --- a/pydirectinput/__init__.py +++ b/pydirectinput/__init__.py @@ -31,6 +31,7 @@ MOUSEEVENTF_MIDDLEDOWN = 0x0020 MOUSEEVENTF_MIDDLEUP = 0x0040 MOUSEEVENTF_MIDDLECLICK = MOUSEEVENTF_MIDDLEDOWN + MOUSEEVENTF_MIDDLEUP +MOUSEEVENTF_WHEEL = 0x0800 # KeyBdInput Flags KEYEVENTF_EXTENDEDKEY = 0x0001 @@ -374,6 +375,22 @@ def tripleClick(x=None, y=None, interval=0.0, button=LEFT, duration=0.0, tween=N # Missing feature: scroll functions +#A negative number of clicks will scroll down and a positive number will scroll up +@_genericPyDirectInputChecks +def scroll(clicks=0, delay=0): + if clicks >= 0: + direction = 1 + else: + direction = -1 + clicks = abs(clicks) + + for i in range(clicks): + extra = ctypes.c_ulong(0) + ii_ = Input_I() + ii_.mi = MouseInput(0, 0, ctypes.c_ulong(direction*120), MOUSEEVENTF_WHEEL, 0, ctypes.pointer(extra)) + x = Input(ctypes.c_ulong(0), ii_) + SendInput(1, ctypes.pointer(x), ctypes.sizeof(x)) + time.sleep(delay) # Ignored parameters: duration, tween, logScreenshot # PyAutoGUI uses ctypes.windll.user32.SetCursorPos(x, y) for this, which might still work fine in DirectInput