Instant HotString

Post your working scripts, libraries and tools
donovv
Posts: 108
Joined: 15 Apr 2017, 21:06

Instant HotString

10 Apr 2018, 00:06

hey guys so I was browsing though the ask for help forum and ran into this https://autohotkey.com/boards/viewtopic.php?f=5&t=46988 where the OP was asking for help creating an improved version of https://autohotkey.com/boards/viewtopic ... =burque505. I decided to take a crack at it and came up with this so far.

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
[edit} code updated to arochon's version
Last edited by donovv on 15 Apr 2018, 23:15, edited 4 times in total.
User avatar
derz00
Posts: 497
Joined: 02 Feb 2016, 17:54
GitHub: derz00
Location: Middle of the round cube

Re: Instant HotString

10 Apr 2018, 10:40

Yours doesn't improve one of the first issues with burque505's. After saving a hotkey, you can't add another one--the window disappears.

EDIT: Actually, his does have a "Show GUI" button in the tray menu, but it doesn't reset the edit fields
try it and see
...
donovv
Posts: 108
Joined: 15 Apr 2017, 21:06

Re: Instant HotString

10 Apr 2018, 12:44

derz00 wrote:Yours doesn't improve one of the first issues with burque505's. After saving a hotkey, you can't add another one--the window disappears.

EDIT: Actually, his does have a "Show GUI" button in the tray menu, but it doesn't reset the edit fields

My script does allow for adding multiple if you right click on the tray icon you can press show GUI and it will allow you to add a new one
burque505
Posts: 681
Joined: 22 Jan 2017, 19:37

Re: Instant HotString

10 Apr 2018, 18:25

Nice script, donovv!
Regards,
burque505
donovv
Posts: 108
Joined: 15 Apr 2017, 21:06

Re: Instant HotString

10 Apr 2018, 18:50

burque505 wrote:Nice script, donovv!
Regards,
burque505
Thank you! Took a lot of inspiration from your script planning on adding a saving feature and working on a few small bugs I noticed today
arochon
Posts: 32
Joined: 04 Apr 2018, 07:49

Re: Instant HotString

11 Apr 2018, 09:06

Great work on this so far donovv

A few issue I noticed with edited script:

1) If you "save and exit" with the list selection on "select a hotstring to edit" the program throws an error

2)if you "save and exit" with selection on a hotstring you have already created, the program duplicates it the next time you run it

3)show gui command in system tray throws an error
arochon
Posts: 32
Joined: 04 Apr 2018, 07:49

Re: Instant HotString

11 Apr 2018, 13:08

added this to the top of the script

Code: Select all

