pythonwindowsonenote

Simulate horizontal scroll in Windows with python


as the title says, I'm looking for a way to simulate horizontal scrolling (specifically in OneNote). I know it is possible to do it in AutoHotKey with a script, but I'm trying to keep the program as localized as possible. I also know it is possible with PyAutoGui on mac and linux, but I've come up empty handed with anything related to windows. If you have any leads, I would greatly appreciate it:)


Solution

  • For anyone running into a similar problem in the future, here's my solution:

    import win32api, time, pyautogui as pag, keyboard
    from win32con import *
    
    
    running = True
    lastX, lastY = pag.position()
    
    while running:
    
        while keyboard.is_pressed("shift"):
            x, y = pag.position()
            if lastX!=x:
                win32api.mouse_event(MOUSEEVENTF_HWHEEL, 0, 0, x-lastX, 0) # Horizontal scrolling
                lastX=x
    
            if lastY!=y:
                win32api.mouse_event(MOUSEEVENTF_WHEEL, 0, 0, lastY-y, 0) # Vertical scrolling
                lastY=y
    

    Hope this can help anyone in the future:)