AHK: %Clipboard% never changes - autohotkey

I want to show the current (=changing) item of the Windows clipboard in a text field where I can do basic text editing. I made it work like so:
<^>!x:: ; AltGr + x
Gui +Resize ; +MinSize300x200
Gui, Add, Edit, , %Clipboard% ; flexibe size (fits content)
Gui, Show ;
Return
However, the problem is that no matter how many items I copy, %Clipboard% always only holds the very first clipboard item which I copied upon loading the above script. It never changes.
What should I do?

<^>!x:: ; AltGr + x
Gui, destroy
Gui +Resize ; +MinSize300x200
Gui, Add, Edit, , %Clipboard% ; flexibe size (fits content)
Gui, Show
Return
https://www.autohotkey.com/docs/v1/lib/Gui.htm#Destroy
If you want to keep the last Gui:
<^>!x:: ; AltGr + x
Gui, New
Gui +Resize ; +MinSize300x200
Gui, Add, Edit, , %Clipboard% ; flexibe size (fits content)
Gui, Show
Return
https://www.autohotkey.com/docs/v1/lib/Gui.htm#New

Related

Trying to change variable using a checkbox in AHK, but it doesn't seem to be changing the variable at all?

I've been trying to make a pretty basic toggle button to turn hotkeys on and off, but it doesn't seem to be updating the "MyHotkeyCheckboxState" variable at all?
I tried changing it to this script to troubleshoot, but the box is just empty. Any ideas or anything big I'm missing?
; Create a GUI window with a checkbox control
Gui, Add, Checkbox, vMyHotkeyCheckboxState, Enable Hotkey
Gui, Show
; Create a hotkey using PgUp as the keybind
Hotkey, PgUp, MyHotkey, On
return
; Toggle the hotkey based on the state of the checkbox
MyHotkey:
MsgBox, %MyHotkeyCheckboxState%
return
The checkbox status wasn't saved to the variable yet when you checked for it in the MsgBox command.
You just need to add Gui, Submit, NoHide every time you want to check for the checkbox state. NoHide is there so that the target GUI doesn't get hidden.
; Create a GUI window with a checkbox control
Gui, Add, Checkbox, vMyHotkeyCheckboxState, Enable Hotkey
Gui, Show
; Create a hotkey using PgUp as the keybind
Hotkey, PgUp, MyHotkey, On
return
; Toggle the hotkey based on the state of the checkbox
MyHotkey:
Gui, Submit, NoHide
MsgBox, %MyHotkeyCheckboxState%
return
Or using GuiControlGet
; Create a GUI window with a checkbox control
Gui, Add, Checkbox, vMyHotkeyCheckboxState, Enable Hotkey
Gui, Show
; Create a hotkey using PgUp as the keybind
Hotkey, PgUp, MyHotkey
Return
; Toggle the hotkey based on the state of the checkbox
MyHotkey:
GuiControlGet, MyHotkeyCheckboxState
MsgBox, %MyHotkeyCheckboxState%
Return

Use Enter button for submit, while working normally elsewhere

I have a script that opens a GUI with a simple interface, which closes with Esc, and submits through the button. The script always runs in the background. I'm trying to find a way to make the Enter key work as a submit, but while still working normally everywhere else. I've tried using IfWinActive, but it doesn't work. Any ideas? thanks! (btw some of the code looks messy in this format, but the "unnecessary details" are there because this isn't the full script.)
Lwin & MButton::
Goto, Start
return
Start:
IfWinNotExist, New
{
Gui,1:-border
gui, font, s24, Product Sans ; Set 10-point Product Sans.
Gui, Add, Text,, Type here to search: ;controls the UI
Gui, Add, Edit, vTextInput
Gui, Add, Button, -WantReturn gSubmit w80, Go
Gui, Show, w400 h300, New
IfWinExist, New
Hotkey, Enter, Submit, On
return
}
Else
Return
IfWinExist, New
Esc::Gui, Destroy
return
IfWinExist, New
Enter::
Goto, Submit
return
Submit:
Gui, Submit ;destroys the UI when submitted
GuiControlGet, TextInput
Gui, Destroy
Else
{
link = https://www.google.com/search?q= %TextInput% ;search google
Run, %link%
}
The code really looks like some real horror haha.
So much legacy AHK or stuff that doesn't work. But anyway, can't fix all that since that isn't the full script.
The answer to the actual question is to make your button the default button:
Gui, -Border
Gui, Font, s24, % "Product Sans"
Gui, Add, Text, , % "Type here to search:"
Gui, Add, Edit, vTextInput
Gui, Add, Button, +Default gSubmit w80, % "Go"
Gui, Show, w400 h300, % "New"
return
Submit:
Gui, Submit
Run, % "https://www.google.com/search?q=" TextInput
return
Sure, you could also define your own hotkey, like you tried to, but there's just no reason to when the above is so convenient.

Issues with AutoHotKey symbol pasting from GUI

