0
votes

I am trying to create my 1st GUI. I just started using AHK today and for the most part have found it very simple to use. I am stuck on one thing though. I created this GUI to display buttons and then depending on what is selected certain text will be typed. When I select the button it is typing the correct text, but it is typing it four times. I have taken off one of the buttons, so there were only three, but it would still type it four times. What do I need to do to make sure it only types it once?

MyGUI:

#SingleInstance Force
Gui, +LastFound +AlwaysOnTop

GUI, Add, Button, x10 y10 w75 h25 gClick1, Button &1
GUI, Add, Button, x95 y10 w75 h25 gClick2, Button &2
GUI, Add, Button, x10 y45 w75 h25 gClick3, ButtonS &3
GUI, Add, Button, x95 y45 w75 h25 gClickCancel, &Cancel
GUI, Show, w200 h100,My GUI
Return

Click1:
Send The first button was selected
Gui Hide
Return

Click2:
Send The second button was selected
Gui Hide
Return

Click3:
Send The third button was selected
Gui Hide
Return

ClickCancel:
Send The cancel button was selected
Gui Hide
Return
1
Did the answer solve your problem?Robert Ilbrink

1 Answers

1
votes

I have not tested it yet, but it could be that your send is initiating this. remember that you first send a keyboard sequence and then hide the GUI, so in your situation the GUI is still active at the moment you send! Try to first hide the GUI and then send or initially replace send by MsgBox to test. You could also first send an !{Esc} to switch the focus back to the previous application before sending your data, That way you don't need to hide the GUI.

OK just tested my assumptions, add the !{Esc} and it works as expected.

#SingleInstance Force
Gui, +LastFound +AlwaysOnTop

GUI, Add, Button, x10 y10 w75 h25 gClick1, Button &1
GUI, Add, Button, x95 y10 w75 h25 gClick2, Button &2
GUI, Add, Button, x10 y45 w75 h25 gClick3, ButtonS &3
GUI, Add, Button, x95 y45 w75 h25 gClickCancel, &Cancel
GUI, Show, w200 h100,My GUI
Return

Click1:
Send, !{Esc}
Send, The first button was selected
;Gui Hide
Return

Click2:
Send, !{Esc}
MsgBox, The second button was selected
;Gui Hide
Return

Click3:
Send, !{Esc}
MsgBox, The third button was selected
;Gui Hide
Return

ClickCancel:
Send, !{Esc}
MsgBox, The cancel button was selected
;Gui Hide
Return