Jump to content

Quick Screener


Mat
 Share

Recommended Posts

I decided that since nothing at the moment uses a combination of the Ctrl key and the middle mouse button... I would. Hold down Ctrl and drag with the middle mouse button and a rather makeshift rectangle will follow. If you drag an area less than $nClick (default is 50px) then it will capture the active window instead.

There is also a few more functions in the tray menu. All files are stored in $sDataDump (Default @TempDir & "\QuickScreenerDump\"), as png's, and every time you take a screen shot, the filename is copied to the clipboard, and an entry is written into the log (default @ScriptDir & "\log.ini")

There is probably a better way to draw the rectangle, but I can't be asked to do any graphics at the moment.

#NoTrayIcon
#include<ScreenCapture.au3>
#include<WindowsConstants.au3>
#include<Array.au3>

Opt("TrayMenuMode", 3)
Opt("TrayOnEventMode", 1)

If WinExists("Autoit Screener tool hidden window") Then ProcessClose(WinGetProcess("Autoit Screener tool hidden window"))
AutoItWinSetTitle("Autoit Screener tool hidden window")

; Settings
Global $sLog = @ScriptDir & "\log.ini"

; More settings
Global $iCounter = IniRead($sLog, "settings", "counter", 1)
Global $sFolder = IniRead($sLog, "settings", "folder", @ScriptDir & "\dump\")
Global $sMask = IniRead($sLog, "settings", "mask", "#")
Global $nClick = IniRead($sLog, "settings", "clickarea", 10)
Global $sMaskMru = IniRead($sLog, "settings", "mask_mru", $sMask)

Global $ahMaskList[10] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

If DirGetSize($sFolder) = -1 Then DirCreate($sFolder)
If StringRight($sFolder, 1) <> "\" Then $sFolder &= "\"
If StringRight($sMaskMru, 1) = "|" Then $sMaskMru = StringTrimRight($sMaskMru, 1)

Global $hUser32 = DllOpen("user32.dll")
Global $hGUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, BitOR($WS_BORDER, $WS_POPUP), BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))
GUISetBkColor(0xFF0000)
WinSetTrans($hGUI, "", 100)
GUICtrlSetResizing(-1, 802)

TraySetIcon("C:\WINDOWS\system32\SHELL32.dll", 23)

$hMenu = TrayCreateMenu("Capture")
TrayCreateItem("Capture Screen", $hMenu)
TrayItemSetOnEvent(-1, "_Capt")
TrayCreateItem("Capture window", $hMenu)
TrayItemSetOnEvent(-1, "_CaptWnd")

TrayCreateItem("")

Global $hMaskMenuRoot = TrayCreateMenu("&Mask")
Global $hMaskMenu = TrayCreateItem($sMask, $hMaskMenuRoot, 0)
TrayItemSetOnEvent(-1, "_MaskSet")

TrayCreateItem("", $hMaskMenuRoot)

$aList = StringSplit($sMaskMru, "|")
If $aList[0] > 9 Then $aList[0] = 9
$ahMaskList[0] = $aList[0]

For $n = 1 To $aList[0]
    $ahMaskList[$n] = TrayCreateItem("&" & $n & ". " & $aList[$n], $hMaskMenuRoot, $n + 1)
    TrayItemSetOnEvent(-1, "_MaskSetMru")
Next
$aList = 0

TrayCreateItem("")

$hMenu = TrayCreateMenu("&Counter")
Global $hCounterMenu = TrayCreateItem($iCounter, $hMenu)
TrayItemSetOnEvent(-1, "_CounterSet")
TrayCreateItem("&Clear", $hMenu)
TrayItemSetOnEvent(-1, "_CounterClear")

TrayCreateItem("")

$hMenu = TrayCreateMenu("&Folder")
TrayCreateItem("&Open", $hMenu)
TrayItemSetOnEvent(-1, "_Open")
TrayCreateItem("&Clear", $hMenu)
TrayItemSetOnEvent(-1, "_Clear")
TrayCreateItem("C&hange...", $hMenu)
TrayItemSetOnEvent(-1, "_Change")

TrayCreateItem("")

$hMenu = TrayCreateMenu("Log")
TrayCreateItem("Open", $hMenu)
TrayItemSetOnEvent(-1, "_Openlog")
TrayCreateItem("Clear", $hMenu)
TrayItemSetOnEvent(-1, "_Clearlog")

TrayCreateItem("")

TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "_Exit")

TraySetToolTip("The window screener tool")
TraySetState()
TrayTip("Screener Version 1.2", "Use Ctrl + The middle mouse button to capture an area or window." & @CRLF & @CRLF & _
        "You can access additional functions through the tray menu.", 15, 1)

