Jump to content

Problem with screencapture


Aassdd
 Share

Recommended Posts

When I press F12 it takes the first screenshot (Screenshot 1.png) but it doesn't take any others. Also when I press F10 it doesn't exit the loop.

Case $msg = $tray_tools_screenshot
            MsgBox(64, "Screenshot", "Screenshot mode is activated." & @CRLF & "Press F10 to deactivate screenshot mode." & @CRLF & "Press F12 to capture a screenshot.")
            While 1
                If FileExists(@DesktopDir & "\Screenshots") = 0 Then DirCreate(@DesktopDir & "\Screenshots")
                If _IsPressed("7B") Then
                    Local $number = 1
                    Local $capture = _ScreenCapture_Capture()
                    Local $save = _ScreenCapture_SaveImage(@DesktopDir & "\Screenshots\Screenshot " & $number & ".png", $capture)
                    $number = $number + 1
                    If _IsPressed("79") Then ExitLoop
                EndIf
            WEnd
            MsgBox(64, "Screenshot", "Screenshot mode is deactivated.")
Link to comment
Share on other sites

If I were you, I'd look at doing it with hotkeys... have one key be the "take shot" key, and one key be the "exit" key... but if you want to use the code you have so far, its only checking for the f10 key while f12 is being pressed. (the if _IsPressed("79") is INSIDE the If _IsPressed("7B") loop.)

I'm not sure exactly what your situation, but here is how I'd do it:

HotKeySet("{f12}", "_TakeShot")
HotKeySet("{f10}", "_exit")
$number = 1
If FileExists(@DesktopDir & "\Screenshots") = 0 Then DirCreate(@DesktopDir & "\Screenshots")

While 1
    Sleep(10)
WEnd

Func _TakeShot()
    $capture = _ScreenCapture_Capture ()
    $save = _ScreenCapture_SaveImage (@DesktopDir & "\Screenshots\Screenshot " & $number & ".png", $capture)
    $number += 1
EndFunc   ;==>_TakeShot

Func _exit()
    Exit
EndFunc   ;==>_exit

Your situation looks a bit different, but that probably gives you the basic idea.

Edited by Brickoneer
Link to comment
Share on other sites

heres a simple picute taker...just run it...and it will do everything:

#include <GDIPlus.au3>
#include <ScreenCapture.au3>

Opt("MustDeclareVars", 1)

; ====================================================================================================


===========================
; Description ...: Shows how to emboss text on an image
; Author ........: Paul Campbell (PaulIA)
; Notes .........:
; ====================================================================================================


===========================

; ====================================================================================================


===========================
; Global variables
; ====================================================================================================


===========================
Global $hBitmap, $hImage, $hGraphic, $hFamily, $hFont, $tLayout, $hFormat, $aInfo, $hBrush1, $hBrush2, $iWidth, $iHeight, $hPen
Global $sString="  Created with AutoIt  "

; ====================================================================================================


===========================
; Main
; ====================================================================================================


===========================

; Initialize GDI+ library
_GDIPlus_StartUp()

; Capture screen
$hBitmap  = _ScreenCapture_Capture(@MyDocumentsDir & '\AutoItImage.bmp')

; Load image and emboss text
$hImage   = _GDIPlus_ImageLoadFromFile(@MyDocumentsDir & '\AutoItImage.bmp')
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
$hFamily  = _GDIPlus_FontFamilyCreate("Arial")
$hFont  = _GDIPlus_FontCreate($hFamily, 16, 1)
$tLayout  = _GDIPlus_RectFCreate(0, 0)
$hFormat  = _GDIPlus_StringFormatCreate(2)
$hBrush1  = _GDIPlus_BrushCreateSolid(0xA2FFFFFF)
$hBrush2  = _GDIPlus_BrushCreateSolid(0xC4FF0000)
$hPen    = _GDIPlus_PenCreate(0xC4000000, 2)
$aInfo  = _GDIPlus_GraphicsMeasureString($hGraphic, $sString, $hFont, $tLayout, $hFormat)
$iWidth   = DllStructGetData($aInfo[0], "Width" )
$iHeight  = DllStructGetData($aInfo[0], "Height")

