Shortcut executed when reaching the right edge of the screen.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Epoch
Posts: 41
Joined: 04 Jun 2021, 11:09

Shortcut executed when reaching the right edge of the screen.

Post by Epoch » 27 Nov 2021, 14:02

So, on Studio One (a DAW/Music Production Program) pressing Control+B opens/hides the "Browser" on the right edge of the screen so you can drag and drop instruments, effects and files. When you don't use it though, it's not really needed, taking screen space.
So I tried to come up with a script that will open the browser once the mouse cursor reaches the end of the right edge of the screen and will hide it once the cursor crosses a certain point, when you start moving back left. In order to properly toggle it, I made 2 screenshots of the word "browse" at the bottom right corner and utilize Imagesearch. When "browse" is surrounded by blue colour, browser shows and when it's not, it's hidden. Here's my script:

Code: Select all

f10::
last_pos := 999999
Loop {
	MouseGetPos, x, y
	if (x > 2560 && last_pos <= 2560)
	{
		ImageSearch, FoundX, FoundY, 0, 0, 2560, 1440, *216 C:\Users\...\Studio One - BrowserOff.png   
		if ( ErrorLevel = 0 )
		{
			
			send ^b
		}
		
		else
		return
		}
	if (x < 2080 && last_pos >= 2080)
	{
		
		ImageSearch, FoundX, FoundY, 0, 0, 2560, 1440, *216 C:\Users\...\Studio One - BrowserOn.png
		if ( ErrorLevel = 0 )
		{
			send ^b
		}
		
		else
			return
			}
	last_pos := x
	Sleep 10
}

return

It works for the most part but there are three problems:

1. If for whatever reason the cursor crosses the right edge of the screen twice, before it reaches the "hide browser" point on the x axis on the left, toggling occurs so the conditions the browser appearing and disappearing are reversed! The same goes if the cursor moves to the right, crossing the "hide browser" point but does not reach the edge. The next time it moves back left, crossing the "hide" point, it shows up instead.
2. When I drag and drop an instrument, effect or file, most of the time I am done, so the browser needs to hide. Now, I am not sure how to do that. Maybe making screenshots of the different icons (instrument,effect,file) appearing while starting a drag n drop action and by utilizing Imagesearch somehow to send "control+b" to hide it? Maybe in conjunction with a timer? In any case it's something way beyond my coding skills, especially since it has to play well with the rest of the code, so even if I knew I have to use a timer or imagesearch, that wouldn't help me much.
3. Probably the easiest of the problems to solve, at the top of my script I use F10 to fire it up, I'd like it to work when the program opens up, in any case, without pressing a hotkey.

Here's a demonstration of how everything looks (please open the .gif in fullscreen if necessary), ending with drag n dropping a synthesizer (notice the synth icon + the word "VST" during drag n drop), which could help coming up with a solution for problem #2.
Hope it's not something too complicated to pull off? Any idea or completely different approach for the same effect is more than welcome!

Image

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

Re: Shortcut executed when reaching the right edge of the screen.

Post by mikeyww » 27 Nov 2021, 15:00

Why are you using a hotkey instead of just running a SetTimer? Why do you issue Return instead of letting the loop run?

Epoch
Posts: 41
Joined: 04 Jun 2021, 11:09

Re: Shortcut executed when reaching the right edge of the screen.

Post by Epoch » 19 Dec 2021, 09:42

mikeyww wrote:
27 Nov 2021, 15:00
Why are you using a hotkey instead of just running a SetTimer?
Thanks for the reply.
Well, that's because my AHK skills are limited, especially when it comes to commands I never had to use much so far and SetTimer is one of them. I have been studying some examples though and I suppose I'll eventually get the hang of it, this doesn't look like the hardest part as I've said.
Why do you issue Return instead of letting the loop run?
The answer to a certain degree is the same, along with the fact that I use one large script for several programs (enabling/disabling stuff with #IfWinActive), and I've noticed that not using Return often results in script progressing, executing lines I don't want. In this case, I tried to remove it but it didn't make a difference for my #1 issue, if that's what it was supposed to take care of. Since #2 looks like a harder task to pull off, do you have any ideas for this one (#1) perhaps?

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

Re: Shortcut executed when reaching the right edge of the screen.

Post by mikeyww » 19 Dec 2021, 10:03

A bunch of other "zone scripts" (screen edge triggers) on this forum could be adapted.

Epoch
Posts: 41
Joined: 04 Jun 2021, 11:09

Re: Shortcut executed when reaching the right edge of the screen.

Post by Epoch » 19 Dec 2021, 10:18

mikeyww wrote:
19 Dec 2021, 10:03
A bunch of other "zone scripts" (screen edge triggers) on this forum could be adapted.
For example? That's what I did to come up with the code I've posted and it partially works minus the #1 issue (cursor crossing a trigger line for a second time before crossing the other results in actions reversed).

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

Re: Shortcut executed when reaching the right edge of the screen.

Post by mikeyww » 19 Dec 2021, 10:46

An example is below.

Code: Select all

Process, Priority,, B
margin1 := 20, margin2 := 250, on := False
SetTimer, Zone, 100

~^b::on := !on

Zone:
CoordMode, Mouse
last := zone
MouseGetPos, x
Switch
{ Case x > A_ScreenWidth - margin1: zone = 0 ; Right edge
  Case x < A_ScreenWidth - margin2: zone = 1 ; Main screen area
  Default                         : zone = 2 ; Browser area
}
Send % zone = last || zone != on ? "" : ("^b", on := !on)
Return

scriptor2016
Posts: 854
Joined: 21 Dec 2015, 02:34

Re: Shortcut executed when reaching the right edge of the screen.

Post by scriptor2016 » 19 Dec 2021, 16:07

How about this:

Code: Select all

#Persistent
CoordMode, Mouse, Screen
SetTimer, Timer, 50

Timer:
MouseGetPos, x, y
If ((x>2560) && (!flag)) ;this is to bump the right side of screen
{
ImageSearch, FoundX, FoundY, 0, 0, 2560, 1440, *216 C:\Users\...\Studio One - BrowserOff.png   
		if ( ErrorLevel = 0 )
		{
		send ^b
		}
flag:=1
}

else if ((x<2080) && (flag)) ;this is to move back to the left 

{
ImageSearch, FoundX, FoundY, 0, 0, 2560, 1440, *216 C:\Users\...\Studio One - BrowserOn.png
		if ( ErrorLevel = 0 )
		{
		Send ^b
		}
flag:=0
}
return

Post Reply

Return to “Ask for Help (v1)”