I am new to AHK, and am trying to make a script that opens a GUI with a short list of commonly-used symbols that can be chosen, and then be automatically be pasted.
My code so far:
!+q::
Gui, Add, ListBox, w100 h100, vSymbolChoice, ™|©|°|π|☭|☢|⚠|ツ|•|Ω
Gui, Add, Button, Default, Submit
Gui, Add, Button, default, Cancel
Gui, Show
return
ButtonSubmit:
Gui, Submit
Sleep, 1000
Send, %SymbolChoice%
Gui, Destroy
ButtonCancel:
Gui, Destroy
It creates the GUI and the ListBox but doesn't paste the symbol when I have it selcted and press submit.
Also, is there a better way to detect if a text field is selected than just waiting a second and hoping the user selected the field in that time?
; auto-execute section
; create and show the Gui
Gui, Add, ListBox, w100 h130 vSymbolChoice, ™|©|°|π|☭|☢|⚠|ツ|•|Ω
Gui, Add, Button, Default, Submit
Gui, Add, Button,, Hide ; you can't have two default buttons on a Gui
Gui, Show
return
; Press Alt+Shift+Q to show the hidden Gui after ButtonSubmit or ButtonHide
!+q:: Gui, Show
ButtonSubmit:
GuiControlGet, SymbolChoice ; get the control's contents stored in the variable SymbolChoice (retrieves the ListBox's current selection)
Gui, Submit ; saves the contents of this control to its associated variable SymbolChoice
SendInput, %SymbolChoice%
return
; Hide the Gui
ButtonHide:
Gui, hide
return
; Press ESC or close the Gui to terminate the script
GuiClose:
Esc:: ExitApp
For details see GUI in the documentation.

Paste into custom GUI with AHK

I have been working on this for a while and I have no idea how to fix this issue. I want to create a custom GUI in AutoHotKey (AHK), I would post ont he AHK Forums but I haven't been able to get my account to work so I am posting here (sorry if this is the wrong place). The ideal state is that I can paste in a list of indiscriminate length from a list, it is almost always return delimited, see the picture below. I would be happy with pasting 10 items in. I have built the GUI but I can not paste the values in with the shortcut Ctrl+v. All that happens is the first value goes into the first cell and I cannot figure out how to get the rest to paste in.
I need to be able to read the values into an array in the AHK when I click continue. Thanks for your help in advance. Below is my code to create the GUI.
Gui, Add, Text,, Please add the List that you want (10 Max at once)
Gui Add, Edit, vButton1,
Gui Add, Edit, vButton2,
Gui Add, Edit, vButton3,
Gui Add, Edit, vButton4,
Gui Add, Edit, vButton5,
Gui Add, Edit, vButton6,
Gui Add, Edit, vButton7,
Gui Add, Edit, vButton8,
Gui Add, Edit, vButton9,
Gui Add, Edit, vButton0,
Gui Add, Button, x200 y270 w88 h26 vButton02 gGoCont, Continue
Gui Add, Button, x290 y270 w88 h26 vButton03 gGoQuit, Cancel
Gui Show
return
GoCont:
{
MsgBox %Button1%
MsgBox %Button2%
}
return
GoQuit:
Gui Destroy
return
If you can stand a txt file with one name per line, called "names.txt" in the same folder as your ahk script, try something like this:
Add this to the top (it reads in your names.txt file one line at a time):
Loop, Read, names.txt
x%A_Index% := A_LoopReadLine
START EDIT (per comments):
Alternatively, if you already copied to the clipboard the several names from a spreadsheet or website table or other list, then put it this way:
Loop, parse, Clipboard, `n, `r
x%A_Index% := A_LoopField
Either way,
END EDIT
Then, replace all 10 of your edit box lines with these two lines:
Loop, 10 ; or more?
Gui Add, Edit, vButton%A_Index%, % x%A_Index%
The rest is just as you had it.
Let us know, Have fun,
Big thanks to #PGilm
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
Lastly if I want to add a keyboard shortcut to work then I mapped in one where I put the below line at the top of the code
PasteIn:
{
And then close the bracket at the end of the code and then add the shortcut. (the below can be added to the bottom of the code to work) this uses the Ctrl+v keyboard shortcut.
}
^v:: GoTo, PasteIn

How can I read multiple lines of user input in AutoHotkey?

I have an AutoHotkey script which needs to read multiple lines of employee data from a user.
InputBox, userInput, Employee Records, Please enter employee records. (One per line)
Unfortunately, an InputBox only allows users to enter a single line of text. Trying to add newlines with Enter will instead submit whatever data has been entered.
How can I take in multiple lines of user input in an AutoHotkey script?
This implements a generic multiline input function
F3::MsgBox % MultiLineInput( "Employee Records", "Please enter employee records (One per line):" )
MultiLineInput(title, prompt)
{
static input
input := ""
Gui, Add, Text,, %prompt%
Gui, Add, Edit, w400 h60 vinput
Gui, Add, Button, gokay_pressed, Okay
Gui, Add, Button, cancel X+8 YP+0, Cancel
Gui, Show, Center autosize, %title%
WinWaitClose %title%
return input
okay_pressed:
Gui Submit
Gui Destroy
return
GuiClose:
GuiEscape:
ButtonCancel:
Gui, Destroy
return
}
This demonstrates a multi-line input box
F2::
Gui, Add, Text,, Please enter employee records (One per line):
Gui, Add, Edit, w600 h60 vinput
Gui, Add, Button, gokay_pressed, Okay
Gui, Add, Button, cancel X+8 YP+0, Cancel
Gui, Show, Center autosize, Employee Records
Return
okay_pressed:
Gui Submit
Gui Destroy
MsgBox %input%
Return
GuiClose:
GuiEscape:
ButtonCancel:
Gui, Destroy
return