Sign in to follow this  
Followers 0
ashley

screencap broken

9 posts in this topic

here my script its meant to take a pic of the screen

#Include <A3LClipBoard.au3>
#Include <A3LScreenCap.au3>
$counter = 000

HotKeySet("{PrintScreen}", "PicFunc")
HotKeySet("{ESC}", "ExitFunc")

SplashTextOn("ScreenCap", "Starting ScreenCap...", 200, 50)
Sleep(1000)
SplashOff()

While 1
WEnd

Func PicFunc()
    $counter =+1
    _Clip_Empty()
    $sFileName = @ScriptDir & "\" & @MON & @MDAY & @HOUR & @MIN &"\Picture" & $counter & ".bmp"
    _ScreenCap_Capture($sFileName)
    _Clip_SetData($sFileName)
    Sleep(100)
SplashTextOn("ScreenCap", "Picture taken", 200, 50)
Sleep(1000)
SplashOff()
EndFunc

Func ExitFunc()
    Exit
EndFunc

thanks

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

$hBitmap =     _ScreenCap_Capture($sFileName)
    _Clip_SetData($hBitmap, $CF_BITMAP)
Although, your example doesn't make much sense to me if you are naming the file every minute, but checking it every second.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Outside of what SmOke_N pointed out, here's what I think is wrong with your script.

1. need to put a Sleep() in your While...WEnd otherwise your CPU will be hate'n life

2. You're asking the script to create the .bmp in a directory that doesn't exist. You need to create the directory first or drop it.

3. the operator should be += 1

Here's the code in case what I said doesn't make sense :)

While 1
    Sleep(40)
WEnd

Func PicFunc()
    $counter += 1
    _Clip_Empty ()
    DirCreate(@ScriptDir & "\" & @MON & @MDAY & @HOUR & @MIN)
    $sFileName = @ScriptDir & "\" & @MON & @MDAY & @HOUR & @MIN &"\Picture" & $counter & ".bmp"
    MsgBox(0, '', $sFileName)
    _ScreenCap_Capture ($sFileName)
    _Clip_SetData ($sFileName)
    Sleep(100)
    SplashTextOn("ScreenCap", "Picture taken", 200, 50)
    Sleep(1000)
    SplashOff()
EndFunc   ;==>PicFunc

Share this post


Link to post
Share on other sites

Outside of what SmOke_N pointed out, here's what I think is wrong with your script.

1. need to put a Sleep() in your While...WEnd otherwise your CPU will be hate'n life

2. You're asking the script to create the .bmp in a directory that doesn't exist. You need to create the directory first or drop it.

3. the operator should be += 1

Here's the code in case what I said doesn't make sense :)

While 1
    Sleep(40)
WEnd

Func PicFunc()
    $counter += 1
    _Clip_Empty ()
    DirCreate(@ScriptDir & "\" & @MON & @MDAY & @HOUR & @MIN)
    $sFileName = @ScriptDir & "\" & @MON & @MDAY & @HOUR & @MIN &"\Picture" & $counter & ".bmp"
    MsgBox(0, '', $sFileName)
    _ScreenCap_Capture ($sFileName)
    _Clip_SetData ($sFileName)
    Sleep(100)
    SplashTextOn("ScreenCap", "Picture taken", 200, 50)
    Sleep(1000)
    SplashOff()
EndFunc   ;==>PicFunc
Take a look at Edit2 of mine... Also, the directory does exist because he's using @ScriptDir ;)

Nice catch on +=1, I didn't catch it.


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Take a look at Edit2 of mine... Also, the directory does exist because he's using @ScriptDir ;)

Nice catch on +=1, I didn't catch it.

Based on timestamps looks like my post and your edit were a photo finish!

I respectfully disagree that the directory existed. If you take the original script and run it, you'll see that the .bmp file is not created in the @ScriptDir. Likewise you'll not that SciTE4AutoIt3 does not report any errors in the console after the script ends. How I came to the conclusion that it was the "missing" directory causing the problem, was by inserting a MsgBox() after $sFileName. In fact that MsgBox() is still in my original post that I left in by accident.

_Clip_Empty ()
    DirCreate(@ScriptDir & "\" & @MON & @MDAY & @HOUR & @MIN)
    $sFileName = @ScriptDir & "\" & @MON & @MDAY & @HOUR & @MIN &"\Picture" & $counter & ".bmp"
    MsgBox(0, '', $sFileName)
    _ScreenCap_Capture ($sFileName)

Now I could be wrong in my troubleshooting methodology, or there could be another way of getting the original script to work without using DirCreate(). The important part is that the script should now work with either solution. I say that without having testing your code in your 2nd Edit. I'm more than confident your extra _ScreenCap_Capturex() is a smarter more hi-tech way of doing this. Just glad I could offer a lo-tech method :).

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

No, you were right, all I saw was @ScriptDir... didn't look to see if he was trying to put that in another directory.

Edit

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

@ssubirias3

Your method won't put the screen shot in the clipboard... will it?


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

@SmOke_N - np on the mix up, as much as I like details there's been plenty of times you and others have shown me the flaw in my logic! About your clipboard question, I don't know to be honest. This is the first time I've ever seen A3LClipBoard.au3 or A3LScreenCap.au3. I personally haven't had a need to use or study those UDFs, so I'm not sure what they are doing. I just saw those 3 points I mentioned earlier and that the end goal was to create a .bmp file (screenshot) in a specific directory.

I would guess from the name A3LClipBoard.au3 that the UDF uses the clipboard at some point. Now whether the UDF keeps the image in the clipboard buffer to allow pasting of the image into another app like WordPad or MSPaint, I didn't test or try that. I didn't see it as part of the scope or requirements ashley put out. And if your additional code accomplishes this, well that's why I said

... your extra _ScreenCap_Capturex() is a smarter more hi-tech way of doing this ...

Share this post


Link to post
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
Sign in to follow this  
Followers 0