Skip to content

Instantly share code, notes, and snippets.

@0x4a
Last active January 3, 2016 10:29
Show Gist options
  • Save 0x4a/8449196 to your computer and use it in GitHub Desktop.
Save 0x4a/8449196 to your computer and use it in GitHub Desktop.
collection of #ahk scripts I use for #work with a custom #tool launcher
#SingleInstance, force
#NoEnv
#persistent
FileEncoding UTF-8
SetWorkingDir %A_ScriptDir%
Gosub INIT
#y::checkSlot("run")
#x::selectTool()
#a::selectIt()
#q::fakeIt()
ExitApp
INIT:
global WaitCursor := 0
global WaitWindow := 0
global ActiveTool := "select"
global guiWidth := 300
global controlWidth := guiWidth - 20
global nMax := 0
global Selection := "empty"
global Cursor := "empty"
global Array := Object()
fileCSV := SubStr( A_ScriptName, 1, -4 ) . ".csv"
if FileExist(fileCSV)
loadCSV(fileCSV)
else
{
Msgbox CSV-Datei mit den Daten wurde nicht gefunden
ExitApp
}
checkSlot("run")
cursorMsg("started")
return
UpdateStatusbar:
GuiControlGet, Cursor
checkSlot("status")
return
GuiClose:
ExitApp
GuiEscape:
ButtonAbbrechen:
Gui, Destroy
WaitWindow := 0
return
ButtonOK:
Gui, Submit
Selection := Cursor
ActiveTool := checkSlot("active")
Gui, Destroy
WaitWindow := 0
return
selectTool()
{
global
if (WaitWindow = 1)
WinActivate ahk_id %MyHwnd%
else
{
str1 := getCmd(1, "str")
str2 := getCmd(2, "str")
str3 := getCmd(3, "str")
str4 := getCmd(4, "str")
str5 := getCmd(5, "str")
str6 := getCmd(6, "str")
WaitWindow := 1
Gui -MinimizeBox HwndMyHwnd
Gui, Margin, 10, 10
Gui, Add, Text, w%controlWidth% , Die gewählte Funktion kann mit $foo aufgerufen werden,`ndiese Auswahl erreichst du mit $bar.
Gui, Add, ListBox, w%controlWidth% r10 vCursor gUpdateStatusbar AltSubmit, %str1%|%str2%|%str3%|%str4%|%str5%|%str6%
Gui, Add, Button, default section, OK
Gui, Add, Button, ys, Abbrechen
Gui, Add, StatusBar,, Samenhaus Müller 2014.
Gui, Show, center w%guiWidth%, Funktion wählen!
if (selection <> "empty")
checkSlot("select")
}
}
loadCSV(file)
{
global
nCmd := 0
Loop, read, %file%
{
nCmd += 1
iCmd := 0
Loop, parse, A_LoopReadLine, `;
{
iCmd += 1
Array[nCmd, iCmd] := A_LoopField
}
iMax := iCmd
}
nMax := nCmd
}
getCmd(iCmd, m = "cmd")
{
column := m="str" ? 1 : m="sb" ? 2 : m="nr" ? iCmd+1 : m="fkt" ? 4 : 3
element := Array[iCmd+1, column]
return element
}
; tooltip timer
cursorTime:
{
SetTimer, cursorTime, off
Tooltip,
WaitCursor := 0
return
}
cursorMsg(string, time = 750)
{
while (WaitCursor)
{
sleep 50
}
WaitCursor := 1
SetTimer, cursorTime, %time%
Tooltip, %string%
return
}
checkSlot(mode = "string")
{
global
local Result
if (mode = "string") ; return string
{
Result := getCmd(Selection, "str")
return Result
}
else if (mode = "select") ; move cursor
{
Result := getCmd(Selection, "str")
Control, ChooseString, %Result%, ListBox1, Funktion wählen!
return 1
}
else if (mode = "number") ; return position
{
Result := getCmd(Selection, "str")
ControlGet, position, FindString, %Result%, ListBox1, Funktion wählen
return position
}
else if (mode = "run") ; run function
{
if (ActiveTool = "select")
selectTool()
else if (ActiveTool = "paste_csv")
toolSaveID()
else if (ActiveTool = "ins-ts_date")
toolTimestamp(1)
else if (ActiveTool = "ins-ts_time")
toolTimestamp(2)
else if (ActiveTool = "ins-ts_datetime")
toolTimestamp(3)
else if (ActiveTool = "cb-remove_newline")
toolRemoveNewline()
else if (ActiveTool = "ins_signature")
toolSignature()
else
{
cursorMsg("error")
return
}
cursorMsg("run: " . ActiveTool)
return
}
else if (mode = "status") ; update statusbar
{
message := getCmd(Cursor, "sb")
SB_SetText(message)
;SB_SetText("s: " . Selection . " | c: " . Cursor . " | " . message)
return message
}
else if (mode = "active") ; make active
{
if (Selection)
{
Result := getCmd( Selection, "cmd")
cursorMsg("aktive: " . Result)
}
else
Result := "select"
return Result
}
else ; error
return false
}
; checkCmdRows(ActiveTool, getCmd(5, "cmd"), getCmd(6, "fkt"))
toolSaveID()
{
msgbox, soon
selectTool()
}
toolRemoveNewline()
{
msgbox, soon
selectTool()
}
toolSignature()
{
msgbox, soon
selectTool()
}
toolTimestamp(mode = 3)
{
local Result
if (mode = 1)
Result = %A_YYYY%-%A_MM%-%A_DD%{Space}-{Space}
else if (mode = 2)
Result = %A_Hour%-%A_Min%-%A_SEC%{Space}
else if (mode = 3)
Result = %A_YYYY%-%A_MM%-%A_DD%_-_%A_Hour%-%A_Min%-%A_SEC%{Space}-{Space}
else
Result = 0
Send %Result%
return
}
fakeIt()
{
global
;ActiveTool := "ins-ts_datetime"
;Selection := 4
;cursorMsg("faked selektion")
return
}
selectIt()
{
out := checkSlot("number")
msgbox % "out: """ . out . """" . Selection
return
}
getOverview(nCmd)
{
global
strCmd := ""
numCmd := "Cmd " . nCmd . "/" . nMax
listvars
Loop, %iMax%
{
local element := Array[nCmd+1, A_Index]
local key := Array[1, A_Index]
strCmd := strCmd . A_Index . ") " . key . " = " . element . "`n"
}
MsgBox,,%numCmd%,%strCmd%
}
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
name;hint;command;function
Zeilenumbrüche entfernen;Entfernt alle Zeilenumbrüche aus dem markierten Text;cb-remove_newline;cmdRemoveNewline()
Datum einfügen;Fügt %TsD% ein;ins-ts_date;cmdTimestamp(1)
Uhrzeit einfügen;Fügt %TsT% ein;ins-ts_time;cmdTimestamp(2)
Datum + Uhrzeit einfügen;Fügt %TsDT% ein;ins-ts_datetime;cmdTimestamp(3)
Markierung zu CSV;Fügt den markierten Text zu CSV hinzu;paste_csv;cmdSaveCSV()
Signatur einfügen;Fügt die Signatur ein;ins_signature;cmdSignature()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment