Code: Select all
If not A_IsAdmin
{
DLLCall("shell32\ShellExecuteA", uint, 0, str, "RunAs", str, A_AhkPath, str, """" .A_ScriptFullPath . """", str, A_WorkingDir, int, 1)
ExitApp
}
/*
This is a tool used to screenshot and crop an area around the mouse. No additional files are required. The name of the new file, type of file, as well as the pixel height and width you want to capture are adjustable.
It has been pieced together from many script snippets and forum posts. I know there are more streamline ways to do many of the the below operations, but this is small, stand alone, and works.
Written and tested on Windows 10.
*/
SetWorkingDir, %A_ScriptDir%
#KeyHistory 500
#Persistent
CoordMode, Mouse, Screen
Gui 1:Add, Button, x10 y10 w50 gScreenshot_Replace, Capture
Gui 1:Add, Button, x70 y10 w50 gReload, Reload
Gui 1:Add, Button, x130 y10 w50 gPause, Pause
Gui 1:Add, Text, -wrap x10 y45 w50, File Name
Gui 1:Add, Edit, x65 y40 w55 h20 vEditFileName, Untitled
Gui 1:Add, Edit, x130 y40 w50 h20 vType, .png
Gui 1:Add, Text, -wrap x10 y70 w65, Pixels Tall
Gui 1:Add, Edit, x75 y65 w35 h20 vPixelsTall, 10
Gui 1:Add, Text, -wrap x115 y70 w35, Wide
Gui 1:Add, Edit, x145 y65 w35 h20 vPixelsWide, 10
Gui 1:Add, Text, x10 y90 w170, Position the mouse and press F9.
Gui 1:Show, x10 y60 w190, %A_ScriptName%
Gui 1:Submit, NoHide
FileName = %EditFileName%%Type%
FilePath = %A_ScriptDir%\%FileName%
Esc::ExitApp
Exit:
ExitApp
return
GuiClose:
ExitApp
return
Reload:
Reload
return
Pause:
Suspend
Pause,,1
return
Screenshot_Replace:
MsgBox, 4, Image, To save a cropped screenshot place the mouse over the location, and press [Enter]`nDO NOT MOVE THE MOUSE Until the function completes.
IfMsgBox Yes
{
Goto, StartCapture
}
return
F9::
StartCapture:
MouseGetPos, MouseX, MouseY
Send, {PrintScreen}
gosub, OpenMSPaint
sleep, 150
Send, ^v
Sleep, 150
Send, ^s
Sleep, 150
gosub, SaveAsWindowWait
gosub, SaveAs_Save
gosub, CloseMSPaintWindow
sleep, 500
crop(FilePath, 10, 20, 300, 400)
crop(FilePath, x, y, w, h) {
WinGetPos,,, deskwidth, deskheight, Program Manager
MouseGetPos, MouseX, MouseY
GuiControlGet,PixelsWide
GuiControlGet,PixelsTall
GuiControlGet,Type
l := MouseX
t := MouseY
r := (deskwidth-l-PixelsWide)
b := (deskheight-t-PixelsTall)
static IP
img := ComObjCreate("WIA.ImageFile")
img.LoadFile(FilePath)
if (!IP) {
IP:=ComObjCreate("WIA.ImageProcess")
ip.Filters.Add(IP.FilterInfos("Crop").FilterID)
}
ip.filters[1].properties("Left") := l
ip.filters[1].properties("Top") := t
ip.filters[1].properties("Right") := r
ip.filters[1].properties("Bottom") := b
img := IP.Apply(img)
FileDelete, %FilePath%
img.SaveFile(FilePath)
msgbox, The image has been saved to your desktop.
return
sleep, 500
return
}
return
OpenMSPaint:
SetTitleMatchMode, 2
IfWinExist, %EditFileName% - Paint
{
WinActivate
return
}
IfWinExist, Untitled - Paint
{
WinActivate
return
}
Run, mspaint
sleep, 500
goto, OpenMSPaint
return
SaveAs_Save:
IfWinExist, Save As
{
WinActivate, Save As
gosub, LocationSaveSet
Send, {Return}
Sleep, 150
Sleep, 150
goto, SaveAs_Save
}
return
SaveAsWindowWait:
Sleep, 150
IfWinExist, Save As
{
return
}
goto, SaveAsWindowWait
return
LocationSaveSet:
ControlFocus, Edit1
Send, %A_ScriptDir%\%FileName%
return
CloseMSPaintWindow:
IfWinExist, %FileName% - Paint
{
WinClose
Sleep, 150
goto, CloseMSPaintWindow
}
return
[/code]