Author Topic: Scroll Mouse at any area of the screen  (Read 3194 times)

0 Members and 1 Guest are viewing this topic.

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Scroll Mouse at any area of the screen
« on: April 29, 2021, 12:38:15 pm »
Since so many people are talking about moving the mouse outside of the screen, I decided to see about scrolling the mouse wherever you want. The below code is not really mine. I found it on Stack Overflow and then edited it.

Code: C++: [Select]
  1. UINT ScrollMouse(int x, int y, int scroll) //save as scroll.h
  2. {
  3.    INPUT input;
  4.    POINT pos;
  5.    SetCursorPos(x,y);
  6.    pos.x = x;
  7.    pos.y = y;
  8.  
  9.    input.type = INPUT_MOUSE;
  10.    input.mi.dwFlags = MOUSEEVENTF_WHEEL;
  11.    input.mi.time = NULL; //Windows will do the timestamp
  12.    input.mi.mouseData = (DWORD)scroll*WHEEL_DELTA; //A positive value indicates that the wheel was rotated forward, away from the user; a negative value indicates that the wheel was rotated backward, toward the user. One wheel click is defined as WHEEL_DELTA, which is 120.
  13.    input.mi.dx = pos.x;
  14.    input.mi.dy = pos.y;
  15.    input.mi.dwExtraInfo = GetMessageExtraInfo();
  16.  
  17.    return SendInput(1, &input, sizeof(INPUT));
  18. }

Code: QB64: [Select]
  1. Declare Library "scroll"
  2.     Function ScrollMouse~& (ByVal x As Long, Byval y As Long, Byval scroll As Long)
  3.  
  4. Print ScrollMouse(2460, 500, -3) 'I have 3 monitors so my width goes beyond regular resolutions.
Shuwatch!