AutoHotKey - "Continue" and "Cancel" Buttons - user-interface

I am a newbie with AutoHotKey, and to this point I consider myself fortunate to have created a script to automate about 90% of the data entry in a window. I'm now trying to kick it up a notch and add a warning/caution GUI to my data entry script. I want to pause the running script and open a GUI that will alert me to look at what has already been entered, with one button to allow things to proceed if a particular entry looks OK, and another to dump out of both the GUI and the remainder of the script if the entry is incorrect.
Here's some code I came up with, mixed with some pseudocode to help show what I want to do.
(Previous data entry script executes to this point)
Stop the script
Gui, New
Gui, Add, Text, 'n Check Authorization Number to be sure it is A1234 (FY 15). ; Wraps text
Gui, Add, Button, Default, Continue
Gui, Add, Button, Quit
Gui, Show, IMPORTANT!
If Continue button is clicked
----Continue with script
If Abort button is clicked
----Close the GUI
----Exit the entire script
(Resume where I left off with rest of the data entry script)
I've read the AHK Help file and am stumped about how to make these buttons work, as well as how to properly return from the GUI back to the script if I hit continue, or quit the whole thing if I spot a problem. I can tweak things like the size of the GUI and the button placement; what's most important is getting the GUI code right. Can someone help with the code? (The last programming class I took was in 2003, so I have forgotten a whole lot!)

In your case, a GUI would be overkill. AHK (and many other languages at that) provide standard dialogs for simple user interaction called message boxes.
Message boxes in AHK can be displayed in two ways:
MsgBox, This is a simple message. Please click "OK".
MsgBox, 4, Attention, Here`, you can choose between "Yes" and "No".
In the second case, we declared an option which controls the buttons that are displayed. You can use IfMsgBox in order to detect what the user has clicked:
IfMsgBox, Yes
MsgBox, 4, Really?, Did you really mean "Yes"?
Putting these pieces together, we can ask the user to decide if they want to continue, without the need to create a GUI, in a few lines:
; Option "1" is "OK/Cancel"
MsgBox, 1, IMPORTANT!, Check Authorization Number to be sure it is A1234 (FY 15).
IfMsgBox, Cancel
{
ExitApp
}
; do stuff
This code addresses each of your other problems, too:
A message box halts the current thread until the user dismisses the dialog or it times out (if you specifically declared a timeout).
To completely stop the execution of our script, we use ExitApp.

Related

AHK Cannot ControlClick on hidden elements in nested child window

I'm trying to automate a many clicking process, just to narrow it to the user input.
I encountered problems in controlClicking interface elements, which seems not to be standard Windows GUI elements.
When pointing them with WinSpy they don't appear as separate buttons, but I can point the whole child Window which is drawn in the main program window.
As on pic1, I pointed the whole window and I can find each tab/button by it's text inside and on pic2 I can inspect the ClassNN of that element and it's ID.
As far as clicking other buttons in the main menu bar of the program works, a simple:
ControlClick, ClaTab_01000000H26, WindowName
doesn't work. I think during the day, and many possibilities I tried, I could ControlClick the above button by pointing it with its ID, but that ID changes every instance. I could confirm that tomorrow if it works by ID.
Of course I tried SetControlDelay -1 and ,NN option. But don't take that for granted, I can try any of your suggestions tomorrow.
Both tabs marked with purple color, are to find in the Windows->SiblingWindows tab. I really don't want using x,yCoords (that actually work), but I need the script to be as reliable as possible.
So my questions are:
Am I missing something or you have any suggestions how to click that elements?
Is it correct, that no matter how deep the child windows get (one has buttons to open another on top of it), all the time the WinName stays the same pointing to the main program ***.exe?
Could you provide an example from the web or yours, to find an element's ID by providing the text attached to the button (pic1-red line and also pic2 in "text")?
I also cannot maximize the child window. Double clicking it works, but I can't find the appropriate ClassNN of the window to call.
Could you provide an example, how to use the Messages tab? I assume, if I find the button as on the pictures, I could send a message with controlClick and see if there's a reaction?
1.Ugh. I found the solution, which is awesome, but a little frustrating that with a bit of luck I tried another aproach that's not that logical for a newbie like me:
instead:
ControlClick, ClaTab_01000000H6, ahk_class ClaWin01000000H_2,,,, NA
it's just
ControlFocus, ClaTab_01000000H6, ahk_class ClaWin01000000H_2,,,, NA
2._Yep. One child window creates another and another and another, but winTitle stays the same. In my case:
ahk_class ClaWin01000000H_2
3._Code below returns the handle/ID of the element you specify. Change ClaTab and ClaWin to your chouice.
ControlGet, OutputVar, hwnd,, ClaTab_01000000H1, ahk_class ClaWin01000000H_2
MsgBox, %OutputVar%`
Probably to be continued.
I highly recomend to both use
WinSpy https://www.autohotkey.com/boards/viewtopic.php?t=28220
SimpleSpy https://www.the-automator.com/downloads/simple-spy/
First one has lots of useful information and the window tab provides information of hidden buttons/windows. Second one in a more clear way indicates the parent window and its class.

