LetUserSelectRect - select a portion of the screen - Scripts and Functions - AutoHotkey Community
https://autohotkey.com/board/topic/4592 ... he-screen/
- I've changed it to use a transparent filled-in rectangle, instead of opaque borders, and it now supports right-click/Esc to cancel, plus it's generally been rewritten.
- You press q, and then when you hold down the left mouse button, a red selection rectangle appears, and when you release the button, the rectangle disappears, and a printscreen is taken of that region and displayed using SplashImage.
- Pressing the right mouse button or Esc cancels the selection.
- Note: the script requires the Gdip/Gdip_All library.
- Problems are that: at the moment it requires CoordMode be set in the auto-execute section, it uses a global variable, and it uses labels within a function.
- I'm posting in case anyone has any suggestions on how to improve it.
Code: Select all
;[Gdip functions]
;GDI+ standard library 1.45 by tic - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=6&t=6517
CoordMode, Mouse, Screen
q:: ;take printscreen based on selection rectangle
DetectHiddenWindows, On
InputRect(vWinX, vWinY, vWinR, vWinB)
vWinW := vWinR-vWinX, vWinH := vWinB-vWinY
if (vInputRectState = -1)
return
vScreen := vWinX "|" vWinY "|" vWinW "|" vWinH
pToken := Gdip_Startup()
pBitmap := Gdip_BitmapFromScreen(vScreen, 0x40CC0020)
DllCall("gdiplus\GdipCreateHBITMAPFromBitmap", Ptr,pBitmap, PtrP,hBitmap, Int,0xffffffff)
;SplashImage, % "HBITMAP:" hBitmap, B
SplashImage, % "HBITMAP:" hBitmap
Sleep, 2000
SplashImage, Off
DeleteObject(hBitmap)
Gdip_DisposeImage(pBitmap)
Gdip_Shutdown(pToken)
return
;==================================================
;based on LetUserSelectRect by Lexikos:
;LetUserSelectRect - select a portion of the screen - Scripts and Functions - AutoHotkey Community
;https://autohotkey.com/board/topic/45921-letuserselectrect-select-a-portion-of-the-screen/
;note: 'CoordMode, Mouse, Screen' must be used in the auto-execute section
;e.g.
;InputRect(vWinX, vWinY, vWinR, vWinB)
;vWinW := vWinR-vWinX, vWinH := vWinB-vWinY
;if (vInputRectState = -1)
; return
InputRect(ByRef vX1, ByRef vY1, ByRef vX2, ByRef vY2)
{
global vInputRectState := 0
DetectHiddenWindows, On
Gui, 1: -Caption +ToolWindow +AlwaysOnTop +hWndhGuiSel
Gui, 1: Color, Red
WinSet, Transparent, 128, % "ahk_id " hGuiSel
Hotkey, *LButton, InputRect_Return, On
Hotkey, *RButton, InputRect_End, On
Hotkey, Esc, InputRect_End, On
KeyWait, LButton, D
MouseGetPos, vX0, vY0
SetTimer, InputRect_Update, 10
KeyWait, LButton
Hotkey, *LButton, Off
Hotkey, Esc, InputRect_End, Off
SetTimer, InputRect_Update, Off
Gui, 1: Destroy
return
InputRect_Update:
if !vInputRectState
{
MouseGetPos, vX, vY
(vX < vX0) ? (vX1 := vX, vX2 := vX0) : (vX1 := vX0, vX2 := vX)
(vY < vY0) ? (vY1 := vY, vY2 := vY0) : (vY1 := vY0, vY2 := vY)
Gui, 1:Show, % "NA x" vX1 " y" vY1 " w" (vX2-vX1) " h" (vY2-vY1)
return
}
vInputRectState := 1
InputRect_End:
if !vInputRectState
vInputRectState := -1
Hotkey, *LButton, Off
Hotkey, *RButton, Off
Hotkey, Esc, Off
SetTimer, InputRect_Update, Off
Gui, 1: Destroy
InputRect_Return:
return
}
;==================================================