OnMessage scroll counter

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
iilabs
Posts: 296
Joined: 07 Jun 2020, 16:57

OnMessage scroll counter

Post by iilabs » 03 Sep 2022, 08:44

Hi AHK world! Artemis 1 Launch today! :dance: Speaking of countdown....

I am trying to make a scroll counter but do not want to bind the scroll wheel and couldn't find one on the forum. So I tried windows messaging. I was able to get a tooltip counter, however met with two issues:

1. The count using Tooltip only shows up and counts when I hover over a GUI only. Can I have the script count regardless if I'm hovering over a GUI or not?

2. How can I make the counter subtract when I scroll up and add when I scroll down? I couldn't find an OnMessage specific to direction. I'm sure there is some kind of creative way? Some kind of state change?

Code: Select all

 
 MouseWheelCounter = 0
Onmessage(0x020A,"MouseWheel")

MouseWheel(){
MouseWheelCounter++
Tooltip,     %MouseWheelCounter%
SetTimer, RemoveToolTip, -1000
}
Return

RemoveToolTip:
ToolTip
return


Descolada
Posts: 1202
Joined: 23 Dec 2021, 02:30

Re: OnMessage scroll counter

Post by Descolada » 03 Sep 2022, 08:54

Why not use the non-blocking hotkeys?

Code: Select all

MouseWheelCounter = 0
~WheelUp::
~WheelDown::
    MouseWheelCounter++
    Tooltip, %MouseWheelCounter%
    SetTimer, RemoveToolTip, -1000

User avatar
iilabs
Posts: 296
Joined: 07 Jun 2020, 16:57

Re: OnMessage scroll counter

Post by iilabs » 03 Sep 2022, 17:33

That worked! Thank you, I forgot about that utility. That being said, are there any OnMessage for scroll up and down out of curiosity and any reason to use such?

Descolada
Posts: 1202
Joined: 23 Dec 2021, 02:30

Re: OnMessage scroll counter

Post by Descolada » 04 Sep 2022, 02:19

@iilabs, I'm not totally sure where OnMessage with WM_MOUSEWHEEL would be useful, perhaps when trying to detect scrolling in AHK windows better and in more detail? I haven't been able to use that message in other non-AHK windows.

Code: Select all

Gui, Show, w400 h400, Test GUI
OnMessage(0x020A, "WM_MOUSEWHEEL")
Return
GuiClose:
ExitApp

WM_MOUSEWHEEL(wParam, lParam, msg) {
   ToolTip, % "wParam loword: " (wParam & 0xffff)
   . "`nwParam hiword: " ((wParam>>16) & 0x8000 ? -((~wParam>>16)&0x7FFF)-1 : (wParam>>16)&0x7FFF)
}

User avatar
iilabs
Posts: 296
Joined: 07 Jun 2020, 16:57

Re: OnMessage scroll counter

Post by iilabs » 04 Sep 2022, 10:05

Thank you once again deacolada! Nice to see many ways to skin a cat.

teadrinker
Posts: 4412
Joined: 29 Mar 2015, 09:41
Contact:

Re: OnMessage scroll counter

Post by teadrinker » 04 Sep 2022, 13:33

Descolada wrote:

Code: Select all

((wParam>>16) & 0x8000 ? -((~wParam>>16)&0x7FFF)-1 : (wParam>>16)&0x7FFF)
All this is unnecessary since the >> operaror keeps the sign.

Descolada
Posts: 1202
Joined: 23 Dec 2021, 02:30

Re: OnMessage scroll counter

Post by Descolada » 04 Sep 2022, 13:36

teadrinker wrote:
04 Sep 2022, 13:33
Descolada wrote:

Code: Select all

((wParam>>16) & 0x8000 ? -((~wParam>>16)&0x7FFF)-1 : (wParam>>16)&0x7FFF)
All this is unnecessary since the >> operaror keeps the sign.
Please show how :)

teadrinker
Posts: 4412
Joined: 29 Mar 2015, 09:41
Contact:

