-
Notifications
You must be signed in to change notification settings - Fork 0
/
witsk.ahk
122 lines (105 loc) · 3.88 KB
/
witsk.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn All ; Enable warnings to assist with detecting common errors.
#SingleInstance force
#Persistent
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
OnExit, EXIT
; Ensure that the INI file exists for this (compiled) script
FileAppend,,%A_ScriptFullPath%.ini
; Work around to figure out the full path to the INI file
$iniFilePath=
Loop, %A_ScriptFullPath%.ini
{
$iniFilePath := A_LoopFileLongPath
}
; Execute all the "library" scripts to update the INI file with the keybinding information
Loop, lib\witsk-*.ahk, 0, 1
{
; HACK: This assumes that .ahk files default action is to execute them
; It works around the issue of dynamically called functions not necessarily working
; The alternative would be for this script to have an #INCLUDE
; for every...single...libary...we...ever...write...
RunWait, %A_AhkPath% "%A_LoopFileLongPath%" "%$iniFilePath%", %A_ScriptDir%, Hide
}
AllLibraries := GetAllLibraries($iniFilePath)
; =============================================================================
; Functions
; =============================================================================
Max(value1, value2)
{
return value1 > value2 ? value1 : value2
}
GetAllLibraries(iniFilePath)
{
@_allLibraries := Object()
IniRead, $settings, %iniFilePath%
Loop, Parse, $settings, `n
{
; We only care about those sections that end in "_Shortcuts"
If (RegExMatch(A_LoopField, "_Shortcuts$") > 0)
{
@_shortcutsSection := A_LoopField
@_libraryCommands := Object()
@actualSection := SubStr(A_LoopField, 1, StrLen(A_LoopField)-StrLen("_Shortcuts"))
; Loop through all the key-value pairs of the shortcuts section
IniRead, @shortCuts, %iniFilePath%, %@_shortcutsSection%
Loop, Parse, @shortCuts, `n
{
@_shortcutLine := A_LoopField
@_key := SubStr(@_shortcutLine, 1, InStr(@_shortcutLine, "=")-1)
@_value := SubStr(@_shortcutLine, StrLen(@_key)+2)
@_libraryCommands[@_key] := @_value
}
IniRead, @_windowTitle, %iniFilePath%, %@actualSection%, WinTitle, %A_Space%
@_allLibraries[@_windowTitle] := @_libraryCommands
}
}
return @_allLibraries
}
GetMaxStringLength(array)
{
@_maxLength := -1
For @_key, @_value in array
@_maxLength := Max(@_maxLength, StrLen(@_key))
return @_maxLength
}
WhatIsThatShortcutKey(commands)
{
Gui, Destroy ; Destroy any current windows because we have a completely new set of requirements
Gui, +ToolWindow -Disabled -SysMenu -Caption +E0x20 ; +AlwaysOnTop
Gui, Margin, 50, 50
Gui, Color, 111111
Gui, Font, s10 cEEEEEE w900, Inconsolata
@_maxKeyLength := GetMaxStringLength(commands) + 1
For key, value in commands
{
paddedKey := SubStr(key . " ", 1, @_maxKeyLength)
Gui, Add, Text, xm yp+22 w150, %paddedKey%
Gui, Add, Text, xp+150 yp+0, %value%
}
Gui, Show, AutoSize NoActivate, ~~WHAT~IS~THAT~SHORTCUT~KEY~~MAIN~~WINDOW~~
WinSet, Transparent, 230, ~~WHAT~IS~THAT~SHORTCUT~KEY~~MAIN~~WINDOW~~
WinSet, AlwaysOnTop, On, ~~WHAT~IS~THAT~SHORTCUT~KEY~~MAIN~~WINDOW~~
}
; =============================================================================
; Hotkeys
; =============================================================================
$^?::
For @_winTitle, @_winCommands in AllLibraries
{
If (WinActive(@_winTitle))
{
WhatIsThatShortcutKey(@_winCommands)
}
}
return
$Esc::
Send, {Esc}
Gui, Destroy
return
GuiEscape:
GuiClose:
ButtonCancel:
EXIT:
ExitApp