Page 1 of 1

Is there a better way of doing this ?

Posted: 22 Apr 2016, 08:52
by WalkerOfTheDay
Hi,

Is there a better way of doing this ?

When I have Sap Business One started, and fire below code, the Send {F2} and Send {F5} only
works when I use WinActivate, otherwise the focus is on the gui.

Just curious, it works like I want but I was just wondering if there was another way.

Code: Select all

SetTitleMatchMode, 2 ; 

Gui, +AlwaysOnTop
Gui, Add, Button, x86 y67 w100 h30 , F2
Gui, Add, Button, x196 y67 w100 h30 , F5
; Generated using SmartGUI Creator for SciTE
Gui, Show, w477 h377, Toetsenbord
return

ButtonF2:
{
	WinActivate,  - SRT International BV, , 3
	Send {F2}
	return
}

ButtonF5:
{
	WinActivate,  - SRT International BV, , 3
	Send {F5}
	return
}
GuiClose:

ExitApp

Re: Is there a better way of doing this ?

Posted: 22 Apr 2016, 09:25
by kczx3
The other way you could do it is just using hotkeys or hotstrings. If you use a gui and have to click a button to send the keystrokes, then yes WinActivate would be required. Hotkey/Hotstring seems like the better way to go.

Re: Is there a better way of doing this ?

Posted: 22 Apr 2016, 11:22
by WalkerOfTheDay
Thank you for your answer.

I do need this GUI in my script, so I'll stick with what I have so far.

Re: Is there a better way of doing this ?

Posted: 22 Apr 2016, 11:56
by SifJar
You could also use ControlSend e.g.

Code: Select all

ButtonF2:
; curly brackets not required for label
ControlSend,,{F2},  - SRT International BV, , 3
return