Variable copy paste

Winkletter • 1 May 2023 •
I want to get back to my reading. A sea serpent fight is in progress. So I’ll just share an AutoHotKey script I had ChatGPT write today. On a Windows PC with AHK installed it lets you save data to any alphanumeric key and lets you retrieve it later.
Here’s ChatGPT’s description and code.
This AutoHotKey script allows you to store and retrieve text snippets in designated variables using alphanumeric keys (0-9 and A-Z) on your keyboard. It provides the following functionality:
Save text to a variable: To save a selected text snippet or manually input text to a variable, press and release CTRL+ALT+C, then press an alphanumeric key (0-9, A-Z). If text is selected, it will be saved to the chosen variable. If no text is selected, you will be prompted to enter the text you wish to save.
Retrieve text from a variable: To paste the text stored in a specific variable, press and release CTRL+ALT+V, then press the corresponding alphanumeric key (0-9, A-Z). The text from the specified variable will be pasted at your cursor location.
Clear a variable: To clear the text stored in a specific variable, press and release CTRL+ALT+X, then press the corresponding alphanumeric key (0-9, A-Z). This will remove the text from the chosen variable.
Reload the script and clear all variables: Press CTRL+ALT+Z to reload the AutoHotKey script, which will reset and clear all the stored variables.
This script is particularly useful for managing multiple text snippets and pasting them quickly and efficiently while working on various tasks.
; Initialize an empty associative array for the variables
variables := {}
; Save data to a variable with CTRL+ALT+C
^!c up::
KeyWait, c
KeyWait, Alt
KeyWait, Ctrl
Send ^c
Sleep, 100
Input, variableKey, L1 T2
if !variableKey
return
if !IsClipEmpty()
{
variables[variableKey] := Clipboard
MsgBox, Data saved to variable %variableKey%.
}
else
{
InputBox, data, Save data to variable %variableKey%, Enter the data you want to save:
if !ErrorLevel
{
variables[variableKey] := data
MsgBox, Data saved to variable %variableKey%.
}
}
return
; Retrieve data from a variable with CTRL+ALT+V
^!v up::
KeyWait, v
KeyWait, Alt
KeyWait, Ctrl
Input, variableKey, L1 T2
if variables.HasKey(variableKey)
{
Clipboard := variables[variableKey]
Send ^v
}
else
MsgBox, No data found in variable %variableKey%.
return
; Clear a variable with CTRL+ALT+X
^!x up::
KeyWait, x
KeyWait, Alt
KeyWait, Ctrl
Input, variableKey, L1 T2
if variables.HasKey(variableKey)
{
variables.Remove(variableKey)
MsgBox, Data cleared from variable %variableKey%.
}
else
MsgBox, No data found in variable %variableKey%.
return
; Reload the script and clear all variables with CTRL+ALT+Z
^!z::
Reload
return
; Function to check if the clipboard is empty
IsClipEmpty()
{
ClipSaved := ClipboardAll
Clipboard := ""
Send ^c
ClipWait, 0.5, 1
isEmpty := (Clipboard == "")
Clipboard := ClipSaved
return isEmpty
}
And here is ChatGPT’s instructions to add the script to the Windows startup folder.
To have the script start automatically when you log in to your Windows account, you can create a shortcut to the script and place it in the “Startup” folder. Here’s how to do it:
- First, make sure your AutoHotKey script is saved as a .ahk file on your computer.
- Right-click the .ahk file, then click “Create shortcut”. This will create a shortcut for the script.
- Press Win+R to open the “Run” dialog box.
- Type shell:startup and press Enter. This will open the “Startup” folder.
- Move or copy the shortcut you created in step 2 to the “Startup” folder.
Now, every time you log in to your Windows account, the AutoHotKey script will start automatically.Keep in mind that you need to have AutoHotKey installed on your computer for the script to run. If you don’t have it installed, you can download it from the official website: https://www.autohotkey.com/