Mouse Move Left Send K, Mouse Move Left Send H Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
wyw
Posts: 93
Joined: 12 Dec 2015, 19:11

Mouse Move Left Send K, Mouse Move Left Send H

09 Nov 2018, 05:51

Here is the script:

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
Timer_State =0 ; off

esc::exitapp
#IfWinActive, DX31
e::
  Timer_State := !Timer_State ; toggle 0 or 1
  If Timer_State =1
    SetTimer, trigger1, 10 
  Else
    SetTimer, trigger1, Off
return 

trigger1: 
  Critical ; doesn't interrupt this thread with other timers
  Mousegetpos, x 
  sleep 5 
  mousegetpos, x2 
  if x2 != %x% 
    {
    tooltip, clicked ; delete this line if you don't want notification - useful for testing
    sleep 111
    send, K
	sleep 111
    send, H
    tooltip
    }
return 
F7::ExitApp
CapsLock::Suspend
F4::Reload
The script does exactly what I want it to do, well, almost. What it does: It sends K and H if you move your mouse, even if it's just a little bit.

Here comes the thing (not sure if AutoHotKey allows this):

I want it to behave like this, that if you move your mouse to the left, it will send K (only), now if you move your mouse to the left again, it should not send K until you move your mouse to the right, which will then send H (only). Same goes for the right side. Move your mouse to the right, send H, move your mouse to the right again, don't send anything until mouse has been moved to the left side. That means that AutoHotKey should somehow detect whether you moved to the left or right. Is that possible?


You should get the following results:

Move Mouse Left = Left Side
Move Mouse Right = Right Side



Left Side - K
Left Side -

Right Side - H
Right Side -

Or:

Left Side - K
Right Side - H
Left Side - K
Left Side -
Right Side - H
Left Side - K
Right Side - H
Right Side -


I hope my explanation is as detailed as possible. I also hope that this is possible somehow!
Rohwedder
Posts: 7610
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Mouse Move Left Send K, Mouse Move Left Send H  Topic is solved

09 Nov 2018, 12:09

Hallo,
try:

Code: Select all

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
Left := 0, Right := 0, Timer_State := 0 ; off 
esc::exitapp
#IfWinActive, DX31
e::
Mousegetpos, xold
If Timer_State := !Timer_State ; toggle 0 or 1
	SetTimer, trigger1, 50
Else
	SetTimer, trigger1, Off
return
trigger1:
Critical ; doesn't interrupt this thread with other timers
Mousegetpos, x
If (x > xold)
{
	Left := 0
	If !Right++
		Send, H
}
Else If (x < xold)
{
	Right := 0
	If !Left++
		Send, K
}
xold := x
return
F7::ExitApp
CapsLock::Suspend
F4::Reload
wyw
Posts: 93
Joined: 12 Dec 2015, 19:11

Re: Mouse Move Left Send K, Mouse Move Left Send H

09 Nov 2018, 12:59

Rohwedder wrote:
09 Nov 2018, 12:09
Hallo,
try:

Code: Select all

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
Left := 0, Right := 0, Timer_State := 0 ; off 
esc::exitapp
#IfWinActive, DX31
e::
Mousegetpos, xold
If Timer_State := !Timer_State ; toggle 0 or 1
	SetTimer, trigger1, 50
Else
	SetTimer, trigger1, Off
return
trigger1:
Critical ; doesn't interrupt this thread with other timers
Mousegetpos, x
If (x > xold)
{
	Left := 0
	If !Right++
		Send, H
}
Else If (x < xold)
{
	Right := 0
	If !Left++
		Send, K
}
xold := x
return
F7::ExitApp
CapsLock::Suspend
F4::Reload

Wow, I really did NOT expect that. Respect. Working like a charm! :D


Thanks alot!
User avatar
TLM
Posts: 1608
Joined: 01 Oct 2013, 07:52
Contact:

Re: Mouse Move Left Send K, Mouse Move Left Send H

09 Nov 2018, 13:55

I sometimes use this `magic` to push values an updating value to an array with 2 keys in a loop: xPosArr[ mod( a_index-1, 2 )+1 ]
key 1 being the current value and key 2 being the previous value.

Here it is applied to your question ( on line 12 ):
wyw
Posts: 93
Joined: 12 Dec 2015, 19:11

Re: Mouse Move Left Send K, Mouse Move Left Send H

09 Nov 2018, 16:39

TLM wrote:
09 Nov 2018, 13:55
I sometimes use this `magic` to push values an updating value to an array with 2 keys in a loop: xPosArr[ mod( a_index-1, 2 )+1 ]
key 1 being the current value and key 2 being the previous value.

Here it is applied to your question ( on line 12 ):
Hey TLM, pretty interesting stuff what you got right there. I saved it just incase.

Thanks!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Rohwedder and 252 guests