Working with Radio Buttons and GUI's - user-interface

I've been learning to use GUI's with Autohotkey, and I'm creating a small script so when I press the insert button it allows me to quick search Google. I can't figure out how to use Radio Buttons, so say for example, I can choose to search Google or Bing. I don't know any of the code for "If Google is selected, search the query on Google".
^Insert::
MsgBox,4,, Would you like to reload?, 3
IfMsgBox, no
Return
IfMsgBox, Timeout
Return
Reload
Insert::
Gui, Add, Text,, Search Google:
Gui, Add, Edit, vSearchQuery ym ;
Gui, Add, Button, default, Search
Gui, Show,, Quick Search
return
GuiClose:
ButtonSearch:
Gui, Submit
Run, http://www.google.com/search?hl=en&q=%searchQuery%
Reload

Here is a simple example:
Gui Add, Radio, vEngine, Google
Gui Add, Radio,, Bing
Gui Add, Button, h25 w126 Default,OK
Gui Show
Return
ButtonOK:
Gui Submit
if Engine = 1
msgbox % "You chose Google!"
else if Engine = 2
msgbox % "You chose Bing!"
ExitApp

Related

Autohotkey Check Variable in GUI

I can't seem to get this message box to work using variables. It should be simple so I am missing something. Please help.
Gui +alwaysontop
Gui, add, button, gChoice vA w50, A
Gui, add, button, gChoice vB w50, B
gui, show, y200 w70
return
Choice:
msgbox % v
gui submit, nohide
if A
MsgBox A
if B
MsgBox B
return
Issues with your code:
Ordinary buttons do not store anything in associated variables. So, specifying vA or vB is meaningless. On the other hand, checkboxes and radio buttons do, as stated here.
I have no idea what you're trying to do with MsgBox % v since there's no other reference to the variable v.
The following's tested to work:
Gui +AlwaysOnTop
Gui Add, Button, gChoiceA w50, A
Gui Add, Button, gChoiceB w50, B
Gui Show, y200 w70
Return
ChoiceA:
MsgBox A
Return
ChoiceB:
MsgBox B
Return

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

Close a GUI window from button in AutoHotKey GUI window not working

I have the AutoHotKey EnterPad Keyboard/Pad with 120 Programmable Keys
It works by sending a Hotkey press for each key to an AutoHotKey script which has a Label function for each key named 001 through 120
Below is my AHK Label function called when key 115 is pressed.
My code allows me to select rows in any Windows Listview component and it will show a popup GUI window with a textbox filled in with the data from the selected rows with each column separated with a TAB space. I can then copy or save it or view it whatever I like.
;---------------------------------------------------------------------115-----
; Copy Selected Windows Listview Items to Tab Spaced Text - Show popup Window Gui
; https://superuser.com/questions/814831/copy-to-clipboard-from-table-list-in-a-program-on-windows
115:
Gui, SelectedListRowsTextGui:Destroy
MouseGetPos, , , , ListView_hwnd, 2 ;2 means return HWND
ControlGet, selected_row_text, List, Selected, , ahk_id %ListView_hwnd%
Gui, SelectedListRowsTextGui: +ToolWindow +AlwaysOnTop -Caption
Gui, SelectedListRowsTextGui:Add, Edit, vUnused_variable x11 y15 w950 h66, %selected_row_text%
Gui, SelectedListRowsTextGui:Add, Button, x62 y84 w140 h30 +Center, Close
Gui, SelectedListRowsTextGui:Show, ,
return
ButtonClose:
Gui, SelectedListRowsTextGui:Destroy
return
Return
Problem
My issue is that once the popup window is opened from my AHK GUI, my CloseButton label dose not get called when I click the close button.
I realize it likely has something to do with it being nested under the key 115s label function. How can I best achieve the desired result?
I tried moving the CloseButton label outside of the 115 label however it still is not called from the GUI's Close button click.
You can see I have named the GUI SelectedListRowsTextGui this is to allow this Enterpad.ahk script to contain many GUI windows for different actions it will perform.
Preview of the GUI window this script creates when listview items are selected and this Label function is called:
I got it now....
Since my GUI is named SelectedListRowsTextGui I had to add that name in front of my CloseButton label name so it is now SelectedListRowsTextGuiButtonClose and works great

Button event doesn't trigger - Autohotkey

Iam developing an ahk-Script that checks the battery of the current device in time intervals.
Besides two text-lines that show the ac-status and the batterylife in percent, I am showing a Button to close the gui. Otherwise the gui closes itself in 10 seconds.
But:
When I click on the button, nothing happens... can someone show me the mistake?
Thx a lot
Gui, +AlwaysOnTop +Disabled -SysMenu +Owner
Gui +LastFound
WinSet, Transparent, 240
Gui, -Caption
Gui, Font, s11 cD0D0D0 Bold
Gui, Add, Text,, %acStatus%
Gui, Add, Text,, %batteryLifePercent% Prozent
Gui, Add, Button, x10 y+5 w90 gsub1, Ok
Gui, Show, x1750 y1000
Gui, Show, NoActivate, Akkustatus
Return
Sleep, 10000
Gui Destroy
Return
sub1:
{
Gui Destroy
}
Return
Remove +Disabled from the gui:
Gui, +AlwaysOnTop +Disabled -SysMenu +Owner
This option will prevent the user from interacting with the window, thus preventing you from clicking on the button.

AutoHotKey - "Continue" and "Cancel" Buttons

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.

Resources