Holding mouse in a region activates something. I have a script ready but it activates instantly while I want to hold 1st

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
brecht2202
Posts: 31
Joined: 17 Mar 2019, 15:12

Holding mouse in a region activates something. I have a script ready but it activates instantly while I want to hold 1st

Post by brecht2202 » 05 Dec 2021, 20:36

So I got a script that does a few things like switching Virtual desktop when mouse touches region in left or right edge or screen. This script works but I want it to only activate if I keep my mouse at the edge for 0,75 seconds (750 ticks) and not instantly.

I can change the time with

Code: Select all

switchDeskTime	:= 750
but if I touch the edge for like 1 single tick and my mouse leaves the region before the 750 ticks are over, it still activates. I could set the timer to 5 seconds (5000) and tap the edge once and then have mouse in the middle of the screen and 5 seconds later the virtual desktop will switch. This shouldn't happen.

It's part of a bigger script so I'm only gonna put a part of the code here.

This is the declaration

Code: Select all

; Standard:	L: 2   R: 1918   T: 680   B: 170
switchDeskLeft 	:= 2					; From the left
switchDeskRight := A_ScreenWidth - switchDeskLeft	; 
switchDeskTop 	:= 680					; From the top ; Do 1080-Height you want, type result here
switchDeskBottom:= A_ScreenHeight - 170		; From the bottom

switchDeskTime	:= 750					; CHOOSE Switch Desktop TIME HERE
And this is the code.

Code: Select all

SetTimer, Check, 100
Check:
CoordMode, Mouse
MouseGetPos, mx, my
last := zone, zone := mx <= switchDeskLeft && my >= switchDeskTop && my <= switchDeskBottom ? 1 
		   : mx >= switchDeskRight && my >= switchDeskTop && my <= switchDeskBottom ? 2 
		   : mx >= timelineLeft && mx <= timelineRight && my >= timelineTop && my >= timelineBottom ? 3
		   : mx >= alttabLeft && mx <= alttabRight && my >= alttabTop && my >= alttabBottom ? 4
		   : 0

If !zone || last = "" || zone = last
 Return
