Never type ahk_class AGAIN

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
gibenedek
Posts: 53
Joined: 20 Sep 2020, 19:51

Never type ahk_class AGAIN

Post by gibenedek » 01 Dec 2021, 01:56

I think I have a great Idea, why type all that trash when u can just...not?

Code: Select all

	msgbox % := Win_DetectInput("SciTE.exe")
		
	Win_DetectInput(title){
		StringTrimRight, title, Tcut, 4
	If Title = #32768
		TheTit := "ahk_class . title"
	Else if title is xdigit
		TheTit := "ahk_id . title"
	Else if strlen(Title) = 4
		thetit := "ahk_pid . Title"
	Else if Instr(Title, ".exe")
		Thetit := "ahk_exe . title"
	Else if title := TCut
		Thetit := Title
	Else if title contains Class
		Thetit := "ahk_class . Title"	
	Else if title contains _
		Thetit := "ahk_class . Title"
	Else if title contains -
		Thetit := Title
	Else if title contains SciTE
		Thetit := "ahk_class" . Title
	Return TheTit
}
[Mod edit: [code][/code] tags added.]


However, its returning blank. Even when I msgbox % title at the very beginning, its blank. HOWEVER when I put SciTE4AutoHotkey, it returns positive as being active,m therefore it works. Its working in the sense that not working still "works" for any window title.

Anyway, I think this one is a bit beyond me, or im just burnt and missing something easy. Anyway, thought Id share my Idea. I also made a run script

gregster
Posts: 9060
Joined: 30 Sep 2013, 06:48

Re: Never type ahk_class AGAIN

Post by gregster » 01 Dec 2021, 02:05

There are probably more syntax problems but you should remove the := from msgbox % := Win_DetectInput("SciTE.exe"). No idea what it's intended to do here. There is no variable that gets assigned... and this has most likely unintended effects on AHK's parsing.

Also, if you want to concatenate a string with the contents of a variable, the variable name shouldn't be inside the quotes (expression syntax):

Code: Select all

TheTit := "ahk_class . title"
to

Code: Select all

TheTit := "ahk_class " . title

Another problem: Else if title := TCut should probably be Else if (title = TCut) since TCut is a variable name in your function, and not meant as a literal string -> If expression syntax

That said, it looks like you mixed up input and output variable in your StringTrimRight line: StringTrimRight, title, Tcut, 4
StringTrimRight, OutputVar, InputVar, Count
You probably wanted title as the input variable, not the yet empty Tcut variable.

User avatar
boiler
Posts: 17068
Joined: 21 Dec 2014, 02:44

Re: Never type ahk_class AGAIN

Post by boiler » 01 Dec 2021, 02:28

Also, it appears that you are making some generalizations to distinguish between a window’s title and its ahk_class, ahk_id, and ahk_pid that often wouldn’t be true. This also wouldn’t be able to be used when you want to specify a combination of window title text and its ahk_class and/or its ahk_exe, which isn’t as uncommon as you might think.

Post Reply

Return to “Ask for Help (v1)”