what it does:
allows you to create, edit and delete hotstrings on the fly.
saves hotstrings over session
Code: Select all
#singleinstance force
#notrayicon
;----------------------variables-----------------------------------------------------------
global hshandle1 := []
global hshandle2 := []
global txtfilea := []
global txtfile := a_scriptdir . "\mycommands.txt"
edits := 0
getsaved()
goto creategui
return
getsaved()
{
loop, read, %txtfile%
{
regexmatch(a_loopreadline,".*(?=\|)",hs1)
hshandle1.push(hs1)
regexmatch(a_loopreadline,"(?<=\|).*",hs2)
hshandle2.push(hs2)
}
loop % hshandle1.length() ;%
{
hotstring(":R:"hshandle1[a_index],hshandle2[a_index])
}
return
}
addhs:
guicontrol Instant: enable, hs1
guicontrol Instant: enable,hs2
guicontrol Instant: enable,button4
return
savehs:
gui Instant: submit
If (hs2 = "") and (hs1 = "") ; Checks if hs2 and hs1 are blank
{
MsgBox, 0, Missing Both Text Fields!, Missing Both Text Fields! You must complete both fields prior to saving. Each entry requires a command text and replacement text.
hs2= You must enter both a command and replacement text before saving. Click "Delete Command" and try again.
hs1= Delete this command
}
If (hs2 = "") ; Checks if hs2 is blank
{
MsgBox, 0, Missing Replacement Text!, Missing Replacement Text! Select your command in the drop down list. Click "Edit Command" and try again.
hs2= Enter Command Text Here
}
If (hs1 = "") ; Checks if hs1 is blank
{
MsgBox, 0, Missing Command Text!, Missing Command Text! You must complete both fields prior to saving. Each entry requires a command text and replacement text.
hs2= You must enter both a command and replacement text before saving. Click "Delete Command" and try again.
hs1= Delete this command
}
if edits = 0
{
hotstring(":R:"hs1,hs2)
hshandle1.push(hs1)
hshandle2.push(hs2)
fileappend,%hs1%|%hs2%`n,%txtfile%
reload
}
if edits = 1
{
hsn := ddlx - 1
hotstring(":R:"hs1,hs2)
hshandle2[hsn] := hs2
loop, read, %txtfile%
{
regexmatch(a_loopreadline,".*(?=\|)",match)
if (match != hs1)
txtfilea.push(a_loopreadline)
else
txtfilea.push(hs1 "|" hs2)
}
filedelete,%txtfile%
sleep 1000
loop % txtfilea.length() ;%
{
txt := txtfilea[a_index]
fileappend, %txt%`n,%txtfile%
}
reload
txtfilea := []
}
return
creategui:
list :=
loop % hshandle1.length() ;%
{
list := list . hshandle1[a_index] . "|"
}
gui Instant: font, s10
gui Instant: add,ddl,x20 y2 w400 h200 choose1 vddlx gddledit altsubmit hwndhcbx,Add Command or Select Command to Edit|%list%
PostMessage, 0x153, -1, 30,, ahk_id %hcbx%
gui Instant: add, text,x85 y46 ,Command Text:
gui Instant: add, edit,disabled vhs1 x200 y45 w220,
gui Instant: add, text,x20 y75 ,Replacement Text:
gui Instant: add, edit,disabled vhs2 x20 y99 w400 h125,
gui Instant: font,s8
gui Instant: add, button,x450 y2 w90 h25 gaddhs,Add Command
gui Instant: add, button,x450 yp+26 w90 h25 disabled gdelhs,Delete Command
gui Instant: add, button,x450 yp+26 w90 h25 disabled gediths,Edit Command
gui Instant: add, button,x450 yp+26 w90 h40 disabled gsavehs,Save
gui Instant: add, button,x450 yp+41 w90 h40 gexit,Exit
gui Instant: add, button,x450 yp+41 w90 h30 gfileexp,Export Commands
gui Instant: add, button,x450 yp+31 w90 h30 gfileget,Import Commands
gui Instant: show, w550 h233,Custom Command Creator
return
fileget:
FileSelectFile, SelectedFile, 3, , Open a file, Text Documents (*.txt)
FileCopy, %SelectedFile%, %a_scriptdir%\mycommands.txt, 1
reload
return
fileexp:
FileSelectFile, ExportFile, S, mycommands.txt, Text Documents (*.txt)
FileCopy, %txtfile%, %ExportFile%, 1
return
ddledit:
gui Instant: submit, nohide
hsn := ddlx - 1
guicontrol Instant:, hs1,% hshandle1[hsn] ;%
guicontrol Instant:, hs2,% hshandle2[hsn] ;%
if hsn != 0
{
guicontrol Instant: enable,button2
guicontrol Instant: enable,button3
guicontrol Instant: disabled,button1
guicontrol Instant: disabled, hs1
guicontrol Instant: disabled,hs2
guicontrol Instant: disabled,button4
} else
{
guicontrol Instant: disabled,button2
guicontrol Instant: disabled,button3
guicontrol Instant: enable,button1
guicontrol Instant: disabled,button4
}
return
delhs:
gui Instant: submit
hotstring(":R:"hshandle1[ddlx - 1], hshandle2[ddlx - 1] , "off")
hshandle1.removeat(ddlx - 1)
hshandle2.removeat(ddlx - 1)
loop, read, %txtfile%
{
regexmatch(a_loopreadline,".*(?=\|)",match)
if (match != hs1)
{
txtfilea.push(a_loopreadline)
}
}
filedelete,%txtfile%
sleep 1000
loop % txtfilea.length() ;%
{
txt := txtfilea[a_index]
fileappend, %txt%`n,%txtfile%
}
reload
txtfilea := []
return
ediths:
gui Instant: submit, nohide
edits := 1
guicontrol Instant: enable,hs2
guicontrol Instant: enable,button4
return
exit:
gui Instant: hide
return
#IfWinActive Custom Command Creator
ENTER::SPACE
RETURN::SPACE
NUMPADENTER::SPACE
RETURN
#IfWinNotActive Custom Command Creator