MS Snippingtool nachgebaut

  • Hallo,

    als Auszug aus einem meiner Hauptscripte habe ich mal das
    Microsoft Snippingtool in Autoit geschrieben und als standalone-Script erstellt:

    [autoit]

    #include <GuiConstants.au3>
    #Include <Misc.au3>
    #Include <ScreenCapture.au3>
    Opt("GuiOnEventMode", 1)
    $fastx = _WinAPI_GetSystemMetrics(78)
    $fasty = _WinAPI_GetSystemMetrics(79)
    $sc = 0
    $maingui = GUICreate("Andygo's Snippingtool", 200, 100)
    GUISetOnEvent($GUI_EVENT_CLOSE, "Quit")
    $b1 = GUICtrlCreateButton("snip it!", 50, 35, 100, 30)
    GUICtrlSetOnEvent(-1, "_area")
    GUISetState()
    While 1
    sleep(20)
    wend

    [/autoit][autoit][/autoit][autoit]

    func _area()
    $sc += 1
    $var = WinList()
    For $i = 1 to $var[0][0]
    If $var[$i][0] <> "" AND $var[$i][0] <> "start" AND IsVisible($var[$i][1]) Then WinSetState ($var[$i][0], "", @SW_DISABLE )
    Next
    $GUI_2 = GUICreate("", 1, 1, -1, -1, 0x80000000 + 0x00800000, 0x00000008)
    GUISetBkColor(0x0c6eec)
    WinSetTrans($GUI_2, "", 130)
    local $s_left = "", $s_top = "", $s_width = "", $s_height = "", $mgp[2]
    Local $hGUI = GUICreate("", $fastx+50, $fasty+50, -15, -25, -1, 0x00000080)
    GUISetBkColor(0xffffff)
    WinSetTrans($hGUI, "", 40)
    WinSetOnTop($hGUI, "", 1)
    GUISetCursor(3)
    GUISetState(@SW_SHOW, $hGUI)
    While Not _IsPressed(01)
    $mgp = MouseGetPos()
    Sleep(50)
    WEnd
    WinMove($GUI_2, "", $mgp[0], $mgp[1], 1, 1)
    GUISetState(@SW_SHOW, $GUI_2)
    While _IsPressed(01)
    $mgp_2 = MouseGetPos()
    If $mgp_2[0] > $mgp[0] And $mgp_2[1] > $mgp[1] Then
    local $s_left = $mgp[0], $s_top = $mgp[1], $s_width = $mgp_2[0] - $mgp[0], $s_height = $mgp_2[1] - $mgp[1]
    ElseIf $mgp_2[0] > $mgp[0] And $mgp_2[1] < $mgp[1] Then
    Local $s_left = $mgp[0], $s_top = $mgp_2[1], $s_width = $mgp_2[0] - $mgp[0], $s_height = $mgp[1] - $mgp_2[1]
    ElseIf $mgp_2[0] < $mgp[0] And $mgp_2[1] > $mgp[1] Then
    Local $s_left = $mgp_2[0], $s_top = $mgp[1], $s_width = $mgp[0] - $mgp_2[0], $s_height = $mgp_2[1] - $mgp[1]
    ElseIf $mgp_2[0] < $mgp[0] And $mgp_2[1] < $mgp[1] Then
    Local $s_left = $mgp_2[0], $s_top = $mgp_2[1], $s_width = $mgp[0] - $mgp_2[0], $s_height = $mgp[1] - $mgp_2[1]
    EndIf
    WinMove($GUI_2, "", $s_left, $s_top, $s_width, $s_height)
    WinSetOnTop($hGUI, "", 1)
    ToolTip($s_width & "x" & $s_height)
    sleep(50)
    WEnd
    ToolTip("")
    GLOBAL $s_left = $s_left, $s_top = $s_top, $s_width = $s_width, $s_height = $s_height
    GUIDelete($hGUI)
    $var = WinList()
    For $i = 1 to $var[0][0]
    If $var[$i][0] <> "" AND IsVisible($var[$i][1]) Then WinSetState ($var[$i][0], "", @SW_ENABLE )
    Next
    GUIDelete($GUI_2)
    while FileExists(@ScriptDir & "\shot"&$sc&".jpg")
    $sc += 1
    wend
    $hBitmap = _ScreenCapture_Capture(@ScriptDir & "\shot"&$sc&".jpg", $s_left, $s_top, $s_left+$s_width, $s_top+$s_height, false)
    msgbox(0,"Screenshot wurde erstellt:",@ScriptDir & "\test"&$sc&".jpg")
    endfunc

    [/autoit][autoit][/autoit][autoit]

    Func IsVisible($handle)
    If BitAnd(WinGetState($handle), 2) Then
    Return 1
    Else
    Return 0
    EndIf
    EndFunc

    [/autoit][autoit][/autoit][autoit]

    func quit()
    Exit
    endfunc

    [/autoit]

    Kann echt ganz praktisch sein und auf Wunsch jedes Einzelnen natürlich nach bedarf angepasst werden.

    Viel Spaß damit, Andy

  • Schaut gut aus, doch (ich hab es nicht getestet):

    [autoit]


    $hBitmap = _ScreenCapture_Capture(@ScriptDir & "\shot"&$sc&".jpg", $s_left, $s_top, $s_left+$s_width, $s_top+$s_height, false)
    msgbox(0,"Screenshot wurde erstellt:",@ScriptDir & "\test"&$sc&".jpg")

    [/autoit]

    Du speicherst es in den Ordner /shot/ und zeigst in der MsgBox nen anderen Pfad an: /test/

    Und wie oben gesagt, habe es nicht getestet, doch das ist mir ins Auge gestochen.

  • Schaut gut aus, doch (ich hab es nicht getestet):

    [autoit]


    $hBitmap = _ScreenCapture_Capture(@ScriptDir & "\shot"&$sc&".jpg", $s_left, $s_top, $s_left+$s_width, $s_top+$s_height, false)
    msgbox(0,"Screenshot wurde erstellt:",@ScriptDir & "\test"&$sc&".jpg")

    [/autoit]

    Du speicherst es in den Ordner /shot/ und zeigst in der MsgBox nen anderen Pfad an: /test/

    Und wie oben gesagt, habe es nicht getestet, doch das ist mir ins Auge gestochen.

    Danke Dir, das hab ich wohl übersehen.

    Schön gemacht :D
    Aber so richtig komfortabel zu bedienen ist es nicht. Ich würde eher einen Hotkey oder ähnliches bevorzugen, oder dass man zB STRG + ALT gedrückt halten muss und anschließend kann man de Bereich auswählen.

    Ich werd das mal kurz modifizieren :D

    Den MOD hier ruhig auch mal posten, vielleicht gefällt er ja :thumbup:

  • So hier mal der Mod:

    Einfach starten und STRG+UMSCHALT drücken falls man einen Ausschnitt wählen möchte.

    Das mit SplashImage ist noch unsauber, da die Skalierung des Bildes nicht erhalten bleibt, aber das werde ich morgen mal durch GDI+ ersetzen ;)

    Spoiler anzeigen
    [autoit]

    ;~ #include <GuiConstants.au3>
    #include <Misc.au3>
    #include <ScreenCapture.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Opt("GuiOnEventMode", 1)

    [/autoit] [autoit][/autoit] [autoit]

    $iScreenHeight = @DesktopHeight
    $iScreenWidth = @DesktopWidth

    [/autoit] [autoit][/autoit] [autoit]

    $iCount = 0

    [/autoit] [autoit][/autoit] [autoit]

    Global $bPressed = False
    Global $hGUI, $GUI_2

    [/autoit] [autoit][/autoit] [autoit]

    HotKeySet("{ESC}","_Exit")

    [/autoit] [autoit][/autoit] [autoit]

    AdlibRegister("_CheckKeysPressed", 50)

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    Sleep(20)
    _Snip()
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _Snip()
    If Not $bPressed Then Return
    $iCount += 1

    [/autoit] [autoit][/autoit] [autoit]

    __SetWinDisable()

    [/autoit] [autoit][/autoit] [autoit]

    Global $GUI_2 = GUICreate("", 1, 1, -1, -1, 0x80000000 + 0x00800000, 0x00000008)
    GUISetBkColor(0x0c6eec)
    WinSetTrans($GUI_2, "", 130)

    [/autoit] [autoit][/autoit] [autoit]

    Local $s_left = "", $s_top = "", $s_width = "", $s_height = "", $aPos[2]
    Global $hGUI = GUICreate("", $iScreenWidth + 50, $iScreenHeight + 50, -15, -25, -1, 0x00000080)
    GUISetBkColor(0xffffff)

    [/autoit] [autoit][/autoit] [autoit]

    WinSetTrans($hGUI, "", 40)
    WinSetOnTop($hGUI, "", 1)

    [/autoit] [autoit][/autoit] [autoit]

    GUISetCursor(3)
    GUISetState(@SW_SHOW, $hGUI)

    [/autoit] [autoit][/autoit] [autoit]

    If Not $bPressed Then
    _Cancel()
    Return
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    While Not _IsPressed(01)
    $aPos = MouseGetPos()
    Sleep(50)
    If Not $bPressed Then
    _Cancel()
    Return
    EndIf
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    WinMove($GUI_2, "", $aPos[0], $aPos[1], 1, 1)

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState(@SW_SHOW, $GUI_2)

    [/autoit] [autoit][/autoit] [autoit]

    While _IsPressed('01')

    [/autoit] [autoit][/autoit] [autoit]

    $aPos_2 = MouseGetPos()

    [/autoit] [autoit][/autoit] [autoit]

    Select
    Case $aPos_2[0] > $aPos[0] And $aPos_2[1] > $aPos[1]
    Local $s_left = $aPos[0], $s_top = $aPos[1], $s_width = $aPos_2[0] - $aPos[0], $s_height = $aPos_2[1] - $aPos[1]

    [/autoit] [autoit][/autoit] [autoit]

    Case $aPos_2[0] > $aPos[0] And $aPos_2[1] < $aPos[1]
    Local $s_left = $aPos[0], $s_top = $aPos_2[1], $s_width = $aPos_2[0] - $aPos[0], $s_height = $aPos[1] - $aPos_2[1]

    [/autoit] [autoit][/autoit] [autoit]

    Case $aPos_2[0] < $aPos[0] And $aPos_2[1] > $aPos[1]
    Local $s_left = $aPos_2[0], $s_top = $aPos[1], $s_width = $aPos[0] - $aPos_2[0], $s_height = $aPos_2[1] - $aPos[1]

    [/autoit] [autoit][/autoit] [autoit]

    Case $aPos_2[0] < $aPos[0] And $aPos_2[1] < $aPos[1]
    Local $s_left = $aPos_2[0], $s_top = $aPos_2[1], $s_width = $aPos[0] - $aPos_2[0], $s_height = $aPos[1] - $aPos_2[1]
    EndSelect

    [/autoit] [autoit][/autoit] [autoit]

    WinMove($GUI_2, "", $s_left, $s_top, $s_width, $s_height)
    WinSetOnTop($hGUI, "", 1)

    [/autoit] [autoit][/autoit] [autoit]

    ToolTip($s_width & "x" & $s_height)

    [/autoit] [autoit][/autoit] [autoit]

    Sleep(50)

    [/autoit] [autoit][/autoit] [autoit]

    If Not $bPressed Then
    _Cancel()
    Return
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    ToolTip("")

    [/autoit] [autoit][/autoit] [autoit]

    Global $s_left = $s_left, $s_top = $s_top, $s_width = $s_width, $s_height = $s_height

    [/autoit] [autoit][/autoit] [autoit]

    GUIDelete($hGUI)
    GUIDelete($GUI_2)

    [/autoit] [autoit][/autoit] [autoit]

    __SetWinEnable()

    [/autoit] [autoit][/autoit] [autoit]

    While FileExists(@ScriptDir & "\shot" & $iCount & ".jpg")
    $iCount += 1
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    $hBitmap = _ScreenCapture_Capture(@ScriptDir & "\shot" & $iCount & ".jpg", $s_left, $s_top, $s_left + $s_width, $s_top + $s_height, False)
    SplashImageOn("PRESS ANY MOUSE BUTTON TO GET RID OF THIS", @ScriptDir & "\shot" & $iCount & ".jpg")

    [/autoit] [autoit][/autoit] [autoit]

    Local $bTemp = True

    [/autoit] [autoit][/autoit] [autoit]

    While $bTemp
    If _IsPressed(01) Or _IsPressed(02) Then $bTemp = False
    Sleep(10)
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    SplashOff()
    EndFunc ;==>_Snip

    [/autoit] [autoit][/autoit] [autoit]

    Func _Cancel()
    GUIDelete($hGUI)
    GUIDelete($GUI_2)
    Global $GUI_2 = '', $hGUI = '', $aPos = '', $s_left = "", $s_top = "", $s_width = "", $s_height = "", $hBitmap = ''
    ToolTip('')
    GUISetCursor(2)
    __SetWinEnable()
    EndFunc ;==>_Cancel

    [/autoit] [autoit][/autoit] [autoit]

    Func _CheckKeysPressed()
    If _IsPressed('10') And _IsPressed('11') Then
    $bPressed = True
    Else
    $bPressed = False
    EndIf
    EndFunc ;==>_CheckKeysPressed

    [/autoit] [autoit][/autoit] [autoit]

    Func __SetWinDisable()
    $var = WinList()
    For $i = 1 To $var[0][0]
    If $var[$i][0] <> "" And $var[$i][0] <> "start" And IsVisible($var[$i][1]) Then WinSetState($var[$i][0], "", @SW_DISABLE)
    Next
    EndFunc ;==>__SetWinDisable

    [/autoit] [autoit][/autoit] [autoit]

    Func __SetWinEnable()
    $var = WinList()
    For $i = 1 To $var[0][0]
    If $var[$i][0] <> "" And IsVisible($var[$i][1]) Then WinSetState($var[$i][0], "", @SW_ENABLE)
    Next
    EndFunc ;==>__SetWinEnable

    [/autoit] [autoit][/autoit] [autoit]

    Func IsVisible($handle)
    If BitAND(WinGetState($handle), 2) Then
    Return 1
    Else
    Return 0
    EndIf
    EndFunc ;==>IsVisible

    [/autoit] [autoit][/autoit] [autoit]

    Func _Exit()
    Exit
    EndFunc ;==>quit

    [/autoit]
  • oetzn:

    gewöhnungsbedürftig mit dem hotkey aber hat auch was. das mit dem splashimage gefällt mir gut, *daumen hoch*. Sollt vielleicht noch "sichtbarer" rein wo das bild nun gelandet ist.