Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

getkeystate wheel (Getkeystate not wheely good!)


  • Please log in to reply
7 replies to this topic
Muzzi
  • Members
  • 111 posts
  • Last active: Dec 15 2013 03:54 AM
  • Joined: 15 Jun 2008
Can getkeystate work somehow on the mouse wheel?
Is there a code for an ambiguous up or down wheel motion?

I have tried wheeldown with no joy.


SetTimer Loop, 100

Loop:
GetKeyState, WheelState, WheelDown  ; < is this right?
If WheelState = D      ; < and this
{
msgBox you sent the wheel down
}
Return

I have searched the forum with nothing found on this so any tips would be appreciated.

Cheers

VxE
  • Moderators
  • 3622 posts
  • Last active: Dec 24 2015 02:21 AM
  • Joined: 07 Oct 2006
Is this a joke? The mousewheel doesn't have a state. Unless you write your own software to keep track of how many wheelup/down messages, you won't ever be able to get the wheel's keystate.

You can try some code like this to keep a looping counter of
; The variable %WheelState% will be between 0 and 11, inclusive
~*WheelDown:: ; this hotkey should 'fall through' to the WheelUp part
WheelState+=-2
~*WheelUp::WheelState:=Mod(0 WheelState+13,12)

^!w::msgbox % "example:`nSend {F" WheelState+1 "}"


Muzzi
  • Members
  • 111 posts
  • Last active: Dec 15 2013 03:54 AM
  • Joined: 15 Jun 2008
No this is not a joke... although curious... and thanks VxE for the reply.

So how does the mouse wheel know its direction when it performs the usual up/down scrolling within a window?

In other words if it can sense with its internal optical encoder and translate that into a code to recognize its direction, then why cannot it be translated into a up/down recognition for AHK's getkeystate? ...just a thought.

I will give your code a whirl... and get back when I do.

Muzzi
  • Members
  • 111 posts
  • Last active: Dec 15 2013 03:54 AM
  • Joined: 15 Jun 2008
Ultimately what I need is a way to sense any (up or down) action of the mouse wheel to trigger a code to perform another task.

If getkeystate works for button action sensing then is there a command to sense the action of the mouse wheel?

VxE
  • Moderators
  • 3622 posts
  • Last active: Dec 24 2015 02:21 AM
  • Joined: 07 Oct 2006

The grand old Duke of York,
He had ten thousand men.
He marched them up to the top of the hill
And he marched them down again.

And when they're up, they're up;
And when they're down, they're down.
But when they're only halfway up,
They're neither up nor down!


The thing is, the mousewheel does not have an up or a down state, it is always in the middle. Why? well, because no matter how far up you scroll it, you can continue to scroll it upwards (Sisyphus). The mouse generates the signal once for each scroll 'tick'.

Unlike keys on the keyboard, which trigger a signal both when pressed and when released, the mousewheel has no 'release' signal. As for getting something like the wheel's absolute orientation.... I don't think that feature is available in mice at all...

Muzzi
  • Members
  • 111 posts
  • Last active: Dec 15 2013 03:54 AM
  • Joined: 15 Jun 2008

But when they're only halfway up,
They're neither up nor down!

I'm not from the U.S. but I do know the tune... it sounds much like me. When I have a good idea I get up and when it goes wrong I get down. :(

Thanks VxE.. now I understand. :wink:

scottmeyer
  • Members
  • 19 posts
  • Last active: Jun 16 2011 09:11 PM
  • Joined: 29 Jul 2007
One solution for replace "GetKeystate, WheelDown and WheelUp"

Thank to Vxe for your idea

Insert in your code :
#NoEnv
#InstallMouseHook

; variable
EtatWheelDown = 1
EtatWheelUp = 1
Check_EtatWheelDown = 1
Check_EtatWheelUp = 1

Loop,  ; ( or SetTimer )
{
   if EtatWheelDown <> %Check_EtatWheelDown%  ; Wheel Down is turn
   {
      Tooltip, Wheel Down is turn.
      Break
   }

   if EtatWheelUp <> %Check_EtatWheelUp%  ; Wheel Up is turn
   {
      Tooltip, Wheel Up is turn.
      Break
   }
   Check_EtatWheelDown = %EtatWheelDown%
   Check_EtatWheelUp = %EtatWheelUp%
}

~*WheelDown::
EtatWheelDown += 1
return

~*WheelUp::
EtatWheelUp += 1
return

bye ^^

thebunnyrules
  • Members
  • 15 posts
  • Last active: Jun 09 2017 02:26 AM
  • Joined: 09 Jan 2015

Good script, Scott, but it wouldn't keep accurate track of wheel movement if unless you put the resets (Check_EtatWheelDown/Up = %EtatWheelDown/Up%) within the if statements. If you want the script to keep constant track of wheel movement (maybe you don't, I don't know), you'd need to take out the break statement in the loop.

#NoEnv
#InstallMouseHook

; variable
EtatWheelDown = 1
EtatWheelUp = 1
Check_EtatWheelDown = 1
Check_EtatWheelUp = 1

Loop,  ; ( or SetTimer )
{
   if EtatWheelDown <> %Check_EtatWheelDown%  ; Wheel Down is turn
   {
      Check_EtatWheelDown = %EtatWheelDown%	
      ToolTip, Wheel Down is turn.
      ;Break
   }

   if EtatWheelUp <> %Check_EtatWheelUp%  ; Wheel Up is turn
   { 
	  Check_EtatWheelUp = %EtatWheelUp%	
      ToolTip, Wheel Up is turn.
      ;Break
   }
   
   
}

~*WheelDown::
EtatWheelDown += 1
return

~*WheelUp::
EtatWheelUp += 1
return