How to mouse wheeldown less than 1 unit

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
paxatax
Posts: 3
Joined: 15 Jan 2017, 12:54

How to mouse wheeldown less than 1 unit

05 Jul 2017, 18:44

Hi guys,

Been using AHK for the last few weeks and loving it. Slowly automating my life.

I am currently trying to write a script that clicks somewhere on the screen, and then scrolls down an exact amount. The problem I am having is 'Click Wheeldown 1' is too much. I need it to be an exact amount, somewhere around 0.7, but I haven't been able to use decimals and can't find the proper solution online.

Furthermore, what would be the best way to measure that exact amount? Do a mouse coordinate measure between two, or is there something better you'd suggest? Essentially scrolling down a long list of usernames and doing actions on each, but the cursor has to land exactly in the middle of each username, consistently.

Thank you in advance, really appreciate your help.
User avatar
Spawnova
Posts: 555
Joined: 08 Jul 2015, 00:12
Contact:

Re: How to mouse wheeldown less than 1 unit

05 Jul 2017, 18:55

I'm not sure if that's possible personally, however another solution may be to just move the mouse based on the difference.

So if you scroll down and the mouse is say 20 pixels off, just do MouseMove,0,-20,,R Moves the mouse up 20 pixels.
You will of course have to do a bit of tweaking to get the right number.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: How to mouse wheeldown less than 1 unit

05 Jul 2017, 19:07

If you use AHK's window spy, what is the control under the cursor, when you hover over the scrollbar (it may be blank)?

Btw can you not use the arrow keys (or send arrow key presses) to line up the item to be under the cursor.

Basically I would consider sending messages to a ScrollBar or Edit control, or using the Acc library, to try to interact with the scrollbar.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: How to mouse wheeldown less than 1 unit

05 Jul 2017, 19:37

I'd been curious to know about how WheelUp/WheelDown is done, I checked the AHK source code and it appears that WM_MOUSEWHEEL is used. I'm not sure if this gives the granularity of control that you're looking for, however, when I used values of 1/-1, the scroll moved incredibly slowly.

Btw I searched the cpp files for 'WheelDown', and subsequently for 'VK_WHEEL_DOWN'. The source code is available here:
GitHub - Lexikos/AutoHotkey_L: AutoHotkey - macro-creation and automation-oriented scripting utility for Windows.
https://github.com/Lexikos/AutoHotkey_L

Code: Select all

q:: ;test - WheelUp/WheelDown
w:: ;test - WheelUp/WheelDown
MouseGetPos, vPosX, vPosY, hWnd, hCtl, 2
if hCtl
	hWnd := hCtl
vNum := 1
if InStr(A_ThisHotkey, "w")
	vNum *= -1 ;negative means downwards
PostMessage, 0x20A, % vNum<<16, % vPosX|(vPosY<<16),, % "ahk_id " hWnd ;WM_MOUSEWHEEL := 0x20A
return

;e::SendInput {WheelUp}
;r::SendInput {WheelDown}
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: How to mouse wheeldown less than 1 unit

05 Jul 2017, 20:03

jeeswg wrote:I'd been curious to know about how...
I was wondering how you guys find something very well.
Now I see some of it (I've nerver thouched its source code, because I do not know C++).

Good job.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: How to mouse wheeldown less than 1 unit

06 Jul 2017, 03:19

Indeed nice one jeeswg, I might use it :thumbup:. But I need to come up with some convenient hotkey, ironically, I'm not a big fan of hotkeys :lol:
Added primitive acceleration and using timers,

Code: Select all

wUp:=func("scroll").bind(1)
wDown:=func("scroll").bind(-1)
q::SetTimer, % wUp, 5
q up::
	SetTimer, % wUp, off
	scroll(0,true)
return
w::SetTimer, % wDown, 5
w up::
	SetTimer, % wDown, off
	scroll(0,true)
return
esc::exitapp
scroll(dir:=1,cls:=false){
	static pdir:=0, ptic:=0, acc:=1
	if cls
		return pdir:=0, ptic:=0, acc:=1
	MouseGetPos, vPosX, vPosY, hWnd, hCtl, 2
	if hCtl
		hWnd := hCtl
	if (pdir!=dir)
		ptic:=A_TickCount,acc:=1
	pdir:=dir
	if (A_TickCount-ptic>300/acc)
		acc++,ptic:=A_TickCount
	vNum := 1*dir*acc
	PostMessage, 0x20A, % vNum<<16, % vPosX|(vPosY<<16),, % "ahk_id " hWnd ;WM_MOUSEWHEEL := 0x20A
	return
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: DataLife, ewerybody, mcd, ShatterCoder and 171 guests