_GDIPlus_GraphicsFillRect($hGraphic, 0, 0, $iWidth, $iHeight, $hBrush1)
_GDIPlus_GraphicsDrawRect($hGraphic, 1, 1, $iWidth, $iHeight, $hPen   )
_GDIPlus_GraphicsDrawStringEx($hGraphic, $sString, $hFont, $aInfo[0], $hFormat, $hBrush2)

; Save image
_GDIPlus_ImageSaveToFile($hImage, @MyDocumentsDir & '\AutoItImage2.bmp')

; Free resources
_GDIPlus_PenDispose      ($hPen )
_GDIPlus_BrushDispose      ($hBrush1 )
_GDIPlus_BrushDispose      ($hBrush2 )
_GDIPlus_StringFormatDispose($hFormat )
_GDIPlus_FontDispose        ($hFont   )
_GDIPlus_FontFamilyDispose  ($hFamily )
_GDIPlus_GraphicsDispose    ($hGraphic)
_GDIPlus_ImageDispose      ($hImage  )
_GDIPlus_ShutDown()

; Show image
Run("MSPaint.exe " & '"' & @MyDocumentsDir & '\AutoItImage2.bmp"')

Hope it helps!

:ALSO!!! if...it only captures one picture...because of this line:

Local $number = 1

this needs to go up for every picture...

why its not exiting:

this ones simple....just do

Hotkeyset("{F10}", "exitall")

then...

Func exitall()
Exit
Endfunc
Edited by Swift
Link to comment
Share on other sites

If I were you, I'd look at doing it with hotkeys... have one key be the "take shot" key, and one key be the "exit" key... but if you want to use the code you have so far, its only checking for the f10 key while f12 is being pressed. (the if _IsPressed("79") is INSIDE the If _IsPressed("7B") loop.)

I'm not sure exactly what your situation, but here is how I'd do it:

HotKeySet("{f12}", "_TakeShot")
HotKeySet("{f10}", "_exit")
$number = 1
If FileExists(@DesktopDir & "\Screenshots") = 0 Then DirCreate(@DesktopDir & "\Screenshots")

While 1
    Sleep(10)
WEnd

Func _TakeShot()
    $capture = _ScreenCapture_Capture ()
    $save = _ScreenCapture_SaveImage (@DesktopDir & "\Screenshots\Screenshot " & $number & ".png", $capture)
    $number += 1
EndFunc   ;==>_TakeShot

Func _exit()
    Exit
EndFunc   ;==>_exitoÝ÷ Ù.®È­¹«b¢yh¢Kn+]÷Þ­éínëm«i®Ún ÷¬Ê­æÚ²'"u濪ê-xhmÁ©í¶u©òÞd{+-¢l¬r¸©´Ì¬r¸©¶¬©òd{+·w*®¢×§jg
Edited by Aassdd
Link to comment
Share on other sites

its only checking for the f10 key while f12 is being pressed. (the if _IsPressed("79") is INSIDE the If _IsPressed("7B") loop.)

I didn't notice that sry. :D

The problems were

Loca $number = 1oÝ÷ Ù©Ýjëh×6If _IsPressed("79") ; thank you BrickoneeroÝ÷ Ø(¶+p¢¹"^­íý²Ø^r^jëh×6Case $msg = $tray_tools_screenshot
            MsgBox(64, "Screenshot", "Screenshot mode is activated." & @CRLF & "Press F10 to deactivate screenshot mode." & @CRLF & "Press F12 to capture a screenshot.")
            Local $number = 1
            While 1
                If FileExists(@DesktopDir & "\Screenshots") = 0 Then DirCreate(@DesktopDir & "\Screenshots")
                If _IsPressed("7B") Then
                    Local $capture = _ScreenCapture_Capture("", 0, 0, -1, -1, False)
                    Local $save = _ScreenCapture_SaveImage(@DesktopDir & "\Screenshots\Screenshot " & $number & ".png", $capture)
                    $number = $number + 1
                EndIf
                If _IsPressed("79") Then ExitLoop
            WEnd
            MsgBox(64, "Screenshot", "Screenshot mode is deactivated.")
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...