Search code examples
automationautoit

AutoIt: How to make the mouse scroll up and down?


I'm thinking to create a script which can:

  1. Open a webpage in the browser
  2. Scroll down the webpage then scroll up

I've tried the following code but it can only do the first step, could anyone help me with this?

#include <AutoItConstants.au3>
ShellExecute("https://www.amazon.com")
MouseWheel($MOUSE_WHEEL_DOWN,10)
sleep(100)
MouseWheel($MOUSE_WHEEL_UP,10)

Thank you very much!


Solution

  • Browser window out of focus in your script.

    Try this code:

    #include <IE.au3>
    
    $oIE = _IECreate("http://amazon.com")
    $oIE.document.parentwindow.scroll(0,500)
    

    Or if who want to use MouseWheel (you must put mouse cursor to window area):

    ShellExecute("https://www.amazon.com")
    WinWaitActive("Amazon.com","")
    $aPos = WinGetPos("Amazon.com","")
    MouseMove($aPos[0]+($aPos[2]/2),$aPos[1]+($aPos[3]/2))
    sleep(100)
    MouseWheel($MOUSE_WHEEL_DOWN,10)
    sleep(100)
    MouseWheel($MOUSE_WHEEL_UP,10)