Can someone assist with this Loop statement?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
chef423
Posts: 213
Joined: 28 Aug 2016, 12:10
Contact:

Can someone assist with this Loop statement?

15 May 2018, 15:34

When the 'Payment Processor Error' applet pops up, my WinActivate and Send, code is not executing....

Code: Select all

Send, !r!r
	Loop,
	  {
		  If WinExist, Payment Processor Error
			{
	   	WinActivate, Payment Processor Error
	  	Send, !o!n{Up}{Del}
	  	Break
			}
	Else ifWinExist, Cash Register Express
		{
	  	WinActivate, Cash Register Express
	  	Break
		}
	}
	Return
	
SirRFI
Posts: 404
Joined: 25 Nov 2015, 16:52

Re: Can someone assist with this Loop statement?

15 May 2018, 16:44

Seems like a part of bigger code. Are you sure the code flow gets to this part? Maybe window with such title is simply not detected? I'd recommend using ahk_exe if possible.

There's a chance this will help:

Code: Select all

Send, !r!r
loop
{
	if WinExist("Payment Processor Error")
	{
		WinActivate, Payment Processor Error
		Send, !o!n{Up}{Del}
		break
	}
	else if WinExist("Cash Register Express")
	{
		WinActivate, Cash Register Express
		break
	}
	sleep 100
}
return
Last edited by SirRFI on 15 May 2018, 16:45, edited 1 time in total.
Use

Code: Select all

[/c] forum tag to share your code.
Click on [b]✔[/b] ([b][i]Accept this answer[/i][/b]) on top-right part of the post if it has answered your question / solved your problem.
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Can someone assist with this Loop statement?

15 May 2018, 16:44

If WinExist vs IfWinExist.

You had it right in your "Else" statement.
chef423
Posts: 213
Joined: 28 Aug 2016, 12:10
Contact:

Re: Can someone assist with this Loop statement?

15 May 2018, 17:12

SirRFI wrote:Seems like a part of bigger code. Are you sure the code flow gets to this part? Maybe window with such title is simply not detected? I'd recommend using ahk_exe if possible.

There's a chance this will help:

Code: Select all

Send, !r!r
loop
{
	if WinExist("Payment Processor Error")
	{
		WinActivate, Payment Processor Error
		Send, !o!n{Up}{Del}
		break
	}
	else if WinExist("Cash Register Express")
	{
		WinActivate, Cash Register Express
		break
	}
	sleep 100
}
return
Its gets there because this works:

Code: Select all

Send, !r!r
	Sleep, 1000
	WinWait, Payment Processor Error
	IfWinExist, Payment Processor Error
	{
	WinActivate, Payment Processor Error
	Send, !o!n{Up}{Del}
	Return
	}
	Else
	Return

I just cant get the +F7 key to work again if it does not invoke that part of the code, beginning with WinWait...
chef423
Posts: 213
Joined: 28 Aug 2016, 12:10
Contact:

Re: Can someone assist with this Loop statement?

16 May 2018, 12:05

Here is the entire piece of code, when F7 is pressed, this imitates the Pay screen in the Point of Sale and adds a .0035 fee when the customer uses credit. The issue is, if the customer presses cacel on the Pax pinpad, the fee remains on the Invoice screen and say they want to use a different card? Then the clerk presses the CREDIT button again, now the customer has been charged the fee TWICE.

So this end code I am having issues with removes the .0035 service fee from the invoice...the code directly below works fine IF the customer cancels the payment on the credit card machine, but if the payment goes thru without invoking the 'Payment processor Error' part, my F7 key does not work again, like its not 'returning' to the top of the code, still waiting on the (winWait) part of the code to execute.

Code: Select all

; Service Fee - Credit
+F7::

	SetTitleMatchMode, 3
	; Customer presses Credit Debit button
	; +F7;;
	; Initiate Pay screen
	Send, !p
	; Copy contents from total amount in Pay Applet
	Send, ^{Ins}
	; Cancel back to Invoice Screen
	Send, !n
	; Send ItemNum into 'Scan Barcode Now...' - 1236
	Send, 1236{Enter} 
	; THANK YOU
	; Has tagalong 1234 SERVICE FEE .035
	; Paste 0.035 in the Pay Applet in the Quantity
	Send, 0.035
	Send, !o
	; Paste Amount from contents copied from the Pay Applet in the Price
	Send, ^v
	Send, !o
	; Press OK on Enter Price Service Fee applet
	; Initiate Credit Debit applet, directly
	Send, !p
	; WinActivate, Cash Register Express
	Send, !r!r
	Sleep, 1000
	WinWait, Payment Processor Error
	IfWinExist, Payment Processor Error
	{
	WinActivate, Payment Processor Error
	Send, !o!n{Up}{Del}
	Return
	}
	Else
	Return
This is why I attempted to add this loop, but it never initiates...

Code: Select all