Create Identifier for input box with AHK GUI

I have created a GUI in AHK and it works well now. I am processing multiple records and would like to be able to track the place that I am on. My code loops through each record and does some actions before moving on to the next one. While this is happening the GUI window is shown. Also I am writing this in AHK then using the conversion tool and creating an .exe with it. I am developing this tool to be distributed as a stand alone EXE that one can install/save and then run when they want to. Below is a screen shot of the tool and the code to load in the names.
Gui, PasteGUI:Add, Text,, Please add the Names that you want to Process.
Counter := 0
Loop, parse, Clipboard, `n, `r
{
x%A_Index% := A_LoopField
Counter++
}
Counter--
Loop, %Counter% ; Dynamic List length
Gui PasteGUI:Add, Edit, vButton%A_Index%, % x%A_Index%
Gui PasteGUI:Add, Button, x200 y270 w88 h26 vButton02 gGoCont Default, Continue
Gui PasteGUI:Add, Button, x290 y270 w88 h26 vButton03 gGoQuit, Cancel
Gui, PasteGUI:Show
}
Return
GoCont:
{
Loop, %Counter%
{
CODE TO PROCESS MY EACH NAME
}
MsgBox Done!
Gui Destroy
}
Return
GoQuit:
Gui Destroy
Return
I want to add something so that when I am processing Jason it can be identified. Having an arrow that moves as I loop through the list would be nice. As I have depicted it below,I drew it on in paint. Otherwise if I could turn the past records a color that would work too. So for the below example the names "Chris" & "Ben" would be highlighted in a color or the boxes would be somehow identified as different. I am not sure how to do either so it would be great to learn both if possible. Lastly, whatever method is described I need to be able to convert it to an .exe with Ahk2Exe and then be able to run the .exe and not have a need to have any further files or other references in the program that would not work. This is interned to be run on a standard Windows computer so if there are some default images that can be accessed that might be useful too.
Okay so Ive worked out how to do this with PGilm's method of checkboxes. You could also possibly do this with a table of some sort. But the code below looks to be working for me.
Also I wanted to let you know I changed the var x to cliparray so it is easier to read.
Gui, Add, Text,section, Please add the Names that you want to Process.
Counter := 0
Loop, parse, Clipboard, `n, `r
{
cliparray%A_Index% := A_LoopField
Counter++
}
Counter--
Loop, %Counter% {
; Dynamic List length
Gui, Add, Checkbox, xs vCheckBox%A_Index%
Gui Add, Edit, yp+1 xs+30 vTextbox%A_Index%, % cliparray%A_Index%
}
Gui Add, Button, x200 y270 w88 h26 gGoCont vButton02 Default, Continue
Gui Add, Button, x290 y270 w88 h26 vButton03 gGoQuit, Cancel
Gui, Show
Return
GoCont:
;needed to get the variables from the edits and check box, else the varibles dont exist See below for more information.
Gui, Submit, NoHide
msgbox, Go..
Loop, %Counter%
{
line=Textbox%A_Index%
GuiControl,, CheckBox%A_Index%, 1
backone:=A_Index-1
GuiControl,, CheckBox%backone%, 0
Msgbox % "variable " line " contains: " Textbox%A_Index%
}
MsgBox Done!
Return
GoQuit:
Gui Destroy
Return
;Used to debug to see list of all variables. Super helpful :D
F7::
ListVars
return
Some logic to take note of would be on the lines that add the edits and checkbox's. I used the Section logic of Gui positioning to make the edit and check on the same line. In this code the section element is set in the first Gui, Add, for the text section. And thus carries down to the other gui elements. Section AHK Documentation
Gui, Add, Checkbox, xs vCheckBox%A_Index%
Gui Add, Edit, yp+1 xs+30 vTextbox%A_Index%, % cliparray%A_Index%
The next part to take a closer look at is in the GoCont function. I am using the index of the loop to check the CheckBox%A_Index% checkbox so that the current line turns on. I also turn off the last index's check box with the GuiControl,, CheckBox%backone%, 0 line. This give the effect of the check box moving through list as you process text with in each element.
One last line to mention is the Gui, Submit, NoHide. Without this you will be missing the variables created for each checkbox and edit. This will create and fill the variables with the data from each gui element. Gui, Submit AHK Documentation

