-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFastKeyboardScreenshot.ahk
More file actions
240 lines (206 loc) · 6.82 KB
/
FastKeyboardScreenshot.ahk
File metadata and controls
240 lines (206 loc) · 6.82 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
; FastKeyboardScreenshot - Main Entry Point
; Create screenshots by selecting regions with keyboard navigation
#Include %A_ScriptDir%\config.ahk
#Include github_modules/Gdip/Gdip.ahk
; Include library modules (functions only - no hotkeys/labels)
#Include %A_ScriptDir%\lib\utils.ahk
#Include %A_ScriptDir%\lib\gui.ahk
#Include %A_ScriptDir%\lib\image.ahk
#Include %A_ScriptDir%\github_modules\RapidOCR-AutoHotkey\RapidOCR\RapidOCR.ahk
#Include %A_ScriptDir%\lib\capture.ahk
#Include %A_ScriptDir%\lib\crop.ahk
#Include %A_ScriptDir%\lib\arrow.ahk
#Include %A_ScriptDir%\lib\number.ahk
#Include %A_ScriptDir%\lib\rectangle.ahk
#Include %A_ScriptDir%\lib\status_bar.ahk
#Include %A_ScriptDir%\lib\FTP_Upload.ahk
#Include %A_ScriptDir%\lib\SingleInstance.ahk
; Class for single instance management
class FastKeyboardScreenshotApp {
IsActive() {
return 1
}
Quit() {
ExitApp
}
}
; Ensure single instance - quit if another instance is already running
CheckSingleInstance("{B8F4C2E1-7A3D-4F9E-8B5C-1D2E3F4A5B6C}", "FastKeyboardScreenshotApp")
; Initialize GDI+ once at startup (keep running for entire script lifetime)
pGdipToken := Gdip_Startup()
if (!pGdipToken) {
MsgBox, 48, Error!, GDI+ failed to initialize
ExitApp
}
OnExit("CleanupAll")
CoordMode, Mouse, Screen
; Initialize RapidOCR for English text
rapidOcr := new RapidOCR({model: "en"})
; Global variables for ShareX
sharexPath := ""
sharexSearched := false
; Global variables for mouse/screenshot state
mouseSpeed := 50
mouseSPeedSlow := 10
interactiveMode := 0
state := 0
delayedScreenShot := 0
screenshotTimerIndex := 0
screenShotStartX := -1
screenShotStartY := -1
screenShotEndX := -1
screenShotEndY := -1
resizeNextScreenshotBy := 1
saveToFile := 0
uploadAfterCapture := 0
editWithShareX := 0
ocrScreenshot := 0
captureCursor := 0
showWindow := 0
; Register message handler for resolution changes
OnMessage(0x007E, "HandleResolutionChange")
; Global variables for preview window
previewImagePath := ""
previewImageWidth := 0
previewImageHeight := 0
previewPBitmap := 0
previewHwnd := 0
previewTempFile := ""
previewSavedFilePath := "" ; Track saved file for overwrite
; Global variables for crop mode
previewMode := "viewing" ; "viewing", "crop", "arrow", "number", or "rectangle"
cropSettingStart := 0 ; 0 = setting first corner, 1 = setting second corner
cropStartX := 0
cropStartY := 0
cropEndX := 0
cropEndY := 0
; Global variables for arrow mode
arrowCursorX := 0
arrowCursorY := 0
arrowStartX := 0
arrowStartY := 0
arrowSettingStart := 0 ; 0 = not setting, 1 = setting start point
arrowSize := 3
arrowColorIndex := 0
arrowColors := [0xFFFF0000, 0xFF0000FF, 0xFF00FF00, 0xFFFFFF00, 0xFF000000] ; red, blue, green, yellow, black
arrowColorNames := ["Red", "Blue", "Green", "Yellow", "Black"]
arrows := [] ; Array of drawn arrows
arrowMoveStep := 10 ; Pixels per keypress
; Global variables for number mode
numbers := [] ; Array of placed numbers
numberSize := 24 ; Circle diameter
numberColorIndex := 0 ; Color index (shares arrowColors palette)
nextNumber := 1 ; Next number to place on click (auto-increments)
; Global variables for rectangle mode
rectangles := [] ; Array of drawn rectangles
rectSize := 3 ; Line thickness (1-20)
rectColorIndex := 0 ; Color index (shares arrowColors palette)
rectSettingStart := 0 ; 0 = not setting, 1 = setting first corner
rectStartX := 0
rectStartY := 0
; Global variables for text preview window
textPreviewHwnd := 0
; Global variable for preview help window
previewHelpOpen := 0
; Global variables for action tooltips (FTP upload and OCR)
lastUploadedUrl := ""
pendingOcrText := ""
; Initialize ShareX path from settings or by searching
IniRead, sharexPath, %settingsFile%, General, ShareXPath, NOT_FOUND
IniRead, sharexNotFound, %settingsFile%, General, ShareXNotFound, 0
; If path is not in settings or marked as not found, search for it
if (sharexPath = "NOT_FOUND" && sharexNotFound = 0) {
sharexPath := FindShareX()
sharexSearched := true
; Store the result in settings.ini
if (sharexPath = "") {
; ShareX was not found, mark it as not found
IniWrite, 1, %settingsFile%, General, ShareXNotFound
} else {
; ShareX was found, store the path
IniWrite, %sharexPath%, %settingsFile%, General, ShareXPath
IniWrite, 0, %settingsFile%, General, ShareXNotFound
}
} else if (sharexNotFound = 1) {
; ShareX was previously not found, set path to empty
sharexPath := ""
}
; Load arrow preferences from settings
IniRead, arrowColorIndex, %settingsFile%, Arrow, ColorIndex, 0
if (arrowColorIndex >= arrowColors.Length())
arrowColorIndex := 0
IniRead, arrowSize, %settingsFile%, Arrow, Size, 3
if (arrowSize < 1 || arrowSize > 20)
arrowSize := 3
; Load number preferences from settings
IniRead, numberColorIndex, %settingsFile%, Number, ColorIndex, 0
if (numberColorIndex >= arrowColors.Length())
numberColorIndex := 0
IniRead, numberSize, %settingsFile%, Number, Size, 24
if (numberSize < 12 || numberSize > 60)
numberSize := 24
; Load rectangle preferences from settings
IniRead, rectColorIndex, %settingsFile%, Rectangle, ColorIndex, 0
if (rectColorIndex >= arrowColors.Length())
rectColorIndex := 0
IniRead, rectSize, %settingsFile%, Rectangle, Size, 3
if (rectSize < 1 || rectSize > 20)
rectSize := 3
; Set tray icon
if (!a_iscompiled) {
Menu, tray, icon, icon.ico,0,1
}
; Setup tray menu
Menu, tray, NoStandard
Menu, tray, add ; Creates a separator line.
Menu, tray, add, Reload
Menu, tray, add, Exit
return
; Include files with hotkeys/labels AFTER auto-execute section (they end auto-execute)
#Include %A_ScriptDir%\lib\help_window.ahk
#Include %A_ScriptDir%\lib\screenshot.ahk
#Include %A_ScriptDir%\lib\preview_window.ahk
#Include %A_ScriptDir%\lib\hotkeys.ahk
Reload:
Reload
return
Exit:
ExitApp
return
; Action tooltip hotkeys (for FTP upload and OCR)
OpenLastUrl:
global lastUploadedUrl, pendingOcrText
if(lastUploadedUrl != "") {
Run, %lastUploadedUrl%
} else if(pendingOcrText != "") {
; Create temp file on-demand and open in default editor
FormatTime, ts, , yyyy_MM_dd_HH_mm_ss
tempTxt := A_Temp . "\ocr_" . ts . ".txt"
FileAppend, %pendingOcrText%, %tempTxt%
Run, %tempTxt%
pendingOcrText := ""
}
GoSub, ClearActionTooltip
return
CancelActionTooltip:
GoSub, ClearActionTooltip
return
ClearActionTooltip:
global pendingOcrText
ToolTip
Hotkey, o, OpenLastUrl, Off
Hotkey, Escape, CancelActionTooltip, Off
SetTimer, ClearActionTooltip, Off
pendingOcrText := "" ; Clear pending text if user dismissed
return
; Cleanup GDI+ and RapidOCR on script exit
CleanupAll() {
global pGdipToken, rapidOcr
; Terminate RapidOCR process
if (IsObject(rapidOcr)) {
try rapidOcr.exec.Terminate()
}
; Shutdown GDI+
if (pGdipToken)
Gdip_Shutdown(pGdipToken)
}