WinGetClass with spaces? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ravena1
Posts: 62
Joined: 06 Sep 2017, 15:13

WinGetClass with spaces?

Post by ravena1 » 23 Jan 2022, 04:02

my ahk works fine if the target wingetclass has no space but gave me error if title has space, can someone help me? thank you Image

Code: Select all

SetTitleMatchMode RegEx
mywinclass:="Ragna Bunny | CLASSIC (^-_-^)"

home::
WinGet, AhkPID, PID, A
WinGetClass,%mywinclass%,ahk_pid %AhkPID%
IniWrite, %AhkPID%, gloria.ini, process, ahk_pid
IniRead, ahk_pid, gloria.ini, process, ahk_pid
SplashTextOn,,, GLORIA!! Process ID:%AhkPID% is saved
Sleep 2000
SplashTextOff
Loop,
	{
ControlSend, ahk_parent, {F4}, ahk_pid %AhkPID%
Sleep, 2000
ControlSend, ahk_parent, {F5}, ahk_pid %AhkPID%
Sleep, 12000

}
	
end::exitapp
#NoEnv
SendMode Input 
SetWorkingDir %A_ScriptDir%

Rohwedder
Posts: 7569
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: WinGetClass with spaces?  Topic is solved

Post by Rohwedder » 23 Jan 2022, 04:11

Hallo,
try:

Code: Select all

WinGetClass, mywinclass, ahk_pid %AhkPID%

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

Re: WinGetClass with spaces?

Post by boiler » 23 Jan 2022, 09:11

Yes, as Rohwedder showed, the first parameter of WinGetClass is an output variable that will receive the class name for the window specified with the subsequent parameters. When you put % around it, you are telling it to use a variable whose name is contained in the variable named mywinclass, which is why it cannot contain a space as it would be an illegal variable name. So if the line was:

Code: Select all

mywinclass:="RagnaBunnyCLASSIC"
…your WinGetClass line is simply storing the class name in the variable named RagnaBunnyCLASSIC.

What is it that you’re trying to achieve? You say it works fine when it doesn’t contain a space, but that can only mean it doesn’t produce an error. It’s not actually doing anything with it, though. Are you trying to change the class name to Ragna Bunny | CLASSIC (^-_-^) or something? For what purpose?

ravena1
Posts: 62
Joined: 06 Sep 2017, 15:13

Re: WinGetClass with spaces?

Post by ravena1 » 24 Jan 2022, 07:50

Rohwedder wrote:
23 Jan 2022, 04:11
Hallo,
try:

Code: Select all

WinGetClass, mywinclass, ahk_pid %AhkPID%
oh yes thank you so much

Post Reply

Return to “Ask for Help (v1)”