Help with an IF condition

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Painterboy
Posts: 5
Joined: 29 Apr 2014, 23:06

Help with an IF condition

29 Apr 2014, 23:55

I'm new to AHK. I can do the basic stuff, hotkeys, hotstrings etc. I am working on automating some repetitive stuff at work, which would probably still be pretty basic for you guys. One problem I have to overcome is I don't have access to the program outside of work so I have to figure out stuff at home then try it out when I get to work. Right now I am working on one particular problem. As you can see below it is mainly just navigating through windows and menu items. The problem is depending on who the subject of my query is there is a popup window. which is why I have the WinGetTitle. I can see the windows title fine in the message box. The problem is the while the beginning of the title remains the same the second half becomes the name of the subject of my query. IE if the person I am querying is named John SMITH the title will be Query - KO SMITH,JOHN. If I set my variable = Query - KO SMITH,JOHN everything works fine but obviously if I query another subject the code will not work. I was hoping SetTitleMatchMode would fix it but no luck. I have been trying to figure out how to set the variable = to just Query - KO with a wildcard standing in for whatever name follows but I can't figure out how to make it work. If anyone could point me in the right direction it would be greatly appreciated.

Thanks in advance



Code: Select all

; script to query CORE and KO
^\::
SetTitleMatchMode 2
send {enter}
send {shift}+{tab}
Send core{+}{enter}{enter}
send y
sleep 1800
send {enter}
sleep 1000
WinGetTitle, windowstitle, A					; gets windows title, variable to store it in, A specifies active window
msgbox, %windowstitle%					; shows what is currently stored in variable
if windowstitle = Query - KO# 	                        ; if what is stored in windows title = windows title name
{
send {tab}{tab}{tab}{tab}k
send {enter}
send {pgUp}
send {enter}
send !f
send p
send {enter}
return				
}
else	
{											
	SendInput, {alt down}r {alt up}
send {tab}{tab}{tab}{tab}k
send {enter}
send {pgUp}
send {enter}
send !f
send p
send {enter}
}
return
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Help with an IF condition

30 Apr 2014, 00:13

Try this:

Code: Select all

; script to query CORE and KO
SetTitleMatchMode 1
SetKeyDelay, 50
^\::
send {enter}{shift}+{tab}core{+}{enter}{enter}y
sleep 1800
send {enter}
sleep 1000
if WinActive("Query - KO")
send {tab}{tab}{tab}{tab}k{enter}{pgUp}{enter}!fp{enter}
else    
{                                           
    SendInput, {alt down}r {alt up}
    send {tab}{tab}{tab}{tab}k{enter}{pgUp}{enter}!fp{enter}
}
return
Painterboy
Posts: 5
Joined: 29 Apr 2014, 23:06

Re: Help with an IF condition

30 Apr 2014, 00:22

Thanks, for the quick response. :) I will give that a shot. I hate that I have to wait till work to try it :lol:

Hmm I never thought about the SetKeyDelay. That should help the script from racing ahead of itself. Such a good idea. So obvious too when you post it up there.

I'll let you know how it goes.
User avatar
TheDewd
Posts: 1510
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Help with an IF condition

01 May 2014, 13:24

Be sure to change if WinActice("Query - KO") to if WinActive("Query - KO")
Painterboy
Posts: 5
Joined: 29 Apr 2014, 23:06

Re: Help with an IF condition

03 May 2014, 21:25

Yeah I saw that the other night lol.

I tried your script but I noticed the parent window and the pop-up window both are call the same so the IF WinActive command always thinks the pop-up window exists. So for a work-around I am using image search. I made a screen capture of the windows unique image and am using that to match the pop-up using the code below. I borrowed some of your ideas and some of a script that was written by Leef_me. (thank you Leef_me :D ) and jammed em all together and came up with this. Not very pretty and not ideal but it gets the job done. I would prefer not to use imagesearch since it makes the script dependent on being able to access the file path to the image so I am still working on figuring out alternatives, but at least I have something I can use until I figure it out.

If you have any more ideas feel free to pass them along.

Thanks again for your help :)

Code: Select all

; script to query CORE and KO
^\::
#singleinstance force

settitlematchmode 2
SetKeyDelay,50

CoordMode, ToolTip, screen
CoordMode, Mouse, screen
CoordMode, Pixel, screen

image_name=refine search.bmp

send {enter}
send {shift}+{tab}
sleep 500
Send core{+}{enter}{enter}
send y
sleep 1000
send {enter}
sleep 1000

SysGet, VirtualScreenWidth, 78
SysGet, VirtualScreenHeight, 79

SysGet, VirtualScreenLeft, 76
SysGet, VirtualScreenTop, 77


;msgbox , ,, Search for the image on the window, 1

ImageSearch, OutputVarX, OutputVarY, VirtualScreenLeft, VirtualScreenTop
		,VirtualScreenLeft+VirtualScreenWidth, VirtualScreenTop+VirtualScreenHeight,E:\portable_apps\PortableApps\autohotkey\imagesearch pics\refine search.bmp


if (errorlevel<>0)
{
send {pgUp}
send {enter}
WinWaitActive, Query - KO#
send !f
send p
send {enter}
}
else
{
msgbox, , ,  we will search for just the KO, 1

Send {tab 4}
Send K
Send {enter}
send {enter}
WinWaitActive, Query - KO#
send !f
send p
send {enter}
}

return


Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Noitalommi_2, ulysim and 313 guests