While 1
    If _Pressed("Ctrl") And _Pressed("Middle") Then
        $hWnd = WinGetHandle("[active]", "")
        WinSetState($hWnd, "", @SW_DISABLE)
        $aPos = _GetArea()
        If ($aPos[2] - $aPos[0] < $nClick) Or ($aPos[3] - $aPos[1] < $nClick) Then
            $aPos = WinGetPos($hWnd, "")
            $aPos[2] += $aPos[0]
            $aPos[3] += $aPos[1]
        EndIf
        WinSetState($hWnd, "", @SW_ENABLE)
        $sFile = _GetFile()
        _ScreenCapture_Capture($sFile, $aPos[0], $aPos[1], $aPos[2], $aPos[3], False)
        ClipPut($sFile)
        _WriteLog($sFile, 1)
        _CounterSet(-2)
    ElseIf _Pressed("Print") Then
        $sFile = _GetFile()
        _ScreenCapture_Capture($sFile, 0, 0, @DesktopWidth, @DesktopHeight, False)
        ClipPut($sFile)
        _WriteLog($sFile, 2)
        _CounterSet(-2)
    EndIf

    Sleep(10)
WEnd

Func _MaskSetMru()
    $s = StringTrimLeft(TrayItemGetText(@TRAY_ID), 4)
    _MaskSet($s)
EndFunc

Func _MaskSet($s = "")
    If Not IsDeclared("s") Then $s = ""

    If $s = "" Then
        $s = InputBox("Mask", "Please enter the mask to use." & @CRLF & @CRLF & "'#' => The counter", $sMask, " M")
        If @error Then Return
    EndIf
    $s = StringStripWS($s, 3)
    $sMask = $s

    $aList = StringSplit($sMaskMru, "|")
    If $aList[0] > 9 Then $aList[0] = 9

    $i = 0
    While $i < $aList[0]
        $i += 1
        If $aList[$i] = $sMask Then
            _ArrayDelete($aList, $i)
            $aList[0] = UBound($aList) - 1
        EndIf
    WEnd
    _ArrayInsert($aList, 1, $sMask)
    $aList[0] -= 1

    If $aList[0] > 9 Then $aList[0] = 9

    $sMaskMru = _ArrayToString($aList, "|", 1, 9)

    For $i = 1 To $aList[0]
        If $ahMaskList[$i] = 0 Then
            TrayCreateItem("&" & $i & ". " & $aList[$i], $hMaskMenuRoot, $i + 1)
            TrayItemSetOnEvent(-1, "_MaskSetMru")
        Else
            TrayItemSetText($ahMaskList[$i], "&" & $i & ". " & $aList[$i])
        EndIf
    Next

    For $i = $aList[0] + 1 To 9
        If $ahMaskList[$i] = 0 Then ExitLoop
        TrayItemDelete($ahMaskList[$i])
        $ahMaskList[$i] = 0
    Next

    TrayItemSetText($hMaskMenu, $sMask)
EndFunc

Func _CounterClear()
    _CounterSet(1)
EndFunc

Func _Change()
    $s = FileSelectFolder("Select folder", "", 7, $sFolder)
    If @error Then Return
    $sFolder = $s
    If StringRight($sFolder, 1) <> "\" Then $sFolder &= "\"
EndFunc

Func _CounterSet($i = -1)
    If Not IsDeclared("i") Then $i = -1

    If $i = -2 Then
        $iCounter += 1
    ElseIf $i < 0 Then
        $i = InputBox("Counter", "Please enter the counter value", $iCounter, " M")
        If @error Then Return
        $iCounter = Int($i)
    Else
        $iCounter = Int($i)
    EndIf

    TrayItemSetText($hCounterMenu, $iCounter)
EndFunc

Func _GetFile()
    Return $sFolder & StringReplace($sMask, "#", $iCounter) & ".jpg"
EndFunc   ;==>_GetFile

Func _Pressed($key)
    Switch StringLower($key)
        Case "Left"
            $iHex = "01"
        Case "middle"
            $iHex = "04"
        Case "ctrl"
            $iHex = "11"
        Case "print"
            $iHex = "2C"
        Case Else
            Return -1
    EndSwitch
    $aIsPressed = DllCall($hUser32, "int", "GetAsyncKeyState", "int", "0x" & $iHex)
    If @error Or (BitAND($aIsPressed[0], 0x8000) <> 0x8000) Then Return 0
    Return 1
EndFunc   ;==>_Pressed