; Service Fee - Credit
+F7::
	SetTitleMatchMode, 1
	; Customer presses Credit Debit button
	; Initiate Pay screen
	Send, !p
	; Copy contents from total amount in Pay Applet
	Send, ^{Ins}
	; Cancel back to Invoice Screen
	Send, !n
	; Send ItemNum into 'Scan Barcode Now...' - 1236
	Send, 1236{Enter} 
	; THANK YOU
	; Has tagalong 1234 SERVICE FEE .035
	; Paste 0.035 in the Pay Applet in the Quantity
	Send, 0.035
	Send, !o
	; Paste Amount from contents copied from the Pay Applet in the Price
	Send, ^v
	Send, !o
	; Press OK on Enter Price Service Fee applet
	; Initiate Credit Debit applet, directly
	Send, !p
	; WinActivate, Cash Register Express
	Send, !r!r
	loop
	{
	if WinExist("Payment Processor Error")
	{
		WinActivate, Payment Processor Error
		Send, !o!n{Up}{Del}
		break
	}
	else if WinExist("Cash Register Express")
	{
		WinActivate, Cash Register Express
		break
	}
	sleep 100
	}
	return
I hope that gives the full scope of what I am attempting to accomplish and can now get some insight on fixing this.

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

Re: Can someone assist with this Loop statement?

16 May 2018, 13:20

check if your titles are correct, id suggest titlematchmode, 2

Code: Select all

F1:: ; to copy window title of interest
{
	WinGetTitle, title, % "A"
	Clipboard := title
	MsgBox, % Format("Copied [{}] to clipboard.", title)
return
}

F2:: ; to check if active or exists
{
	MsgBox, % Format("Window with title:`n[{}]`n ", title) ((WinActive(title)) ? "IS" : "ISN'T") " active." 
	MsgBox, % Format("Window with title:`n[{}]`n ", title) ((WinExist(title)) ? "DOES" : "DOESN'T") " exist." 
return
}

Esc::ExitApp
chef423
Posts: 213
Joined: 28 Aug 2016, 12:10
Contact:

Re: Can someone assist with this Loop statement?

16 May 2018, 13:57

I am using this in my .ahk file

#NoEnv
#KeyHistory 0
ListLines off
SetKeyDelay, -1, -1
SetNumLockState, AlwaysOn

Would any of those line affect it?
chef423
Posts: 213
Joined: 28 Aug 2016, 12:10
Contact:

Re: Can someone assist with this Loop statement?

16 May 2018, 14:08

swagfag wrote:check if your titles are correct, id suggest titlematchmode, 2

Code: Select all

F1:: ; to copy window title of interest
{
	WinGetTitle, title, % "A"
	Clipboard := title
	MsgBox, % Format("Copied [{}] to clipboard.", title)
return
}

F2:: ; to check if active or exists
{
	MsgBox, % Format("Window with title:`n[{}]`n ", title) ((WinActive(title)) ? "IS" : "ISN'T") " active." 
	MsgBox, % Format("Window with title:`n[{}]`n ", title) ((WinExist(title)) ? "DOES" : "DOESN'T") " exist." 
return
}

Esc::ExitApp

Both windows are confirmed.
chef423
Posts: 213
Joined: 28 Aug 2016, 12:10
Contact:

Re: Can someone assist with this Loop statement?

16 May 2018, 16:36

This works: (but I HATE using a Timer!) I want the loop to work


And what does the '20' mean after my timer? 20 seconds or 20 milliseconds?

Code: Select all

; Service Fee - Credit
+F7::
	
	SetTitleMatchMode, 2
	SetTitleMatchMode, Fast
	; Customer presses Credit Debit button
	; +F7;;
	; Initiate Pay screen
	Send, !p
	; Copy contents from total amount in Pay Applet
	Send, ^{Ins}
	; Cancel back to Invoice Screen
	Send, !n
	; Send ItemNum into 'Scan Barcode Now...' - 1236
	Send, 1236{Enter} 
	; THANK YOU
	; Has tagalong 1234 SERVICE FEE .035
	; Paste 0.035 in the Pay Applet in the Quantity
	Send, 0.035
	Send, !o
	; Paste Amount from contents copied from the Pay Applet in the Price
	Send, ^v
	Send, !o
	; Press OK on Enter Price Service Fee applet
	; Initiate Credit Debit applet, directly
	Send, !p
	; WinActivate, Cash Register Express
	Send, !r!r
	Sleep, 2000
	#Persistent
	SetTimer, Alert1, 20
	return

	Alert1:
	IfWinNotExist, Payment Processor Error
    	return
	; Otherwise:
	SetTimer, Alert1, Off  ; i.e. the timer turns itself off here.
	Send, !o!n{Up}{Del} ; removed service fee
	return
chef423
Posts: 213
Joined: 28 Aug 2016, 12:10
Contact:

Re: Can someone assist with this Loop statement?

16 May 2018, 17:01

So, I flipped the Timer so the error box is not the delimiter: (and it doesnt work)

Code: Select all

#Persistent
	SetTimer, Alert1, 20
	return

	Alert1:
	IfWinExist, Payment Processor Error
    	Send, !o!n{Up}{Del} ; removed service fee
    	SetTimer, Alert1, Off  ; i.e. the timer turns itself off here.
	Return
	; Otherwise:
	SetTimer, Alert1, Off  ; i.e. the timer turns itself off here.
	return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: doodles333, mikeyww and 322 guests