robotgo icon indicating copy to clipboard operation
robotgo copied to clipboard

question in scroll function on different systems

Open IsaacDiane opened this issue 3 years ago • 1 comments

  • Robotgo version (or commit ref):
  • Go version:1.18.3
  • Gcc version:8.1.0
  • Operating system and bit:windows10 x86_64 & darwin arm64
  • Resolution:1920 * 1080
  • Can you reproduce the bug at Examples:
    • [x] Yes (provide example code)
    • [ ] No
    • [ ] Not relevant
  • Provide example code:
  • robotgo.ScrollSmooth(-1)
  • robotgo.ScrollSmooth(0,1,100,-1)

  • Log gist:

Description

The first code above leads to very different result on windows and darwin. What does the toy and tox really mean? On darwin,I think it means the number of pixel? What about windows?Moreover, the tox param seems can't work on windows, the code has been shown as the second one above. Is it a bug? Or just my wrong usage of the function? ...

IsaacDiane avatar Jul 19 '22 08:07 IsaacDiane

Maybe I have saved the potential BUG in code. In the file mouse/mouse_h.c

there are following code:

#elif defined(IS_WINDOWS) mouseScrollInputH.type = INPUT_MOUSE; mouseScrollInputH.mi.dx = 0; mouseScrollInputH.mi.dy = 0; mouseScrollInputH.mi.dwFlags = MOUSEEVENTF_WHEEL; mouseScrollInputH.mi.time = 0; mouseScrollInputH.mi.dwExtraInfo = 0; mouseScrollInputH.mi.mouseData = MOUSE_DELTA*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 = MOUSE_DELTA*y;

	SendInput(1, &mouseScrollInputH, sizeof(mouseScrollInputH));
	SendInput(1, &mouseScrollInputV, sizeof(mouseScrollInputV));
#endif

Let's focus on mouseData. MOUSE_DELTA is a constant configured in Windows. We can config it in system setting, the line scroll by one rotation of the wheel. It is 120 by default setting. So the tox,toy truely in robotgo means the time we rotate the wheel, not like macOS, which means the pixel. How to keep them consistent? Just delete MOUSE_DELTA. But please pay attention that, if mouseData is less than 120, nothing happens.

Then about the horizon scrolling, PLEASE focus on the dwFlags, they are both MOUSEEVENTF_WHEEL, which means vertial scrolling. In win32api, there is another constant called MOUSEEVENTF_HWHEEL, however, when I changed to the constant, the code cannot compile, so I use the value to substitute it, which is 0x1000.

So the following code can do my requirement successfully.

#elif defined(IS_WINDOWS) mouseScrollInputH.type = INPUT_MOUSE; mouseScrollInputH.mi.dx = 0; mouseScrollInputH.mi.dy = 0; mouseScrollInputH.mi.dwFlags = 0x01000; mouseScrollInputH.mi.time = 0; mouseScrollInputH.mi.dwExtraInfo = 0; 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));
#endif

In the main func: robotgo.Scroll(500,500)

Can any maintainers see if the code can be fixed into some coming version of robotgo? @vcaesar

IsaacDiane avatar Aug 02 '22 06:08 IsaacDiane