Skip to content

Commit 3fdc4f8

Browse files
FEATURE: ocr support
FEATURE: build process
1 parent e53e071 commit 3fdc4f8

10 files changed

Lines changed: 74 additions & 8 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/release
22
/screenshots
3+
/bin

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "github_modules/Gdip"]
22
path = github_modules/Gdip
33
url = https://github.com/tariqporter/Gdip.git
4+
[submodule "github_modules/OCR"]
5+
path = github_modules/OCR
6+
url = https://github.com/Descolada/OCR.git

KeyboardScreenshot.ahk

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
;https://www.autohotkey.com/boards/viewtopic.php?style=19&t=96159
2-
;@Ahk2Exe-ExeName %A_ScriptDir%\release\KeyboardScreenshot.exe
1+
#Include %A_ScriptDir%\config.ahk
32
#Include github_modules/Gdip/Gdip.ahk
43

5-
#SingleInstance, force
64
CoordMode, Mouse, Screen
75

86
mouseSpeed := 50
@@ -22,6 +20,7 @@ resizeNextScreenshotBy := 1
2220
saveToFile := 0
2321
uploadWithShareX := 0
2422
editWithShareX := 0
23+
ocrScreenshot := 0
2524

2625
if (!a_iscompiled) {
2726
Menu, tray, icon, icon.ico,0,1
@@ -91,6 +90,7 @@ return
9190
saveToFile := 0
9291
uploadWithShareX := 0
9392
editWithShareX := 0
93+
ocrScreenshot := 0
9494
;SetTimer, MouseHintTimer, 100
9595
ToolTip, move to START position with arrow keys`nthen press space
9696
}
@@ -214,6 +214,11 @@ e::
214214
uploadWithShareX := 0
215215
return
216216

217+
o::
218+
ToolTip, Screenshot will be OCR'd
219+
ocrScreenshot := 1
220+
return
221+
217222
GetStartPosition:
218223
state := 2
219224
MouseGetPos, screenShotStartX, screenShotStartY
@@ -293,7 +298,7 @@ CreateScreenshot:
293298
SoundBeep, 500, 5
294299
*/
295300

296-
CaptureScreen(screenShotStartX ", " screenShotStartY ", " screenShotEndX ", " screenShotEndY, 0, saveToFile, uploadWithShareX, editWithShareX, 0, resizeNextScreenshotBy)
301+
CaptureScreen(screenShotStartX ", " screenShotStartY ", " screenShotEndX ", " screenShotEndY, 0, saveToFile, uploadWithShareX, editWithShareX, ocrScreenshot, 0, resizeNextScreenshotBy)
297302
;ToolTip, Mouse region capture to clipboard
298303
Sleep, 1000
299304
ToolTip,
@@ -355,7 +360,7 @@ PreviewDestroy() {
355360
; Convert("C:\image.bmp", "C:\image.jpg", 95)
356361
; Convert(0, "C:\clip.png") ; Save the bitmap in the clipboard to sFileTo if sFileFr is "" or 0.
357362

358-
CaptureScreen(aRect = 0, bCursor = False, saveToFile = 0, uploadWithShareX = 0, editWithShareX = 0, nQuality = "", resizeBy = 1)
363+
CaptureScreen(aRect = 0, bCursor = False, saveToFile = 0, uploadWithShareX = 0, editWithShareX = 0, ocrScreenshot = 0, nQuality = "", resizeBy = 1)
359364
{
360365
; Add Gdip startup
361366
If !pToken := Gdip_Startup()
@@ -436,10 +441,11 @@ CaptureScreen(aRect = 0, bCursor = False, saveToFile = 0, uploadWithShareX = 0,
436441

437442
SetClipboardData(hBM)
438443

439-
if(saveToFile = 1 || uploadWithShareX = 1 || editWithShareX = 1) {
444+
if(saveToFile = 1 || uploadWithShareX = 1 || editWithShareX = 1 || ocrScreenshot = 1) {
440445
;Convert(hBM, "c:\test.bmp", nQuality), DllCall("DeleteObject", "ptr", hBM)
441446
FormatTime, currentDateTime, , yyyy_MM_dd_HH_mm_ss
442-
filename := A_ScriptDir . "\screenshots\" . currentDateTime . ".jpg"
447+
baseFilename := A_ScriptDir . "\screenshots\" . currentDateTime
448+
filename := baseFilename . ".jpg"
443449
Convert(0, filename)
444450
}
445451

@@ -460,7 +466,24 @@ CaptureScreen(aRect = 0, bCursor = False, saveToFile = 0, uploadWithShareX = 0,
460466
FileDelete, %filename%
461467
}
462468
}
463-
469+
470+
if(ocrScreenshot = 1) {
471+
;M sgBox, "C:\Program Files\ShareX\ShareX.exe" "%filename%"
472+
if (!a_iscompiled) {
473+
RunWait, "ocr.ahk" "%baseFilename%"
474+
} else {
475+
RunWait, "ocr.exe" "%baseFilename%"
476+
}
477+
textFilename := baseFilename . ".txt"
478+
FileRead, text, %textFilename%
479+
clipboard := text
480+
FileDelete, %textFilename%
481+
if(saveToFile = 0) {
482+
Sleep, 1000
483+
FileDelete, %filename%
484+
}
485+
}
486+
464487
DllCall("DeleteObject", "ptr", hBM)
465488
; Add Gdip shutdown at the end of the function
466489
Gdip_Shutdown(pToken)

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ It will also be copied to the clipboard as usual.
7575
Note that you need to have sharex installed and configured for this to work.
7676
Currently te path is fixed to `C:\Program Files\ShareX\ShareX.exe`
7777

78+
#### ocr
79+
80+
Press o during the screenshot process to run ocr on the screenshot.
81+
The text will be copied to the clipboard and not the image.
82+
7883
## Licence
7984

8085
GPL 2.0

build_release.bat

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
mkdir bin
2+
del bin\* /Q
3+
mkdir release
4+
del release\* /Q
5+
"tools\Ahk2Exe.exe" /in KeyboardScreenshot.ahk
6+
"tools\Ahk2Exe.exe" /bin tools\AutoHotkey64_v2.exe /in ocr.ahk
7+
cd bin
8+
7z a ..\release\KeyboardScreenshot.zip *
9+
cd ..

config.ahk

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
;@Ahk2Exe-SetMainIcon icon.ico
2+
;@Ahk2Exe-ExeName %A_ScriptDir%\bin\KeyboardScreenshot.exe
3+
4+
#NoEnv
5+
SendMode Input
6+
#SingleInstance force
7+
SetTitleMatchMode, 2
8+
SetWorkingDir %A_ScriptDir%
9+
ListLines Off
10+
SetBatchLines -1

github_modules/OCR

Submodule OCR added at 6e9b5c4

ocr.ahk

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#Requires AutoHotkey >=v2.0
2+
;@Ahk2Exe-ExeName %A_ScriptDir%\bin\ocr.exe
3+
#include github_modules\OCR\Lib\OCR.ahk
4+
#NoTrayIcon
5+
command := A_Args[1]
6+
imageFilename := command . ".jpg"
7+
textFilename := command . ".txt"
8+
;M sgBox imageFilename
9+
result := OCR.FromFile(imageFilename)
10+
resultText := result.Text
11+
;M sgBox resultText
12+
if (FileExist(textFilename))
13+
FileDelete textFilename
14+
FileAppend resultText, textFilename

tools/Ahk2Exe.exe

969 KB
Binary file not shown.

tools/AutoHotkey64_v2.exe

1.2 MB
Binary file not shown.

0 commit comments

Comments
 (0)