Re: OnMessage scroll counter

Post by teadrinker » 04 Sep 2022, 13:37

Code: Select all

MsgBox, % -4 >> 1

Descolada
Posts: 1202
Joined: 23 Dec 2021, 02:30

Re: OnMessage scroll counter

Post by Descolada » 04 Sep 2022, 13:44

@teadrinker, try that with my example as well.

teadrinker
Posts: 4412
Joined: 29 Mar 2015, 09:41
Contact:

Re: OnMessage scroll counter

Post by teadrinker » 04 Sep 2022, 13:52

Hm, tested on Windows 7 before, now have tested on Windows 10, looks like wParam is interpreted as unsigned.
I was wrong. :) :oops:

teadrinker
Posts: 4412
Joined: 29 Mar 2015, 09:41
Contact:

Re: OnMessage scroll counter

Post by teadrinker » 04 Sep 2022, 20:01

But there is an easier way:

Code: Select all

Gui, Show, w400 h400, Test GUI
OnMessage(0x020A, "WM_MOUSEWHEEL")
Return
GuiClose:
ExitApp

WM_MOUSEWHEEL(wParam, lParam, msg) {
   ToolTip, % "wParam loword: " . wParam & 0xffff . "`n"
            . "wParam hiword: " . (wParam >> 31 ? -~wParam : wParam) >> 16
}
:)

User avatar
iilabs
Posts: 296
Joined: 07 Jun 2020, 16:57

Re: OnMessage scroll counter

Post by iilabs » 20 Jun 2023, 16:10

Thank you all. However I see that tooltip either presents as 24 or -24 can I use these values to increase or decrease scrollcount? I tried several iterations but couldn't get it running. Any clue where I went wrong?

Code: Select all


mousewheelcounter=0

Gui, Show, w400 h400, Test GUI
OnMessage(0x020A, "WM_MOUSEWHEEL")
Return
GuiClose:
ExitApp


WM_MOUSEWHEEL(wParam, lParam, msg) {
   ;Low := wParam & 0xffff . "`n"
   high := (wParam >> 31 ? -~wParam : wParam) >> 16

   if high > 1
    MouseWheelCounter--

   if high < 1
    MouseWheelCounter++

   tooltip, % MouseWheelCounter

}

teadrinker
Posts: 4412
Joined: 29 Mar 2015, 09:41
Contact:

Re: OnMessage scroll counter

Post by teadrinker » 20 Jun 2023, 17:38

I'm not quite sure what 24 and -24 that you're talking about, but maybe you should make the MouseWheelCounter variable global or static.

User avatar
iilabs
Posts: 296
Joined: 07 Jun 2020, 16:57

Re: OnMessage scroll counter

Post by iilabs » 21 Jun 2023, 08:09

Those two numbers is what I get when I run the code above and use scroll. When I scroll up it’s -24 and when I scroll down it’s 24. Should they be incrementing instead?

teadrinker
Posts: 4412
Joined: 29 Mar 2015, 09:41
Contact:

Re: OnMessage scroll counter

Post by teadrinker » 21 Jun 2023, 10:28

iilabs wrote: When I scroll up it’s -24 and when I scroll down it’s 24.
Hmm, but there is nothing in the script you posted that would cause this result. In any case, try to do what I advised.

User avatar
iilabs
Posts: 296
Joined: 07 Jun 2020, 16:57

Re: OnMessage scroll counter

Post by iilabs » 21 Jun 2023, 13:08

Ok will do. Are you getting different results from the code you posted other than -24 and 24 when moving the mouse wheel? Just want to make sure it’s not something else I might need to fix.

teadrinker
Posts: 4412
Joined: 29 Mar 2015, 09:41
Contact:

Re: OnMessage scroll counter

Post by teadrinker » 21 Jun 2023, 14:24

For me my code shows
wParam loword: 8
wParam hiword: -120
and
wParam loword: 8
wParam hiword: 120
yours -1 and 1.

Post Reply

Return to “Ask for Help (v1)”