Moin bichlepa,
weil das Thema wieder hochgekommen ist, habe ich mich auch noch einmal internsiver mit den Skripten beschäftigt.
Ich habe mich dann daran erinnert, dass ich auch schon mal einen Skriptgenerator geschrieben habe, der erst ähnlich wie Dein
AddCode() das Skript zeilenweise aufgebaut hat. Weil das auch noch 'schön' aussehen sollte, habe ich mich immer wieder damit herumgeärgert, wenn sich nachträgliche Änderungen auf mehrere Zeilen auswirkten. Ich habe dann für die überwiegend 'festen' Teile 'Templatedateien' erstellt, die im Stück eingelesen und dann soweit nötig über 'Platzhalter' modifiziert werden. Das hat das Editieren dieser Skriptteile für mich deutlich vereinfacht.
Nachdem ich mir sowohl
unicode enter generator.ahk als auch das 'Ergebnis'
unicode enter script.ahk angeschaut habe, bin ich der Meinung, dass Du für den 'festen' ein Template nutzen kannst. Als Platzhalter habe ich Zeichenketten im Format
???...??? verwendet.
Template.ahk:
Code: Select all
#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%
#persistent
#hotstring ?*B0
???FileInclude???
showNewChar:
gosub prepareNewChar
return
???TriggerHotkey???::
gosub showNextChar
return
prepareNewChar:
lastsentchar:=""
lastsentindex:=0
if instr(a_thishotkey, "::")
{
lastsentlength:=strlen(substr(a_thishotkey,3))
}
else
{
lastsentlength:=0
}
return
showNextChar:
settimer, turnOffTooltip, off
settimer, turnOffHotkeyShowNextChar, off
lastsentindex++
if (lastsentindex > currentChars.maxindex())
lastsentindex = 1
currentcharsstring =
currentcharsstring1 =
currentcharsstring2 =
for oneindex, onechar in currentChars
{
if (oneindex < lastsentindex)
{
currentcharsstring1.= onechar
if (CurrentExplanations[oneindex])
{
currentcharsstring1.= "(" CurrentExplanations[oneindex] ")"
}
currentcharsstring1.= "`n"
}
else
{
currentcharsstring2.= onechar
if (CurrentExplanations[oneindex])
{
currentcharsstring2.= "(" CurrentExplanations[oneindex] ")"
}
currentcharsstring2.= "`n"
}
}
currentcharsstring := currentcharsstring2 currentcharsstring1
if (A_CaretX && A_CaretY)
{
tooltip,% currentcharsstring, % A_CaretX, % A_CaretY +20
}
else
{
tooltip,% currentcharsstring
}
send,{bs %lastsentlength%}
sendraw,% currentChars[lastsentindex]
lastsentchar:=currentChars[lastsentindex]
lastsentlength:=new_strlen(currentChars[lastsentindex])
loop
{
if (GetKeyState("???TriggerHotkey???") == False)
break
sleep 10
}
settimer, turnOffTooltip, -1000
settimer, turnOffHotkeyShowNextChar, -5000
settimer, turnOffHotkeyShowNextChar2, 1
return
turnOffHotkeyShowNextChar:
hotkey,???TriggerHotkey???,showNextChar, off
settimer, turnOffHotkeyShowNextChar, off
settimer, turnOffHotkeyShowNextChar2, off
return
turnOffHotkeyShowNextChar2:
Input, SingleKey, L1 T0.2 V, {LControl}{RControl}{LAlt}{RAlt}{LShift}{RShift}{LWin}{RWin}{AppsKey}{F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}{Left}{Right}{Up}{Down}{Home}{End}{PgUp}{PgDn}{Del}{Ins}{BS}{Capslock}{Numlock}{PrintScreen}{Pause}
if (SingleKey && SingleKey != "???TriggerHotkey???")
goto turnOffHotkeyShowNextChar
return
turnOffTooltip:
tooltip
return
showSymbols:
hotkey,???TriggerHotkey???,showNextChar, on
settimer,turnOffHotkeyShowNextChar, -5000
if (not instr(a_thishotkey,":?:"))
{
settimer,prepareNewChar,-1
}
else
{
settimer,showNewChar,-1
}
return
new_strlen(newstrlen_string)
{
newstrlen_length:=0
loop,parse,newstrlen_string
{
newstrlen_length++
Transform,newstrlen_charnumber,asc,%A_LoopField%
if (newstrlen_charnumber >= 0xDC00 && newstrlen_charnumber <= 0xDFFF)
newstrlen_length--
}
return newstrlen_length
}
Ich habe hier noch ein Label
showSymbols: eingefügt, das die (für mich) festen Teile aus den Hotkey/string Routinen enthält. Der Code für die Generierung der Hotkeys/strings sähe dann so aus:
Code: Select all
for oneindex, oneentry in allEntriesInverted
{
;~ MsgBox % oneentry.keytype " -" oneentry.keyname " - " oneentry.chars[1] "," oneentry.chars[2] "," oneentry.chars[3]
;Add hotkey or hotstring
If (oneentry.keytype = "hotkey")
{
addcode("~" oneentry.keyname "::")
}
else
addcode("::" oneentry.keyname "::")
;Write variables which will contain the strings and their comments
codeline:="CurrentChars:= ["
codelineexpl:="CurrentExplanations:= ["
for onecharindex, onechar in oneentry.chars
{
if a_index > 1
{
codeline.=", "
codelineexpl.=", "
}
codeline.="""" onechar """"
codelineexpl.="""" oneentry.explanations[onecharindex] """"
}
codeline.="]"
codelineexpl.="]"
addcode(codeline)
addcode(codelineexpl)
addcode("gosub, showsymbols")
addcode("return")
; ;Enable hotkey
; addcode("hotkey," triggerhotkey ",showNextChar, on")
; ;~ addcode("fileappend,%a_tickcount% %a_thishotkey%, log.txt") ;only for debugging
; addcode("settimer,turnOffHotkeyShowNextChar, -5000") ;disable the hotkey after some seconds
;
; addcode("if (not instr(a_thishotkey,"":?:""))")
; addcode("{")
; ;If this is a hotkey, only prepare the new char without showing it. It will only be shown when user presses the hotkey
; addcode(" settimer,prepareNewChar,-1")
; addcode("}")
; addcode("else")
; addcode("{")
; ;If this is a hotstring, the user already pressed the hotkey. So show the first char
; addcode(" settimer,showNewChar,-1")
; addcode("}")
; addcode("return")
progresspercentage:=6+(94/countallEntriesInverted*A_Index)
}
Den Code für die Generierung des festen Teils stelle ich mir so vor:
Code: Select all
FileRead, scriptcode, *t Template.ahk
If (ErrorLevel)
{
MsgBox, 16, Unicode enter generator, Couldn't find or read the file Template.ahk.`nThe program will exit.
ExitApp
}
scriptcode := StrReplace(scriptcode, "???FileInclude???", fileinclude)
scriptcode := StrReplace(scriptcode, "???TriggerHotkey???", triggerhotkey)
scriptcode .= "`n"
Vielleicht gefällt Dir die Idee? (Ich habe das allerdings nicht wirklich getestet!)
Ostergrüße!
just me
Edit: Template.ahk gefixt: Break statt ???TriggerHotkey???