Processing: Creating Buttons

I'm trying to create a program that creates three buttons on the right side of the screen.
When I press a button, the entire background will change color (each button will make the background a different color). Whenever the mouse is not pressed, the background will return to white. I'm having trouble understanding how to make the three rectangles into buttons.
THIS MUST BE DONE WITHOUT A SPECIAL BUTTON METHOD/LIBRARY
You need to break your problem down into smaller pieces.
Can you create a program that just shows a single button? Don't even worry about making it interactive yet. Just show a single button at hard-coded coordinates.
Now can you detect when the user clicks in that button? Just print something to the console. Get that working perfectly before moving on.
Now can you get multiple buttons working together? Again, just print somethign to the console, and make sure it works perfectly before moving on.
Finally, can you make it so pressing each button changes the background instead of printing something to the console?
If you get stuck on a specific step, you can post a MCVE along with a specific technical question. Stack Overflow really isn't designed for general "how do I do this" type questions. It's for specific "I tried X, expected Y, but got Z instead" type questions. So please try something and post an MCVE of a specific step you're stuck on. Good luck.
Check processing's documentation for mouseClicked() and mousePressed.
The former being a method called upon a click, and the later is a boolean that is constantly updated. (So you'd check for it in your draw())
You'd then want to check the mouseX and mouseY values to see if they are in your desired button's area. (Which would be displayed on screen using rect())

Messagebox centered to parent Window / Form

I am trying to build my own HTA right now to act as a front end for some of my batch scripts. I would like to use a msgbox (or anything equivalent) that I can use to output any errors, clicking Ok will just get rid of the prompt.
Here is the code I have been using:
x=msgbox("Error text" ,48, "Error: Title")
I would preferably like the following conditions, to be able to use a custom icon, the box to center on X and Y to the parent window/form, and to allow me to define the text in the box and it's title.
If this is not possible then just a messagebox that can be centered on X and Y to the parent window would suffice.
Is there any way of doing this in VBScript?
Or should I look into doing an HTML/CSS version that would popup on the screen?
I don't know the answer to your first question, but whatever the answer is there must be necessarily limits to what a box message box that pops up outside of the HTML can do.
So for customization that includes icon, centering and anything else expressible in HTML/CSS, I think you should do HTML/CSS that pops up on the screen.
You might want to look at jqueryui or bootstrap to get you going faster so you don't have to start from scratch.
https://jqueryui.com/dialog/#modal-message
http://getbootstrap.com/javascript/#modals
They both use jquery underneath so if you aren't already using it, you'll pick up some more bytes in your initial download.

Update Gui without pressing submit in AHK

So I bet the has already been covered but I couldn't find it, so if you know where the answer is, simply point me in the right direction!
I have a GUI with two radio check boxes, and I would like to show/hide some commands based on which radio is selected. However, I would prefer not to have to create a new GUI, or have to click the Submit button to do so. Is there a way to trigger guicontrol without submitting the gui?
Thanks!
Paul
Ok, so I figured out how to accomplish what I'm trying to do, and so I'm posting it here for posterity sake! ;)
I realized that I could use GUI, Submit without closing the form if I appended it with nohide. So I created a glabel for both radio buttons, so when either one is selected they activate a subroutine which submits the form (without hiding it), and does whatever actions I want it to, such as show more commands, or insert text.
Paul

Resources