hotstrings/clipboard question (SOLVED)

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
arochon
Posts: 32
Joined: 04 Apr 2018, 07:49

hotstrings/clipboard question (SOLVED)

09 Apr 2018, 09:36

I have spent quite a bit of time trying to adapt some of the instanthotstring.ahk code by burque505 and InstantHotkey.ahk by Jack Dunning to a project I am working on.
Thank you both for your work on this project as it has opened some new ideas for what I am trying to accomplish.

My problem is that once a string has been created it has to be edited within the showhotstring GUI using the same input text or it will continue to run in the background.

I want to be able to destroy that hotstring if I replace it with a new input/output within that GUI. Is this possible?

I have tried to use stringreplace without success (notated in code) and experimented with clipboard commands and haven't had any luck.

This is a snippet of the whole code to keep things simple. I have 5 other custom buttons (buttoncustom-2,buttoncustom-3....etc) that are in the main GUI that have the same function.

After I figure this out I would like to find a way to save the commands to file so they can be reloaded to the GUI next time the program runs.



Code: Select all

Gui, Add, Button, x551 y12 w100 h30 vcustom1 , Custom-1
Gui, Show, x674 y381 h233 w652,
return
buttonCustom-1:
Gui new:+LastFoundExist
IfWinExist
{
Gui, new:Show
ControlFocus, Edit1
}
else
{
#NoEnv 
SendMode Input  
SetWorkingDir %A_ScriptDir% 
#SingleInstance off
Gui, new:Add, Text,, Enter Custom Command
Gui, new:Add, Edit, vHString ys
Gui, new:Add, Edit, w400 r8 vTextInsert xs, <Insert command text here>
Gui, new:Add, Button, gSetupString, Set Custom Command #1
Gui, new:Show, , Custom Shorthand #1
Return


SetupString:
Gui, new:Submit
If HString !=
{
    NewText := Hotstring(":*:"Hstring, TextInsert)
    gosub, TextAdd
SetTimer, update1,-250
}
Else {
    msgbox 
	(
	No custom command created. You must enter a command and a command output text. Please try again.
	)
    gosub, ShowHotstring
SetTimer, update-1,-250
}
    

TextAdd:
OldClip = Clipboard
Clipboard =
Clipboard = %NewText%
Clipwait, 0.3
 Send, ^ 
Clipboard = %OldClip%
OldClip =
;---------------------- Below settimer command had no effect--------------------------------------
Settimer, changed1

changed1:
StringReplace, clipboard, clipboard, %Hstring%, %TextInsert%, All 

;---------------------- Above settimer command had no effect--------------------------------------

update1:
GuiControl, , custom1 , %HString%
return

update-1:
GuiControl, , custom1 , Custom-1
return

ShowHotstring:
Gui, new:Show
ControlFocus, Edit1
Return
}
return
Last edited by arochon on 13 Apr 2018, 10:09, edited 1 time in total.
donovv
Posts: 108
Joined: 15 Apr 2017, 21:06

Re: hotstrings/clipboard question

10 Apr 2018, 00:11

Your post got me thinking give this a try still working on saving and reloading the hotstrings should have that added by tomorrow

https://autohotkey.com/boards/viewtopic.php?f=6&t=47024
arochon
Posts: 32
Joined: 04 Apr 2018, 07:49

Re: hotstrings/clipboard question

10 Apr 2018, 20:41

donovv,

Great work on this. Exactly what I was looking to do. The reloading hotstrings would be awesome. I have thought about also making a separate gui window with checkbox for the list of commands so they can easily be enabled/disabled at the users preference. That way you can just deselect the ones you don't want to use as opposed to deleting them and then having to recreate them later.

Anyways thank you for the help. Excited to see this reloading feature if you finish up on it.

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

Re: hotstrings/clipboard question

10 Apr 2018, 21:09

donnov,

I tried using that code some more and ran into issues after editing the output text. After editing the output text for the hotstings, saving and exiting, the hotstring does not work at all.

For example: if you assign "lol" to "laugh out loud" then save and exit it works perfect. After clicking "show gui" in the tray, selecting the hotstring to edit (lol), then changing "laugh out loud" to something else, save and exit. When you type "lol" nothing appears.
donovv
Posts: 108
Joined: 15 Apr 2017, 21:06

Re: hotstrings/clipboard question

10 Apr 2018, 21:43

arochon wrote:donnov,

I tried using that code some more and ran into issues after editing the output text. After editing the output text for the hotstings, saving and exiting, the hotstring does not work at all.

For example: if you assign "lol" to "laugh out loud" then save and exit it works perfect. After clicking "show gui" in the tray, selecting the hotstring to edit (lol), then changing "laugh out loud" to something else, save and exit. When you type "lol" nothing appears.
thanks for the feed back I'm actually working on it right now that's one of the issues i found earlier today I'm also working on having it save hotstrings over sessions

[edit 1] I've fixed the edit issue(I think) ill post code here shortly
donovv
Posts: 108
Joined: 15 Apr 2017, 21:06

Re: hotstrings/clipboard question

10 Apr 2018, 23:09

New code up save working let me know if you find any bugs
arochon
Posts: 32
Joined: 04 Apr 2018, 07:49

Re: hotstrings/clipboard question

11 Apr 2018, 07:26

new code works great so far. only issue is that an error occurs when trying to use your "show gui" tray icon. Ive only got it to work once. However if you run the ahk again it pulls up everything. Very neat.

Thank you for the help.
arochon
Posts: 32
Joined: 04 Apr 2018, 07:49

Re: hotstrings/clipboard question

11 Apr 2018, 07:38

donovv,

Another feature you may look into is to be able to save the new hotsting and auto update the gui instead of having to save and exit every time you want to add a new one. Maybe have just a "save" button?
arochon
Posts: 32
Joined: 04 Apr 2018, 07:49

Re: hotstrings/clipboard question

13 Apr 2018, 10:05

Adapted your version donovv. Take a look and let me know what you think.

Cheers!


- 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

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, peter_ahk and 409 guests