Page 1 of 1
how to replace multiple ::key:: to a copy-paste function ?
Posted: 06 Dec 2021, 11:08
by S_N
i have many hotkeys which type text letter by letter...
sorry... i just recently discovered clipboard ...
is there a way to re-script my code to make it simpler ?
i tried replacing a few of the codes, but its quite painful/time-consuming to do for all the lines...
example
Code: Select all
::^F3::alongstringoftext
::shortcut::
SendInput `
(
alongparagraph
withmultiple
lines
)
return
my current... painful to apply solution...:
Code: Select all
::^F3::
t_str=
(
alongstringoftext
)
return
::shortcut::
t_str=
(
alongparagraph
withmultiple
lines
)
copypasta(t_str)
return
copypasta(t_str)
{
clipboard:=t_str
send ^v
clipboard:=""
return
}
Re: how to replace multiple ::key:: to a copy-paste function ?
Posted: 06 Dec 2021, 11:17
by mikeyww
If you are using a standard edit control, you can also use the
Control, EditPaste command.
You could put all of your text into a separate text file that includes delimiters. Your script could then just read the file. It's just another way to manage your text, neither better nor worse in the final outcome. An INI file might even be handy.
IniRead
Code: Select all
Global ini := StrReplace(A_ScriptFullPath, ".ahk", ".ini")
IniWrite, alongparagraph|withmultiple|lines, %ini%, Section1, par1
F3::paste("Section1", "par1")
paste(section, key) {
IniRead, ttext, %ini%, %section%, %key%
Clipboard := "", Clipboard := StrReplace(ttext, "|", "`n")
ClipWait, 0
If ErrorLevel
MsgBox, 48, Error, An error occurred while waiting for the clipboard.
Else Send ^v
}
Re: how to replace multiple ::key:: to a copy-paste function ?
Posted: 07 Dec 2021, 18:46
by S_N
ok i got to this place , where hotkeys seem to be assigned,
but i'm unable to pass the %value% outside into the copypasta function
i added global but that only gives me the last line in the definitions list with any hotkey used ...
thank you !
Code: Select all
KEYSARRAY := []
global key
global value
IniFile := "hkdefinitions.ini" ;-------- hot key definitions list file
IniRead, hkinireadvar, %IniFile%, hotkeys
KEYSARRAY := Object(StrSplit(hkinireadvar, ["=", "`n"])*) ; make array by splitting using '=' and '`n' as delimiters.
for key,value in KEYSARRAY
hotkey, %key%, copypasta
return
copypasta(){
Clipboard := %value%
ClipWait, 0
If ErrorLevel
MsgBox, 48, Error, An error occurred while waiting for the clipboard.
else send ^v
}
Re: how to replace multiple ::key:: to a copy-paste function ?
Posted: 07 Dec 2021, 19:41
by mikeyww
You can post your INI file here.
Re: how to replace multiple ::key:: to a copy-paste function ?
Posted: 07 Dec 2021, 23:11
by S_N
mikeyww wrote: ↑07 Dec 2021, 19:41
You can post your INI file here.
Its just test stuff ini
Code: Select all
[hotstrings]
sn1=0123456789
sn2=987654321
[hotkeys]
^f1=Short words
+c=Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam convallis justo ac libero scelerisque, vitae scelerisque libero gravida. Nam malesuada nunc nulla, id ornare massa accumsan at. Curabitur at turpis feugiat,
F3=mark
Re: how to replace multiple ::key:: to a copy-paste function ?
Posted: 08 Dec 2021, 05:58
by mikeyww
Code: Select all
dir := A_ScriptDir
IniFile := dir "\hkdefinitions.ini"
KEYSARRAY := {}
IniRead, hkinireadvar, %IniFile%, hotkeys
For each, line in StrSplit(hkinireadvar, "`n") {
RegExMatch(line, "(.+?)=(.*)", part), KEYSARRAY[part1] := part2
Hotkey, %part1%, copypasta
}
Return
copypasta:
Clipboard := "", Clipboard := KEYSARRAY[A_ThisHotkey]
ClipWait, 0
If ErrorLevel
MsgBox, 48, Error, An error occurred while waiting for the clipboard.
Else Send ^v
Return