Switch zone {
 Case 1: 
		Sleep %switchDeskTime%
		If (mx <= switchDeskLeft && my >= switchDeskTop && my <= switchDeskBottom)
		{
			SendInput #^{Left}
		}
 Case 2: 
		Sleep %switchDeskTime%
		If (mx >= switchDeskRight && my >= switchDeskTop && my <= switchDeskBottom)
		{
			SendInput #^{Right}
		}

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Holding mouse in a region activates something. I have a script ready but it activates instantly while I want to hold

Post by mikeyww » 05 Dec 2021, 20:49

When the mouse first hits the edge, start a timer with a frequency of -750. Set the timed subroutine to execute your action. When the mouse leaves the edge, turn off the timer.

brecht2202
Posts: 31
Joined: 17 Mar 2019, 15:12

Re: Holding mouse in a region activates something. I have a script ready but it activates instantly while I want to hold

Post by brecht2202 » 05 Dec 2021, 21:12

I don't really understand how to do that.

I set timer to 2000 to test more easily. This is what I got right now. Is it possible to do it without the mouse having to leave the region? I want it so that if I have multiple desktops open I can just hold the mouse at the edge and every 0,75seconds it will switch to the following desktop.

Code: Select all

switchDeskTime	:= 2000					; CHOOSE Switch Desktop TIME HERE

Code: Select all

Switch zone {
 Case 1: 
		SetTimer, switchDeskLeftTimer, -%switchDeskTime%
		switchDeskLeftTimer:
		SendInput #^{Left}
		SetTimer, switchDeskLeftTimer, Off
		/*
		Sleep %switchDeskTime%
		If (mx <= switchDeskLeft && my >= switchDeskTop && my <= switchDeskBottom)
		{
			SendInput #^{Left}
		}
		*/

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Holding mouse in a region activates something. I have a script ready but it activates instantly while I want to hold

Post by mikeyww » 05 Dec 2021, 21:39

Here is an example that you can test.

Code: Select all

#Persistent
Process, Priority,, B
SetTimer, Check, 50
Check:
CoordMode, Mouse
MouseGetPos, x
last := edge, edge := x < 30, start := last & edge ? start : A_TickCount
If (A_TickCount - start > 749)
 MsgBox, 64, Done, Boom!, 0.5
Return

brecht2202
Posts: 31
Joined: 17 Mar 2019, 15:12

Re: Holding mouse in a region activates something. I have a script ready but it activates instantly while I want to hold

Post by brecht2202 » 05 Dec 2021, 21:52

This code works after changing 2 things.
The SetTimer "Check" name (Duplicate label with the first mouse position check).
I also had a problem that after the 749 ticks it would just immediately repeat the SendInput #^{Left} command without a delay. So all I had to do was add a Sleep command before the return.

Now it works! Thanks a lot!!! :D

This is the code:

Code: Select all

Switch zone {
 Case 1: 
		
		Process, Priority,, B
		SetTimer, switchDeskLeftTimerCheck, 50
		switchDeskLeftTimerCheck:
		CoordMode, Mouse
		MouseGetPos, x
		last := edge, edge := x < 30, start := last & edge ? start : A_TickCount
		If (A_TickCount - start > 749)
		 ; MsgBox, 64, Done, Boom!, 0.5
		 SendInput #^{Left}
		 Sleep 500
		Return

brecht2202
Posts: 31
Joined: 17 Mar 2019, 15:12

Re: Holding mouse in a region activates something. I have a script ready but it activates instantly while I want to hold

Post by brecht2202 » 05 Dec 2021, 22:06

actually I've ran into another problem.

The way that code is setup is having the time inside of the code like this and that works:

Code: Select all

If (A_TickCount - start > 750)
but I want to have it like this:

Code: Select all

switchDeskTimer			:= 750			; CHOOSE Switch Desktop TIME HERE
switchDeskTimerDelay	:= 500

Code: Select all

		Process, Priority,, B
		SetTimer, switchDeskLeftTimerCheck, 50
		switchDeskLeftTimerCheck:
		CoordMode, Mouse
		MouseGetPos, x
		last := edge, edge := x < 30, start := last & edge ? start : A_TickCount
		If (A_TickCount - start > %switchDeskTimer%)	; %switchDeskTimer% instead of 750 --- PROBLEM LAYS HERE
		 ; MsgBox, 64, Done, Boom!, 0.5
		 SendInput #^{Left}
		 Sleep %switchDeskTimerDelay%
		Return
This way I can use a variable at the start of the script with the rest of the declarations so I can easily change it in one place. But if I switch 750 in the code to %switchDeskTimer% it kind of infinitely activates the script immediately.
I find weird since
Sleep %switchDeskTimerDelay%
does work.

How can I change the 750 in the code to %switchDeskTimer%

brecht2202
Posts: 31
Joined: 17 Mar 2019, 15:12

Re: Holding mouse in a region activates something. I have a script ready but it activates instantly while I want to hold

Post by brecht2202 » 05 Dec 2021, 22:17

I also have an issue with the region with the second check.

In your example you used x=30 but I have a region I want to check.

I tried changing Last and Zone so it doesn't have duplicate labels but it doesn't work anymore.

This is the code right now:

Code: Select all

; Standard:	L: 2   R: 1918   T: 680   B: 170
switchDeskLeft 	:= 2					; From the left
switchDeskRight := A_ScreenWidth - switchDeskLeft	; 
switchDeskTop 	:= 680					; From the top ; Do 1080-Height you want, type result here
switchDeskBottom:= A_ScreenHeight - 170		; From the bottom

switchDeskTimer			:= 750			; CHOOSE Switch Desktop TIME HERE
switchDeskTimerDelay	:= 500

Code: Select all

SetTimer, Check, 100
Check:
CoordMode, Mouse
MouseGetPos, mx, my
last := zone, zone := mx <= switchDeskLeft && my >= switchDeskTop && my <= switchDeskBottom ? 1 
		   : mx >= switchDeskRight && my >= switchDeskTop && my <= switchDeskBottom ? 2 
		   : mx >= timelineLeft && mx <= timelineRight && my >= timelineTop && my >= timelineBottom ? 3
		   : mx >= alttabLeft && mx <= alttabRight && my >= alttabTop && my >= alttabBottom ? 4
		   : 0

If !zone || last = "" || zone = last
 Return
Switch zone {
 Case 1: 
		Process, Priority,, B
		SetTimer, SwitchDeskLeftTimerCheck, 50
		SwitchDeskLeftTimerCheck:
		CoordMode, Mouse
		MouseGetPos, x
		lastSDL := zoneSDL, zoneSDL := mx <= switchDeskLeft && my >= switchDeskTop && my <= switchDeskBottom, start := lastSDL & edge ? start : A_TickCount
		If (A_TickCount - start > 750)	; %switchDeskTimer%
		 ; MsgBox, 64, Done, Boom!, 0.5
		 SendInput #^{Left}
		 Sleep %switchDeskTimerDelay%
		Return
		
		/*
		Sleep %switchDeskTime%
		If (mx <= switchDeskLeft && my >= switchDeskTop && my <= switchDeskBottom)
		{
			SendInput #^{Left}
		}
		*/
		
		; SendInput #^{Left}
 Case 2: 
 		Process, Priority,, B
		SetTimer, SwitchDeskRightTimerCheck, 50
		SwitchDeskRightTimerCheck:
		CoordMode, Mouse
		MouseGetPos, x
		lastSDR := zoneSDR, zoneSDR := mx >= switchDeskRight && my >= switchDeskTop && my <= switchDeskBottom, start := lastSDR & edge ? start : A_TickCount
		If (A_TickCount - start > 750)	; %switchDeskTimer%
		 ; MsgBox, 64, Done, Boom!, 0.5
		 SendInput #^{Right}
		 Sleep %switchDeskTimerDelay%
		Return
Last edited by brecht2202 on 05 Dec 2021, 22:18, edited 1 time in total.

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Holding mouse in a region activates something. I have a script ready but it activates instantly while I want to hold

Post by mikeyww » 05 Dec 2021, 22:18

Remove % inside the parentheses, because If uses expressions.

If your Sleep is meant to be part of a block under If, then use braces around the block.

If the various zones are important, then you will need to add conditional statements that indicate what you want, such as whether the time in a single zone has exceeded some threshold. That is how my demonstration works. When the mouse first enters the zone, it marks the time. With each timer cycle, the script then checks to see whether the time elapsed exceeds the threshold. You may seek some variation of this approach.

brecht2202
Posts: 31
Joined: 17 Mar 2019, 15:12

Re: Holding mouse in a region activates something. I have a script ready but it activates instantly while I want to hold

Post by brecht2202 » 05 Dec 2021, 22:41

I've been thinking of how to go about that and I simply can't wrap my head around on what the statements should be. Also the treshold itself aswell.

Side Question:
When I change this in the first case:

Code: Select all

last := edge, edge := x < 30, start := last & edge ? start : A_TickCount
To this:

Code: Select all

lastSDL := edgeL, edgeL := x < 30, startL := lastSDL & edgeL ? startL : A_TickCount
and change this in the second case:

Code: Select all

last := edge, edge := x > 1890, start := last & edge ? start : A_TickCount
To this:

Code: Select all

lastSDR := edgeR, edgeR := x > 1890, startR := lastSDR & edgeR ? startR : A_TickCount
It also don't work anymore


With the following code I got right now I can go to the right multiple times like it should but then if I go to the left it only works once and then both sides dont work anymore. This also happens when going to the left first and then go to the right.

This is the code right now:

Code: Select all

If !zone || last = "" || zone = last
 Return
Switch zone {
 Case 1: 
		Process, Priority,, B
		SetTimer, SwitchDeskLeftTimerCheck, 50
		SwitchDeskLeftTimerCheck:
		CoordMode, Mouse
		MouseGetPos, x		
		last := edge, edge := x < 30, start := last & edge ? start : A_TickCount
		; lastSDL := edgeL, edgeL := x < 30, startL := lastSDL & edgeL ? startL : A_TickCount
		; lastSDL := zoneSDL, zoneSDL := mx <= switchDeskLeft && my >= switchDeskTop && my <= switchDeskBottom, start := lastSDL & edge ? start : A_TickCount
		If (A_TickCount - start > switchDeskTimer)	; %switchDeskTimer%
		 ; MsgBox, 64, Done, Boom!, 0.5
		 SendInput #^{Left}
		 Sleep %switchDeskTimerDelay%
		Return
		
		/*
		Sleep %switchDeskTime%
		If (mx <= switchDeskLeft && my >= switchDeskTop && my <= switchDeskBottom)
		{
			SendInput #^{Left}
		}
		*/
		
		; SendInput #^{Left}
 Case 2: 
 		Process, Priority,, B
		SetTimer, SwitchDeskRightTimerCheck, 50
		SwitchDeskRightTimerCheck:
		CoordMode, Mouse
		MouseGetPos, x
		last := edge, edge := x > 1890, start := last & edge ? start : A_TickCount
		; lastSDR := edgeR, edgeR := x > 1890, startR := lastSDR & edgeR ? startR : A_TickCount
		; lastSDR := zoneSDR, zoneSDR := mx >= switchDeskRight && my >= switchDeskTop && my <= switchDeskBottom, start := lastSDR & edge ? start : A_TickCount
		If (A_TickCount - start > switchDeskTimer)	; %switchDeskTimer%
		 ; MsgBox, 64, Done, Boom!, 0.5
		 SendInput #^{Right}
		 Sleep %switchDeskTimerDelay%
		Return
		
		/*
		Sleep %switchDeskTime%
		If (mx >= switchDeskRight && my >= switchDeskTop && my <= switchDeskBottom)
		{
			SendInput #^{Right}
		}
		*/
		
		; SendInput #^{Right}

brecht2202
Posts: 31
Joined: 17 Mar 2019, 15:12

Re: Holding mouse in a region activates something. I have a script ready but it activates instantly while I want to hold

Post by brecht2202 » 05 Dec 2021, 22:56

Ok so this is the code right now. (A little bit cleaned up)
This has 2 issues:
- It kind of works but I don't know how to make it use the region instead of the edge.
- When going to one side it works but if I then go to the other side it only works once and then both sides don't work anymore

Code: Select all

If !zone || last = "" || zone = last
 Return
Switch zone {
 Case 1: 
		Process, Priority,, B
		SetTimer, SwitchDeskLeftTimerCheck, 50
		SwitchDeskLeftTimerCheck:
		CoordMode, Mouse
		MouseGetPos, x		
		lastL := edgeL, edgeL := x < 30, start := lastL & edgeL ? start : A_TickCount
		; lastSDL := edgeL, edgeL := x < 30, startL := lastSDL & edgeL ? startL : A_TickCount
		; lastSDL := zoneSDL, zoneSDL := mx <= switchDeskLeft && my >= switchDeskTop && my <= switchDeskBottom, start := lastSDL & edge ? start : A_TickCount
		If (A_TickCount - start > switchDeskTimer)	; %switchDeskTimer%
		 ; MsgBox, 64, Done, Boom!, 0.5
		 SendInput #^{Left}
		 Sleep %switchDeskTimerDelay%
		Return
		

 Case 2: 
 		Process, Priority,, B
		SetTimer, SwitchDeskRightTimerCheck, 50
		SwitchDeskRightTimerCheck:
		CoordMode, Mouse
		MouseGetPos, x
		lastR := edgeR, edgeR := x > 1890, start := lastR & edgeR ? start : A_TickCount
		; lastSDR := edgeR, edgeR := x > 1890, startR := lastSDR & edgeR ? startR : A_TickCount
		; lastSDR := zoneSDR, zoneSDR := mx >= switchDeskRight && my >= switchDeskTop && my <= switchDeskBottom, start := lastSDR & edge ? start : A_TickCount
		If (A_TickCount - start > switchDeskTimer)	; %switchDeskTimer%
		 ; MsgBox, 64, Done, Boom!, 0.5
		 SendInput #^{Right}
		 Sleep %switchDeskTimerDelay%
		Return


Also, in the conditional statements this code with edge works:

Code: Select all

lastL := edgeL, edgeL := x < 30, start := lastL & edgeL ? start : A_TickCount
while this code with regions doesn't work at all:

Code: Select all

lastSDL := zoneSDL, zoneSDL := mx <= switchDeskLeft && my >= switchDeskTop && my <= switchDeskBottom, start := lastSDL & edge ? start : A_TickCount
Why does this not work, and how can I fix this?

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Holding mouse in a region activates something. I have a script ready but it activates instantly while I want to hold

Post by mikeyww » 06 Dec 2021, 05:13

An example of using left & right edges is below.

Code: Select all

#Persistent
Process, Priority,, B
margin    := 30                                    ; Maximum distance from edge
threshold := 750                                   ; Minimum time to trigger
timer     := 50                                    ; Frequency of check
SetTimer, Check, %timer%
Check:
CoordMode, Mouse
MouseGetPos, x
last := zone                                       ; Previous zone
Switch                                             ; Define whatever zones you need
{ Case x <= margin                : zone := 1      ; Left edge
  Case x >= A_ScreenWidth - margin: zone := 2      ; Right edge
  Default                         : zone := 0      ; Middle
}
start := last && last = zone ? start : A_TickCount ; Update if zone changed or is middle
If (A_TickCount - start < threshold)               ; Threshold has not been met
 Return
Switch zone {                                      ; Act according to zone
 Case 1: MsgBox, 48, Boom!, Southpaw!, 1           ; Left edge
 Case 2: MsgBox, 64, Boom!, Righty!, 1             ; Right edge
}
Sleep, threshold - timer                           ; Wait a little while before the next check
Return

brecht2202
Posts: 31
Joined: 17 Mar 2019, 15:12

Re: Holding mouse in a region activates something. I have a script ready but it activates instantly while I want to hold

Post by brecht2202 » 06 Dec 2021, 09:05

Hey,

This code does work but I'm still left with the region problem and I had a variable wich had a separate Delay variable wich doesn't work.

The switchDeskTimerDelay works like this:
1. When mouse is within region the threshold timer variable runs
2. When threshold timer has run out it activates the case (so sends the command/msgbox)
3. The last sleep command has the switchDeskTimerDelay wich is kinda the new threshold aslong as my mouse is in the region/edge.


I have 4 cases since In the full program I have it so there's a 3rd case with a region on the left side of the taskbar that activates Win+Tab and a 4th case with a region on the right side of the taskbar wich activates AltTab. Case 3 and 4 are fully done and working. I just say this so you know that I need to be able to add more regions than only those 2.

The region problem I mean is that I have multiple more cases with multiple regions where I have set a variable for every direction each time (Left, Right, Top, Bottom).
Everytime the region variables are setup like this so I can always easily choose where I want the region to be:

Code: Select all

; --------- --------- --------- --------- --------- --------- --------- 
; Standard:	L: 2   R: 1918   T: 680   B: 170
switchDeskLeft 	:= 2					; From the left
switchDeskRight := A_ScreenWidth - switchDeskLeft	; 
switchDeskTop 	:= 680					; From the top ; Do 1080-Height you want, type result here
switchDeskBottom:= A_ScreenHeight - 170		; From the bottom

switchDeskTimer			:= 750			; CHOOSE Switch Desktop TIME HERE
switchDeskTimerDelay	:= 500
; --------- --------- --------- --------- --------- --------- --------- 
; Standard:	L: 200   R: 720 (1920-720=1200)   T: 40   B: 0
timelineLeft	:= 200				; From the left
timelineRight	:= A_ScreenWidth - 1200		; From the right ; 1920-Width you want, type result here
timelineTop	:= A_ScreenHeight - 40		; From the bottom
timelineBottom	:= 0				; From the bottom
; --------- --------- --------- --------- --------- --------- --------- 
; Standard:	L: 1100   R: 1675 (1920-1675=245)   T: 40   B: 0
alttabLeft	:= 1100				; From the left
alttabRight	:= A_ScreenWidth - 245		; From the right ; 1920-Width you want, type result here
alttabTop	:= A_ScreenHeight - 40		; From the bottom
alttabBottom	:= 0				; From the bottom

Before the Switch zone with the cases I have this code running to send the left region to case 1, right region to case 2, LeftsideTaskbar region to case 3 and RightsideTaskbar region to case 4.

Code: Select all

SetTimer, Check, 100
Check:
CoordMode, Mouse
MouseGetPos, mx, my
last := zone, zone := mx <= switchDeskLeft && my >= switchDeskTop && my <= switchDeskBottom ? 1 
		   : mx >= switchDeskRight && my >= switchDeskTop && my <= switchDeskBottom ? 2 
		   : mx >= timelineLeft && mx <= timelineRight && my >= timelineTop && my >= timelineBottom ? 3
		   : mx >= alttabLeft && mx <= alttabRight && my >= alttabTop && my >= alttabBottom ? 4
		   : 0

If !zone || last = "" || zone = last
 Return



I just can't find out how to make the new cases work with the multiple conditions:

Code: Select all

mx <= switchDeskLeft && my >= switchDeskTop && my <= switchDeskBottom      ; Left edge
mx >= switchDeskRight && my >= switchDeskTop && my <= switchDeskBottom      ; Right edge
mx >= timelineLeft && mx <= timelineRight && my >= timelineTop && my >= timelineBottom	; Leftside Taskbar
mx >= alttabLeft && mx <= alttabRight && my >= alttabTop && my >= alttabBottom	; Rightside Taskbar
instead of only:

Code: Select all

x <= margin
x >= A_ScreenWidth - margin

I tried replacing this code:

Code: Select all

{ Case x <= margin                : zone := 1      ; Left edge
  Case x >= A_ScreenWidth - margin: zone := 2      ; Right edge
With this code to not use the entire edge but only my regions:

Code: Select all

{ Case mx <= switchDeskLeft && my >= switchDeskTop && my <= switchDeskBottom	: zone := 1      ; Left edge
  Case mx >= switchDeskRight && my >= switchDeskTop && my <= switchDeskBottom	: zone := 2      ; Right edge
Now it doesn't react anymore.






Here is the code right now:

Code: Select all


; Standard:	L: 2   R: 1918   T: 680   B: 170
switchDeskLeft 	:= 2					; From the left
switchDeskRight := A_ScreenWidth - switchDeskLeft	; 
switchDeskTop 	:= 680					; From the top ; Do 1080-Height you want, type result here
switchDeskBottom:= A_ScreenHeight - 170		; From the bottom

switchDeskTimer			:= 750			; CHOOSE Switch Desktop TIME HERE (first activation)
switchDeskTimerDelay		:= 500			; After the first activation

; ===

Process, Priority,, B
margin    := 30                                    ; Maximum distance from edge
threshold := 750                                   ; Minimum time to trigger
timer     := 50                                    ; Frequency of check
switchDeskTimerDelay		:= 500		   ; After the first activation
SetTimer, Check, %timer%
Check:
CoordMode, Mouse
MouseGetPos, x
last := zone                                       ; Previous zone
Switch                                             ; Define whatever zones you need
{ Case mx <= switchDeskLeft && my >= switchDeskTop && my <= switchDeskBottom	: zone := 1      ; Left edge
  Case mx >= switchDeskRight && my >= switchDeskTop && my <= switchDeskBottom	: zone := 2      ; Right edge
;{ Case x <= margin                : zone := 1      ; Left edge
;  Case x >= A_ScreenWidth - margin: zone := 2      ; Right edge
  Default                         : zone := 0      ; Middle
}
start := last && last = zone ? start : A_TickCount ; Update if zone changed or is middle
If (A_TickCount - start < threshold)               ; Threshold has not been met
 Return
Switch zone {                                      ; Act according to zone
 Case 1: MsgBox, 48, Boom!, Southpaw!, 1           ; Left edge
 Case 2: MsgBox, 64, Boom!, Righty!, 1             ; Right edge
}
Sleep, %switchDeskTimerDelay% - timer                           ; Wait a little while before the next check
Return
This is the ENTIRE code of the program before you send your last code:
https://pastebin.com/g4J4zunw

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Holding mouse in a region activates something. I have a script ready but it activates instantly while I want to hold

Post by mikeyww » 06 Dec 2021, 09:16

It looks to me like you have not defined mx in your script.

While you are testing, I recommend using a margin larger than 2 pixels. I would try 20 for your testing.

brecht2202
Posts: 31
Joined: 17 Mar 2019, 15:12

Re: Holding mouse in a region activates something. I have a script ready but it activates instantly while I want to hold

Post by brecht2202 » 06 Dec 2021, 09:21

I have mx defined here:

Code: Select all

SetTimer, Check, 100
Check:
CoordMode, Mouse
MouseGetPos, mx, my
last := zone, zone := mx <= switchDeskLeft && my >= switchDeskTop && my <= switchDeskBottom ? 1 
		   : mx >= switchDeskRight && my >= switchDeskTop && my <= switchDeskBottom ? 2 
		   : mx >= timelineLeft && mx <= timelineRight && my >= timelineTop && my >= timelineBottom ? 3
		   : mx >= alttabLeft && mx <= alttabRight && my >= alttabTop && my >= alttabBottom ? 4
		   : 0

If !zone || last = "" || zone = last
 Return
 
The mx and my does work since case 3 and 4 also work only in the correct regions.

Also, I'll try 20 pixels for testing.

But any idea on how to make the new cases work with these multiple conditions:

Code: Select all

mx <= switchDeskLeft && my >= switchDeskTop && my <= switchDeskBottom      ; Left edge
mx >= switchDeskRight && my >= switchDeskTop && my <= switchDeskBottom      ; Right edge
mx >= timelineLeft && mx <= timelineRight && my >= timelineTop && my >= timelineBottom	; Leftside Taskbar
mx >= alttabLeft && mx <= alttabRight && my >= alttabTop && my >= alttabBottom	; Rightside Taskbar
instead of only:

Code: Select all

x <= margin
x >= A_ScreenWidth - margin

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Holding mouse in a region activates something. I have a script ready but it activates instantly while I want to hold

Post by mikeyww » 06 Dec 2021, 09:25

I'm not seeing the whole script here. Your previous one did not define mx in what was posted.

brecht2202
Posts: 31
Joined: 17 Mar 2019, 15:12

Re: Holding mouse in a region activates something. I have a script ready but it activates instantly while I want to hold

Post by brecht2202 » 06 Dec 2021, 09:32

I had added this to last comment.
Here:
This is the ENTIRE code of the program before you send your last code:
https://pastebin.com/g4J4zunw

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Holding mouse in a region activates something. I have a script ready but it activates instantly while I want to hold

Post by mikeyww » 06 Dec 2021, 09:46

You can debug your script by adding MsgBox or ToolTip lines that display the values of last and zone after you set those variables. That's about all that I can suggest. Follow your script line by line, examining every variable and conditional statement. Display them if needed. That will bring you to your answer.

Indentation often looks good but has no effect on the AHK parsing. As already noted, if you have a block (e.g., with If), then enclose it in braces. Documentation has examples.

Your script seems a bit convoluted. I would shorten and simplify it while you are testing. Test one small addition at a time, instead of trying to add the entire script and then figure out where it went wrong.

brecht2202
Posts: 31
Joined: 17 Mar 2019, 15:12

Re: Holding mouse in a region activates something. I have a script ready but it activates instantly while I want to hold

Post by brecht2202 » 06 Dec 2021, 11:40

Ok, thanks for the pointers and suggestions!!

Thanks a lot for all the help! :D

Post Reply

Return to “Ask for Help (v1)”