Adding in Focused Control

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
aweinberg
Posts: 52
Joined: 08 Feb 2019, 15:38

Adding in Focused Control

15 Nov 2020, 00:14

How do I add focused control to my script, so it only works in the area? I got the focus control info from window spy.

ClassNN: DroverLord - Window Class77
Text: DroverLord - TabPanel Window
x: 782 y: 1379 w: 2849 h: 699
Client: x: 769 y: 1302 w: 2848 h: 699

My script is below:

Code: Select all

#NoEnv
#SingleInstance Force
#Warn ClassOverwrite
SendMode Input
SetBatchLines -1
SetTitleMatchMode 2

#IfWinActive, ahk_exe Adobe Premiere Pro.exe


c::
send, c
keywait, c
return ;  <<<<< this, too, to separate the hotkeys

c up::
send,v
return
aweinberg
Posts: 52
Joined: 08 Feb 2019, 15:38

Re: Adding in Focused Control

15 Nov 2020, 01:28

Here is my poor attempt that does not work

Code: Select all

#IfWinActive, ahk_exe Adobe Premiere Pro.exe
c::
send, c
keywait, c
return  

c up::

Process, Exist, DroverLord - Window Class77
;msgbox errorLevel `n%errorLevel%
	If errorLevel = 0
		Send v, 
return
	else
	return
	
User avatar
boiler
Posts: 17404
Joined: 21 Dec 2014, 02:44

Re: Adding in Focused Control

15 Nov 2020, 02:13

Use ControlGetFocus. Note also that you should put a $ in front of the first hotkey to keep the Send, c line from triggering the hotkey itself.

Code: Select all

#IfWinActive, ahk_exe Adobe Premiere Pro.exe
$c:: ; $ prevents the next line from triggering this hotkey
send, c
keywait, c
return  

c up::
ControlGetFocus, FocusedCtrl , ahk_exe Adobe Premiere Pro.exe
if (FocusedCtrl = "DroverLord - Window Class77")
	Send, v ; I assume you meant 'Send, v' and not 'Send v,' like you had
return

For future reference, you have to group multiple lines after an if statement with { }, so this part of your code would have looked like this:

Code: Select all

If errorLevel = 0
{
	Send, v
	return
}
else
	return
Although the first return and the else part isn’t needed since you want the return to happen in either case. It can just be:

Code: Select all

If errorLevel = 0
	Send, v
return
aweinberg
Posts: 52
Joined: 08 Feb 2019, 15:38

Re: Adding in Focused Control

15 Nov 2020, 12:50

Thanks boiler and appreciate the explanation.
aweinberg
Posts: 52
Joined: 08 Feb 2019, 15:38

Re: Adding in Focused Control

14 Dec 2020, 22:51

I keep getting errors how have I formatted my if else statement.

Code: Select all

	hideDescription(hwnd, keybind)
	{
		

{ControlGetFocus, FocusedCtrl , ahk_exe Adobe Premiere Pro.exe
If (FocusedCtrl = "Chrome_WidgetWin_01")
	return
	
	else
	
PremiereTooltip.isPremiereActive()
			{Send v }
			return
			
	}
}
User avatar
boiler
Posts: 17404
Joined: 21 Dec 2014, 02:44

Re: Adding in Focused Control

14 Dec 2020, 23:04

You are not understanding how to use { }. You have them haphazardly placed. You’re not using them to group multiple statements as are their purpose, while also incorrectly wrapping them around a single command and placing them where they are not needed at all. It looks like you intended it to be this:

Code: Select all

hideDescription(hwnd, keybind)
{
	ControlGetFocus, FocusedCtrl , ahk_exe Adobe Premiere Pro.exe
	If (FocusedCtrl = "Chrome_WidgetWin_01")
		return
	else
	{	
		PremiereTooltip.isPremiereActive()
		Send v
		return
	}
}

I assume there is other code not shown. Also, if that’s meant to be a function, it’s not making use of the parameters it is passed.
aweinberg
Posts: 52
Joined: 08 Feb 2019, 15:38

Re: Adding in Focused Control

14 Dec 2020, 23:16

Thanks again, appreciate the help i added }} to the end and now it works.

Code: Select all

#NoEnv
#SingleInstance Force
#Warn ClassOverwrite
SendMode Input
SetBatchLines -1
SetTitleMatchMode 2

TooltipHotkeys := [new PremiereTooltip("V", "Selection tool", "The default tool, used to select clips in the timeline.")
				 , new PremiereTooltip("A", "Track Select tool", "Select all clips on a track from a given point, or select multiple tracks.")
				 , new PremiereTooltip("B", "Ripple Edit tool", "Adjust an edit point and move other clips in the timeline to compensate.")
				 , new PremiereTooltip("N", "Rolling Edit tool", "Adjust an edit point between two clips without affecting the rest of the timeline.")
				 , new PremiereTooltip("R", "Rate Stretch tool", "Change the duration of a clip while simultaneously changing the speed to compensate.")
				 , new PremiereTooltip("C", "Razor tool", "Cut a clip (or multiple clips) into two clips.")
				 , new PremiereTooltip("Y", "Slip tool", "Move a clip's in and out points by the same amount simultaneously, so the rest of the timeline is not affected.")
				 , new PremiereTooltip("U", "Slide tool", "Move a clip back and forth in the timeline, while simultaneously adjusting adjacent clips to compensate.")
				 , new PremiereTooltip("P", "Pen tool", "Create control (anchor) points.")
				 , new PremiereTooltip("H", "Hand tool", "Drag the timeline view left and right.")
				 , new PremiereTooltip("Z", "Zoom tool", "Click in the timeline to magnify the view, or drag and select a rectangular area to zoom into.")]

class PremiereTooltip
{
	static GUI_WIDTH := 200
		
		 , EXE := "ahk_exe Adobe Premiere Pro.exe"
		

	__New(keybind, name, description) {
		

		fn := this.hideDescription.Bind("", hwnd, keybind)
		Hotkey % Format("~{} Up", keybind), % fn

		


		
	}

	isPremiereActive() {
		return WinActive(PremiereTooltip.EXE) && !A_CaretX
	}

	

hideDescription(hwnd, keybind)
{
	 ControlGetFocus, FocusedCtrl , ahk_exe Adobe Premiere Pro.exe
	 If (FocusedCtrl = "Chrome_WidgetWin_01")
		return
	 else
	{	
		PremiereTooltip.isPremiereActive()
		Send v
		return
	}
}
}
		

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mikeyww, peter_ahk, Spawnova and 349 guests