Gui Instant:+LastFoundExist
IfWinExist
{
Gui, Instant:Show
}
else
{
and changed gui destroy commands to gui hide

helped solve a lot of error issues
burque505
Posts: 681
Joined: 22 Jan 2017, 19:37

Re: Instant HotString

11 Apr 2018, 17:41

Nice addition. Just for clarity:

Code: Select all

#singleinstance force
#warn 

Gui Instant:+LastFoundExist
IfWinExist
{
Gui, Instant:Show
}
else
{
menu ,tray,add,show gui,creategui
;----------------------variables-----------------------------------------------------------
hsarray := []
hshandle1 := []
hshandle2 := []
edits := 0
goto creategui 
return
}
I know it's not that hard to figure out, but as posted the 'else' is missing a brace.

Regards,
burque505
arochon
Posts: 32
Joined: 04 Apr 2018, 07:49

Re: Instant HotString

12 Apr 2018, 21:36

Adapted above version posted.

- Changed GUI
- Disabled all buttons that cause script errors
- Enabled buttons to edit/save when needed
- Auto reloads after saving
- Exit/Minimize added
- Removed tray menu button to show gui (caused errors)
- Eliminated duplicate entry errors
- Removed GUI destroy commands

Let me know what you guys think.....

Code: Select all

#singleinstance force
;#warn 
;----------------------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("::"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 edits = 0
	{
		hotstring("::"hs1,hs2)
		hshandle1.push(hs1)
		hshandle2.push(hs2)
		fileappend,%hs1%|%hs2%`n,%txtfile%
		reload
	}
	if edits = 1
	{	
		hsn := ddlx - 1
		hotstring("::"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 h25 disabled gsavehs,Save
	gui Instant: add, button,x450 yp+26 w90 h25 gexit,Exit
	gui Instant: show, w550 h233,Custom Command Creator
	
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("::"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: minimize
Last edited by arochon on 13 Apr 2018, 17:50, edited 3 times in total.
burque505
Posts: 681
Joined: 22 Jan 2017, 19:37

Re: Instant HotString

13 Apr 2018, 14:15

arochon, it crashes if the replacement text has a paragraph, an empty line, and another pargraph.
Regards,
burque505
arochon
Posts: 32
Joined: 04 Apr 2018, 07:49

Re: Instant HotString

13 Apr 2018, 14:27

Burque505,

I noticed this as well today. I am looking into remapping or somehow eliminating the use of enter in the “hs2” box or figuring out away to include paragraphs. I’ll spend some time on it tonight. Let me know if you guys have any ideas. I’m also working on a way to import/switch default textfile using select file commands.

Cheers
arochon
Posts: 32
Joined: 04 Apr 2018, 07:49

Re: Instant HotString

13 Apr 2018, 16:53

Added this to bottom of script to keep from crashing for now. Still looking for a way to include returns without error.

Code: Select all

#IfWinActive Custom Command Creator
ENTER::SPACE
RETURN::SPACE
NUMPADENTER::SPACE
RETURN
arochon
Posts: 32
Joined: 04 Apr 2018, 07:49

Re: Instant HotString

14 Apr 2018, 17:16

-Eliminated missing text field crashes by adding error messages and instructions.
-Modified key maps to not allow returns that create errors in hs2 input box
-Added button for select file to change txt document source, still working to make this operable - let me know if you have any ideas.

Code: Select all

#singleinstance force
;----------------------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("::"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("::"hs1,hs2)
		hshandle1.push(hs1)
		hshandle2.push(hs2)
		fileappend,%hs1%|%hs2%`n,%txtfile%
		reload
	}
	if edits = 1
	{	
		hsn := ddlx - 1
		hotstring("::"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 h25 disabled gsavehs,Save
	gui Instant: add, button,x450 yp+26 w90 h25 gexit,Exit
	gui Instant: add, button,x450 yp+26 w90 h25 gfileget,Select File
	gui Instant: show, w550 h233,Custom Command Creator
	
return


fileget:
FileSelectFile, txtfilealt, 3, %a_scriptdir%, Open a file, Text Documents (*.txt) 
global txtfile := txtfilealt
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("::"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


burque505
Posts: 681
Joined: 22 Jan 2017, 19:37

Re: Instant HotString

15 Apr 2018, 13:20

Hi arachon, one modest suggestion:

Code: Select all

hotstring(":R:"hshandle1[a_index],hshandle2[a_index])
will keep it from choking on control chars, et cetera. Try this for a replacement text with your present code and you'll see what I mean:

Code: Select all

!ye be a sniveling *$% +black#purple^white/brown cow, now!!!$!@
as a replacement text becomes

Code: Select all

e be a sniveling *$% Blackurplehite/brown cow, now
and yields some other disconcerting behavior from Windows :)
If you use the ":R:" option for the hotstrings that won't happen.

Regards,
burque505
arochon
Posts: 32
Joined: 04 Apr 2018, 07:49

Re: Instant HotString

15 Apr 2018, 13:51

burque505,

Thank you for the suggestion. I see what happened with windows controls when replacement text went into the computer.

Where is the best place to insert that line of code?

Thank you,

arochon
arochon
Posts: 32
Joined: 04 Apr 2018, 07:49

Re: Instant HotString

15 Apr 2018, 13:54

Never mind I found it.

Replaced:

Code: Select all

hotstring("::"hshandle1[a_index],hshandle2[a_index])
burque505
Posts: 681
Joined: 22 Jan 2017, 19:37

Re: Instant HotString

15 Apr 2018, 18:56

Sorry, that wasn't very clear, my apologies. What I did was replace

Code: Select all

hotstring("::
with

Code: Select all

hotstring(":R:
everywhere in the script.
Regards,
burque505
arochon
Posts: 32
Joined: 04 Apr 2018, 07:49

Re: Instant HotString

15 Apr 2018, 19:25

- Updated with :R: option as suggested above
- Added Import command list option
- Added Export command list option

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

Return to “Scripts and Functions”

Who is online

Users browsing this forum: Bon and 40 guests