Are Labels included in Auto Executing Section?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
mrmech
Posts: 81
Joined: 07 Dec 2015, 17:37

Are Labels included in Auto Executing Section?

Post by mrmech » 27 Mar 2023, 16:04

I think the my label and the commands underneath it are auto executing when I run or reload the script and I keep getting the "Missing ControlGetFocus." Error from line #45 even though I haven't triggered anything other than opening the script. This part of my script sets the variable Selected_Text to the...selected text. 8-) Also, do I need both returns at the bottom. Thanks for any help.

This is the very top of my script:

Code: Select all

;------------------------------------------------
;---- AUTOHOTKEY KEYBOARD & MOUSE REMAPPING -----
;------------------------------------------------

GET_SELECTED_TEXT: 							;{
;------------------------------------------------ Clear Clipboard and Selected Text Variable
Clipboard := ""
Global Selected_Text
Selected_Text := ""
;------------------------------------------------ Chrome
If WinActive("ahk_exe chrome.exe"){
	Send ^c
	ClipWait, 2
	If ErrorLevel {
	 MsgBox, 48, Error, An error occurred while waiting for the clipboard.
	 Return
	 }
	Selected_Text := Trim(Clipboard)
;-	MsgBox % Selected_Text
;------------------------------------------------ ComicRack
} Else If WinActive("ahk_exe ComicRack.exe") {
	ControlGet, Selected_Text, Selected,, WindowsForms10.EDIT.app.0.37e3228_r6_ad12, ahk_exe ComicRack.exe
		If ErrorLevel {
		 MsgBox, 48, Error, Missing ControlGet.
		 Return
		 }
	Selected_Text := Trim(Selected_Text)
;-	MsgBox % Selected_Text
;------------------------------------------------ MediaMonkey	
} Else If WinActive("ahk_exe MediaMonkey.exe") {
	Send ^c
	ClipWait, 2
	If ErrorLevel {
	 MsgBox, 48, Error, An error occurred while waiting for the clipboard.
	 Return
	 }
	Selected_Text := Trim(Clipboard)
;-	MsgBox % Selected_Text
;------------------------------------------------ Everything Else
} Else {
	WinActive("A")
;-	MsgBox % "WinActive: " WinActive("A")
	ControlGetFocus, My_Control
		If ErrorLevel {
		 MsgBox, 48, Error, Missing ControlGetFocus.
		 Return
		 }
	ControlGet, Selected_Text, Selected,, %My_Control%
		If ErrorLevel {
		 MsgBox, 48, Error, Text is NOT selected.
		 Return
		 }
	Selected_Text := Trim(Selected_Text)
	Return
	}
return
;}

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Are Labels included in Auto Executing Section?

Post by swagfag » 27 Mar 2023, 18:10

regular labels are. hotkey and hotstring labels are not

do u need 2 returns? who knows, depends on what the code is meant to be doing. maybe u do, maybe u dont(but if u have to ask, u probably do)

mrmech
Posts: 81
Joined: 07 Dec 2015, 17:37

Re: Are Labels included in Auto Executing Section?

Post by mrmech » 28 Mar 2023, 07:57

When the label is called, this script gets the selected text with any program you're using with special circumstances for 3 programs.

Post Reply

Return to “Ask for Help (v1)”