visual_TableTexter.ahk
Posted: 01 Jul 2018, 18:32
Habe hier meinen "Quick`n`Dirty" Code für meine Texttabellenerstellung in SciTE gepostet. Hab zwar noch einen zweiten Code der die Breite der Tabellenspalten (vielmehr die Anzahl der Füllzeichen) anhand der virtuellen Textbreite unter Benutzung der eingestellten Schriftart in SciTE errechnen soll. Aber da knacke ich so einige Dinge nicht, aus SciTE sozusagen ein Office-Ersatz zu machen ist nicht so einfach. Das hier ging deutlich schneller. Wie man sieht auch nicht "Bug-free"! Ist eben kein "Coffee to go". Ich sehe aber immer gern dem Caret zu, weil es so schön hin und her hüpft. Und bin völlig gespannt ob es am Ende gegen die Latte '|' rennt.
Falls es jemand benutzen möchte.
Das Caret braucht ein Skelett an dem es sich orientieren kann. Es braucht also oberhalb ein leeres Zellengerüst z.B.:
Warum beim ersten Start wie oft nichts im Clipboard ist weiß ich nicht. Deshalb habe ich auch eine MsgBox zum Abbrechen eingefügt. Eben nochmal Strg+R und dann geht es immer.
So Bettzeit!
Falls es jemand benutzen möchte.
Das Caret braucht ein Skelett an dem es sich orientieren kann. Es braucht also oberhalb ein leeres Zellengerüst z.B.:
Code: Select all
;| | | | |
Code: Select all
#IfWinActive ahk_class SciTEWindow
^r:: ;{ ;--helps to write the documentation for AHK-Rare
SetKeyDelay, 0, 0
SetBatchLines, -1
MarkDownApp:= "Typora" ;use your own documentation Softwaretitle here, this is for
MarkDownAppName:= "Typora" ;if name of window and app title doesnt match
Send, {Home}{Shift Down}{End}{Shift Up}
Send, {CTRL down}c{CTRL up}
ClipWait, 8
markedCode:= Clipboard
cutpos1:= Instr(markedCode, "`(")
cutpos2:= Instr(markedCode, "`)")
cutpos3:= Instr(markedCode, "`;--") + 2
txtforscript:= " " . SubStr(markedCode, 1, cutpos1) . "`)"
txtforMarkDownApp:= "**" . Trim(SubStr(markedCode, 1, cutpos1) . SubStr(markedCode, cutpos2, 2)) . "** " . SubStr(markedCode, cutpos3, StrLen(markedCode)-cutpos3+3)
MsgBox, 4, Inhalt des Clipboards, Text zum Einfügen ins AHK-Script:`n%txtforscript%`n---------------------------------------------------------------------------`nText zum Einfügen bei %MarkDownAppName%:`n%txtforMarkDownApp%`n---------------------------------------------------------------------------`n`nMöchtest Du weitermachen?
IfMsgBox, No
return
caretx:=A_CaretX, carety:=A_CaretY - 20
ToolTip, Setze jetzt den Curser in`nder Scripttabelle einfach in die richtige Zelle!.`nDie genaue Position ist egal!`n`nIch warte auf Strg+linke Maustaste`n!Tasten loslassen! zum Auslösen der Funktion.,%caretx%, %carety%, 11
;{ Wait for LeftMousebutton down & {LControl Down} and waits for releasing both keys
KeyWait, LControl, D
KeyWait, LButton, D
sleep, 100
KeyWait, LControl
KeyWait, LButton
;}
;this part can be removed - its for SciTE - You only lose the function controlling the number of columns in your table, so you have to manually control it
oSciTE := GetSciTEInstance()
if !oSciTE {
MsgBox, 16, SciTE4AutoHotkey, Cannot find SciTE!
ExitApp
}
hSciTE := oSciTE.SciTEHandle
ControlGet, scintillahwnd, Hwnd,, Scintilla1, ahk_id %hSciTE%
Pos:=SciUtil_GetCurPos(hSci)
thisline:= SciUtil_LineFromPos(hSci, Pos)
If (StrCount(thisline,"|")=4) { ;if you want more columns change 4 to what you need
Send, {ENTER}
SendRawFast(";|")
} else {
lastColumn:= Instr(thisline, "|", -1)
}
SendRawFast(txtforscript)
;{ The loop for space and tabs in your editor
SetKeyDelay, -1, -1
Loop {
Send, {Up}
Send, {LShift Down}{Right}{LShift Up}
Send, {CTRL Down}c{CTRL Up} ;goes up the line, selects the upper character
ClipWait, 8
If !(clipboard=="`|") { ;if no '|' add space to column
Send, {Down}
Send, {Space}
}
else { ;end it and send '|'
Send, {Down}
SendRaw, `|
Send, {Left 1}
Send, {BackSpace 2}
Send, {Tab}
Send, {End}
;~ Send, {Space 3} ;this spaces are not needed anymore
break
}
;}
SetKeyDelay, 20, 50
}
SetKeyDelay, 20, 50
ToolTip, Setze jetzt den Curser in`nTypora an die Einfügeposition.`n`nIch warte auf Strg+linke Maustaste`n!Tasten loslassen! zum Auslösen der Funktion.,%caretx%, %carety%, 11
WinWaitActive, %MarkDownApp%
;{ Wait for LeftMousebutton down & {LControl Down} and waits for releasing both keys
KeyWait, LControl, D
KeyWait, LButton, D
sleep, 100
KeyWait, LControl
KeyWait, LButton
;}
SetKeyDelay, 0, 0
WinGetActiveTitle, MarkDowner
If Instr(MarkDowner, MarkDownApp) {
SendRawFast(txtforMarkDownApp)
Send, {Enter} ;neue Zeile
Send, {Alt Down}s{AltUp} ;save entry to file
}
ToolTip, Okay ready.,%caretx%, %carety%, 11
sleep, 5000
ToolTip,,,, 11
return
;}
#IfWinActive
SendRawFast(string) {
SetKeyDelay, 0, 0
SendRaw, %string%
SetKeyDelay, 20, 50
}
So Bettzeit!