Func _GetArea()
    Local $aPos = MouseGetPos(), $aLast[2] = [-1, -1], $aPosFirst = MouseGetPos(), $aRet[4]
    WinMove($hGUI, "", $aPosFirst[0], $aPosFirst[1], 1, 1)
    GUISetState(@SW_SHOW, $hGUI)

    While _Pressed("Middle")
        $aPos = MouseGetPos()
        If ($aPos[0] <> $aLast[0]) Or ($aPos[1] <> $aLast[1]) Then
            $aRet[0] = $aPosFirst[0]
            $aRet[1] = $aPosFirst[1]

            $aRet[2] = $aPos[0]
            $aRet[3] = $aPos[1]

            If $aRet[0] > $aRet[2] Then
                $tmp = $aRet[0]
                $aRet[0] = $aRet[2]
                $aRet[2] = $tmp
            EndIf
            If $aRet[1] > $aRet[3] Then
                $tmp = $aRet[1]
                $aRet[1] = $aRet[3]
                $aRet[3] = $tmp
            EndIf

            WinMove($hGUI, "", $aRet[0], $aRet[1], $aRet[2] - $aRet[0], $aRet[3] - $aRet[1])
            $aLast = $aPos
        EndIf
        ToolTip($aRet[2] - $aRet[0] & " x " & $aRet[3] - $aRet[1])
        Sleep(10)
    WEnd
    ToolTip("")
    GUISetState(@SW_HIDE, $hGUI)
    Return $aRet
EndFunc   ;==>_GetArea

Func _WriteLog($sFile, $nType)
    IniWrite($sLog, @MDAY & "." & @MON & "." & @YEAR, @MIN & ":" & @HOUR & ":" & @SEC & ":" & @MSEC & "_" & $nType, StringRegExpReplace($sFile, ".*\\", ""))
EndFunc   ;==>_WriteLog

Func _Capt()
    $sFile = _GetFile()
    _ScreenCapture_Capture($sFile, 0, 0, @DesktopWidth, @DesktopHeight, False)
    ClipPut($sFile)
    _WriteLog($sFile, 3)
    _CounterSet(-2)
EndFunc   ;==>_Capt

Func _CaptWnd()
    WinSetTrans($hGUI, "", 1)
    WinMove($hGUI, "", 0, 0, @DesktopWidth, @DesktopHeight)
    GUISetCursor(3, 1, $hGUI)
    GUISetState(@SW_SHOW, $hGUI)
    While Not _Pressed("Left")
    WEnd
    GUISetState(@SW_HIDE, $hGUI)
    GUISetCursor(1, 1, $hGUI)
    MouseClick("")
    $aPos = WinGetPos("[active]")
    WinSetTrans($hGUI, "", 100)
    $aPos[2] += $aPos[0]
    $aPos[3] += $aPos[1]
    $sFile = _GetFile()
    _ScreenCapture_Capture($sFile, $aPos[0], $aPos[1], $aPos[2], $aPos[3], False)
    ClipPut($sFile)
    _WriteLog($sFile, 4)
    _CounterSet(-2)
EndFunc   ;==>_CaptWnd

Func _OpenLog()
    ShellExecute($sLog)
EndFunc   ;==>_OpenLog

Func _ClearLog()
    FileDelete($sLog)
    IniWrite($sLog, "settings", "counter", $iCounter)
    IniWrite($sLog, "settings", "folder", $sFolder)
    IniWrite($sLog, "settings", "mask", $sMask)
    IniWrite($sLog, "settings", "clickarea", $nClick)
EndFunc   ;==>_ClearLog

Func _Open()
    ShellExecute($sFolder)
EndFunc   ;==>_Open

Func _Clear()
    DirRemove($sFolder, 1)
    DirCreate($sFolder)
    _WriteLog("\Cleared data", 5)
EndFunc   ;==>_Clear

Func _Exit()
    TraySetState(2)
    IniWrite($sLog, "settings", "counter", $iCounter)
    IniWrite($sLog, "settings", "folder", $sFolder)
    IniWrite($sLog, "settings", "mask", $sMask)
    IniWrite($sLog, "settings", "clickarea", $nClick)
    IniWrite($sLog, "settings", "mask_mru", $sMaskMru)
    Exit
EndFunc   ;==>_Exit

Posted Image

The tray menu, and an example of an image generated using this tool

Mat

Edited by Mat
Link to comment
Share on other sites

  • 11 months later...

I know this is an old topic, but I was searching for a script that would let me do what this script does and I have to say this one works great. Thanks for posting it, it saved me a lot of work when I had to write up a document for a user that needed screenshots of the steps needed to do something on her computer.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I know this is an old topic, but I was searching for a script that would let me do what this script does and I have to say this one works great. Thanks for posting it, it saved me a lot of work when I had to write up a document for a user that needed screenshots of the steps needed to do something on her computer.

I now use FSCapture. It has a nice function for entering templates, e.g. ScreenshotForProgram####.jpg

http://www.faststone.org/FSCaptureDetail.htm

However, I still like the way my program uses ctrl and the middle mouse button. It means I can do it so much easier ;) if fsc implemented that it would be great.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...