Skip to content

Commit

Permalink
Reduce repeated SendInput calls in scroll Mouse
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravindran authored and Ravindran committed Oct 18, 2018
1 parent 2026f88 commit ee432a6
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions src/mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,7 @@ void scrollMouse(int x, int y)
#if defined(IS_WINDOWS)
// Fix for #97 https://github.com/octalmage/robotjs/issues/97,
// C89 needs variables declared on top of functions (mouseScrollInput)
INPUT mouseScrollInputH;
INPUT mouseScrollInputV;
INPUT mouseScrollInputs[2];
#endif

/* Direction should only be considered based on the scrollDirection. This
Expand Down Expand Up @@ -293,25 +292,24 @@ void scrollMouse(int x, int y)

#elif defined(IS_WINDOWS)

mouseScrollInputH.type = INPUT_MOUSE;
mouseScrollInputH.mi.dx = 0;
mouseScrollInputH.mi.dy = 0;
mouseScrollInputH.mi.dwFlags = MOUSEEVENTF_HWHEEL;
mouseScrollInputH.mi.time = 0;
mouseScrollInputH.mi.dwExtraInfo = 0;
mouseScrollInputs[0].type = INPUT_MOUSE;
mouseScrollInputs[0].mi.dx = 0;
mouseScrollInputs[0].mi.dy = 0;
mouseScrollInputs[0].mi.dwFlags = MOUSEEVENTF_HWHEEL;
mouseScrollInputs[0].mi.time = 0;
mouseScrollInputs[0].mi.dwExtraInfo = 0;
// Flip x to match other platforms.
mouseScrollInputH.mi.mouseData = -x;

mouseScrollInputV.type = INPUT_MOUSE;
mouseScrollInputV.mi.dx = 0;
mouseScrollInputV.mi.dy = 0;
mouseScrollInputV.mi.dwFlags = MOUSEEVENTF_WHEEL;
mouseScrollInputV.mi.time = 0;
mouseScrollInputV.mi.dwExtraInfo = 0;
mouseScrollInputV.mi.mouseData = y;

SendInput(1, &mouseScrollInputH, sizeof(mouseScrollInputH));
SendInput(1, &mouseScrollInputV, sizeof(mouseScrollInputV));
mouseScrollInputs[0].mi.mouseData = -x;

mouseScrollInputs[1].type = INPUT_MOUSE;
mouseScrollInputs[1].mi.dx = 0;
mouseScrollInputs[1].mi.dy = 0;
mouseScrollInputs[1].mi.dwFlags = MOUSEEVENTF_WHEEL;
mouseScrollInputs[1].mi.time = 0;
mouseScrollInputs[1].mi.dwExtraInfo = 0;
mouseScrollInputs[1].mi.mouseData = y;

SendInput(2, mouseScrollInputs, sizeof(mouseScrollInputs));
#endif
}

Expand Down

0 comments on commit ee432a6

Please sign in to comment.