visual_TableTexter.ahk

Veröffentliche deine funktionierenden Skripte und Funktionen

Moderator: jNizM

User avatar
Frosti
Posts: 426
Joined: 27 Oct 2017, 14:30
Contact:

visual_TableTexter.ahk

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.:

Code: Select all

;|                                         |                                         |                                         |                                         |
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.

Image

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!
User avatar
Frosti
Posts: 426
Joined: 27 Oct 2017, 14:30
Contact:

Re: visual_TableTexter.ahk

02 Jul 2018, 18:09

So ich weiß keine Sau braucht das. Aber weil es mir grad so ein Spaß macht hier ein paar kleine Verbesserungen. Der Bug kommt nicht mehr. Der Code ist etwas kürzer und die Texte für die MsgBoxèn und ToolTips sind am Anfang des Skriptes festgelegt damit es vielleicht noch lokalisiert werden kann.

Code: Select all

^r::																																									
SetKeyDelay, 20, 50
SetBatchLines, -1
MarkDownApp:= "Typora"           	;use your own documentation Softwaretitle here, this is for
MarkDownAppName:= "Typora"   	;if name of window and app title doesnt match
savedClipBoard:= Clipboard		;this time I wan't to save the clipboard content
clipboard:=""   			        	;now I like to clear it, perhaps it helps to solve the "I always get the last copy"
markedCode:=""                        	;empty marked code if its used before
MBoxTitle  := "Extraktionen!"		;for easier localization 
MBoxText1:= "Text zum Einfügen ins AHK-Script:"
MBoxText2:= "Text zum Einfügen bei"
MBoxText3:= "⋐⋑⋐⋑⋐⋑⋐⋑⋐⋑⋐⋑⋐⋑⋐⋑⋐⋑⋐⋑⋐⋑⋐⋑⋐⋑⋐⋑⋐⋑⋐⋑⋐⋑"
MBoxText4:= "Möchtest Du weitermachen?"
TTipText1:= "Setze den Cursor in der Scripttabelle`n an den Anfang der richtigen Zelle!.`n`nIch warte auf Strg+linke Maustaste`n!Tasten loslassen! zum Auslösen der Funktion."
TTipText2:= "Setze jetzt den Curser in Deiner " MarkDownApp " an die Einfügeposition.`n`nIch warte auf Strg+linke Maustaste`n!Tasten loslassen! zum Auslösen der Funktion."
		
While (markedCode="") {								;removed bug - it stays here until Ctrl+C retrieves a reliable return
	Send, {Home}{Shift Down}{End}{Shift Up}
	Send, {CTRL down}c{CTRL up}
	ClipWait, 1
	markedCode:= Clipboard
}
cutpos1:= Instr(markedCode, "`(")
cutpos2:= Instr(markedCode, "`)")
cutpos3:= Instr(markedCode, "`;--") + 2
txtforscript:= "   " . SubStr(markedCode, 1, cutpos1) . "`)"
txtforMarkDownApp:= "**" . Trim(txtforscript) . "** " . SubStr(markedCode, cutpos3, StrLen(markedCode)-cutpos3+3)

MsgBox, 4, %MBoxTitle% , %MBoxText1%`n%txtforscript%`n---------------------------------------------------------------------------n%MBoxText2%%MarkDownAppName%:`n%txtforMarkDownApp%`n%MBoxText3%`n`n%MBoxText4%
IfMsgBox, No
	return
caretx:=A_CaretX, carety:=A_CaretY - 20
ToolTip, %TTipText1% ,%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
;}
	
;sends the shortend function to my texttable
SendRawFast(txtforscript)
		
;{ The loop for space and tabs in your editor
SetKeyDelay, 20, 20
Loop {
Send, {Up}
Send, {LShift Down}{Right}{LShift Up}
Send, {CTRL Down}c{CTRL Up}    	;goes up the line, selects the upper character
ClipWait, 1
	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}
		break
	}
}
;}	
	SetKeyDelay, 20, 50
caretx:=A_CaretX, carety:=A_CaretY + 20
ToolTip, %TTipText1%, %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
}
	
Clipboard:= savedClipBoard                             		;so, I put the old clip content back to its source
ToolTip, Okay ready.,%caretx%, %carety%, 11
sleep, 5000
ToolTip,,,, 11
SetKeyDelay, 20, 50

return
Vielleicht findet ja jemand noch ein paar "Improvements"?
Insbesondere würde ich gern wissen, warum das Ende der Tabellenspalte mit Send oder SendInput (erster Befehl unter Einstellung SetKeyDelay, 0,0) nicht mehr gefunden wird.
Diese Einstellung war auch nicht anzuschauen. Da tanzt Fräulein Caret auch nicht mehr. Aber dennoch rein wissenschaftlich, nur mal so aus dem wissenschaftlichen Blickwinkel heraus, wäre es schon mal interessant für mich.
User avatar
Frosti
Posts: 426
Joined: 27 Oct 2017, 14:30
Contact:

Re: visual_TableTexter.ahk

21 Jul 2018, 18:43

Does everyone likes my very good DENGlISH?

Return to “Skripte und Funktionen”

Who is online

Users browsing this forum: No registered users and 19 guests