Jump to content
Sign in to follow this  
TheNorwegianUser

Black webcam

Recommended Posts

TheNorwegianUser

This script was made a few years ago, so i wonder if it still works, i just get a black screen. Any idea how to fix it?

#include <WindowsConstants.au3>
$WM_CAP_START = 0x400
$WM_CAP_UNICODE_START = $WM_CAP_START +100
$WM_CAP_PAL_SAVEA = $WM_CAP_START + 81
$WM_CAP_PAL_SAVEW = $WM_CAP_UNICODE_START + 81
$WM_CAP_UNICODE_END = $WM_CAP_PAL_SAVEW
$WM_CAP_ABORT = $WM_CAP_START + 69
$WM_CAP_DLG_VIDEOCOMPRESSION = $WM_CAP_START + 46
$WM_CAP_DLG_VIDEODISPLAY = $WM_CAP_START + 43
$WM_CAP_DLG_VIDEOFORMAT = $WM_CAP_START + 41
$WM_CAP_DLG_VIDEOSOURCE = $WM_CAP_START + 42
$WM_CAP_DRIVER_CONNECT = $WM_CAP_START + 10
$WM_CAP_DRIVER_DISCONNECT = $WM_CAP_START + 11
$WM_CAP_DRIVER_GET_CAPS = $WM_CAP_START + 14
$WM_CAP_DRIVER_GET_NAMEA = $WM_CAP_START + 12
$WM_CAP_DRIVER_GET_NAMEW = $WM_CAP_UNICODE_START + 12
$WM_CAP_DRIVER_GET_VERSIONA = $WM_CAP_START + 13
$WM_CAP_DRIVER_GET_VERSIONW = $WM_CAP_UNICODE_START + 13
$WM_CAP_EDIT_COPY = $WM_CAP_START + 30
$WM_CAP_END = $WM_CAP_UNICODE_END
$WM_CAP_FILE_ALLOCATE = $WM_CAP_START + 22
$WM_CAP_FILE_GET_CAPTURE_FILEA = $WM_CAP_START + 21
$WM_CAP_FILE_GET_CAPTURE_FILEW = $WM_CAP_UNICODE_START + 21
$WM_CAP_FILE_SAVEASA = $WM_CAP_START + 23
$WM_CAP_FILE_SAVEASW = $WM_CAP_UNICODE_START + 23
$WM_CAP_FILE_SAVEDIBA = $WM_CAP_START + 25
$WM_CAP_FILE_SAVEDIBW = $WM_CAP_UNICODE_START + 25
$WM_CAP_FILE_SET_CAPTURE_FILEA = $WM_CAP_START + 20
$WM_CAP_FILE_SET_CAPTURE_FILEW = $WM_CAP_UNICODE_START + 20
$WM_CAP_FILE_SET_INFOCHUNK = $WM_CAP_START + 24
$WM_CAP_GET_AUDIOFORMAT = $WM_CAP_START + 36
$WM_CAP_GET_CAPSTREAMPTR = $WM_CAP_START + 1
$WM_CAP_GET_MCI_DEVICEA = $WM_CAP_START + 67
$WM_CAP_GET_MCI_DEVICEW = $WM_CAP_UNICODE_START + 67
$WM_CAP_GET_SEQUENCE_SETUP = $WM_CAP_START + 65
$WM_CAP_GET_STATUS = $WM_CAP_START + 54
$WM_CAP_GET_USER_DATA = $WM_CAP_START + 8
$WM_CAP_GET_VIDEOFORMAT = $WM_CAP_START + 44
$WM_CAP_GRAB_FRAME = $WM_CAP_START + 60
$WM_CAP_GRAB_FRAME_NOSTOP = $WM_CAP_START + 61
$WM_CAP_PAL_AUTOCREATE = $WM_CAP_START + 83
$WM_CAP_PAL_MANUALCREATE = $WM_CAP_START + 84
$WM_CAP_PAL_OPENA = $WM_CAP_START + 80
$WM_CAP_PAL_OPENW = $WM_CAP_UNICODE_START + 80
$WM_CAP_PAL_PASTE = $WM_CAP_START + 82
$WM_CAP_SEQUENCE = $WM_CAP_START + 62
$WM_CAP_SEQUENCE_NOFILE = $WM_CAP_START + 63
$WM_CAP_SET_AUDIOFORMAT = $WM_CAP_START + 35
$WM_CAP_SET_CALLBACK_CAPCONTROL = $WM_CAP_START + 85
$WM_CAP_SET_CALLBACK_ERRORA = $WM_CAP_START + 2
$WM_CAP_SET_CALLBACK_ERRORW = $WM_CAP_UNICODE_START + 2
$WM_CAP_SET_CALLBACK_FRAME = $WM_CAP_START + 5
$WM_CAP_SET_CALLBACK_STATUSA = $WM_CAP_START + 3
$WM_CAP_SET_CALLBACK_STATUSW = $WM_CAP_UNICODE_START + 3
$WM_CAP_SET_CALLBACK_VIDEOSTREAM = $WM_CAP_START + 6
$WM_CAP_SET_CALLBACK_WAVESTREAM = $WM_CAP_START + 7
$WM_CAP_SET_CALLBACK_YIELD = $WM_CAP_START + 4
$WM_CAP_SET_MCI_DEVICEA = $WM_CAP_START + 66
$WM_CAP_SET_MCI_DEVICEW = $WM_CAP_UNICODE_START + 66
$WM_CAP_SET_OVERLAY = $WM_CAP_START + 51
$WM_CAP_SET_PREVIEW = $WM_CAP_START + 50
$WM_CAP_SET_PREVIEWRATE = $WM_CAP_START + 52
$WM_CAP_SET_SCALE = $WM_CAP_START + 53
$WM_CAP_SET_SCROLL = $WM_CAP_START + 55
$WM_CAP_SET_SEQUENCE_SETUP = $WM_CAP_START + 64
$WM_CAP_SET_USER_DATA = $WM_CAP_START + 9
$WM_CAP_SET_VIDEOFORMAT = $WM_CAP_START + 45
$WM_CAP_SINGLE_FRAME = $WM_CAP_START + 72
$WM_CAP_SINGLE_FRAME_CLOSE = $WM_CAP_START + 71
$WM_CAP_SINGLE_FRAME_OPEN = $WM_CAP_START + 70
$WM_CAP_STOP = $WM_CAP_START + 68
#include <GUIConstants.au3>
$avi = DllOpen("avicap32.dll")
$user = DllOpen("user32.dll")
$snapfile = @ScriptDir & "\scrshot.bmp"
$Main = GUICreate("Camera",350,270)
$cap = DllCall($avi, "int", "capCreateCaptureWindow", "str", "cap", "int", BitOR($WS_CHILD,$WS_VISIBLE), "int", 15, "int", 15, "int", 320, "int", 240, "hwnd", $Main, "int", 1)
DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_DRIVER_CONNECT, "int", 0, "int", 0)
DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_SCALE, "int", 1, "int", 0)
DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_OVERLAY, "int", 1, "int", 0)
DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_PREVIEW, "int", 1, "int", 0)
DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_PREVIEWRATE, "int", 1, "int", 0)
GUISetState(@SW_SHOW)
HotKeySet("{INSERT}", "SnapShot"); Press 'Insert' to make a SnapShot !
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then
    ;DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_CALLBACK_FRAME, "int", 0, "int", 0)
        DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_END, "int", 0, "int", 0)
        DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_DRIVER_DISCONNECT, "int", 0, "int", 0)
    ;DllClose($avi)
        DllClose($user)
        Exit
    EndIf
    Sleep(1)
Wend
Func SnapShot()
    DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_GRAB_FRAME_NOSTOP, "int", 0, "int", 0)
    DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_FILE_SAVEDIBA, "int", 0, "str", $snapfile)
EndFunc

Taken from

Share this post


Link to post
Share on other sites
Andreik

I have to ask you if you have a webcam and is powered on?


When the words fail... music speaks

Share this post


Link to post
Share on other sites
TheNorwegianUser

I have to ask you if you have a webcam and is powered on?

I have a laptop, Acer Crystal Eye.

How do i turn the webcam on? Anyways, i also tried while the program was running, and it worked there, but not with this script.

Share this post


Link to post
Share on other sites
TheNorwegianUser

Btw, it worked the first time i ran it, but after that, it turned black :/

Share this post


Link to post
Share on other sites
BrewManNH

If this is Vista or Win7 I believe this doesn't work on those OSs.


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

Share this post


Link to post
Share on other sites
TheNorwegianUser

If this is Vista or Win7 I believe this doesn't work on those OSs.

It's Win7 :/

But it worked the first time i tried, but the next time it didnt work :S

Share this post


Link to post
Share on other sites
TheNorwegianUser

Another way i can take a screenshot with the webcam? It doesn't need to show me on a screen first, but just save a picture?

Share this post


Link to post
Share on other sites
AoRaToS

Try this, it's part of a test I was doing, Webcam.au3 is needed, I have it if you want it

Edit: this doesn't a picture (if that what's you meant by screenshot above) but just test it to see if your webcam works. Press Esc to exit

Edit2: added Webcam.au3 to take a picture just use _WebcamSnap

PS: I use Windows 7 x64

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <Webcam.au3>

$gui = GUICreate("Webcam", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOOLWINDOW)
$Label = GUICtrlCreateLabel("", 5, 0, 100, 18)
_WebcamInit()
$webcam = _WebcamOpen($gui,20, 20, @DesktopWidth - 40, @DesktopHeight - 40)
;_WebcamSetup($webcam)
GUISetState(@SW_SHOW)


While 1
    Sleep(10)
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then
        _WebcamClose($webcam)
        Exit
    EndIf
Sleep(1)
WEnd

Webcam.au3

#include-once
#include <GUIConstants.au3>

$WM_CAP_START = 0x400
$WM_CAP_UNICODE_START = $WM_CAP_START +100
$WM_CAP_PAL_SAVEA = $WM_CAP_START + 81
$WM_CAP_PAL_SAVEW = $WM_CAP_UNICODE_START + 81
$WM_CAP_UNICODE_END = $WM_CAP_PAL_SAVEW
$WM_CAP_ABORT = $WM_CAP_START + 69
$WM_CAP_DLG_VIDEOCOMPRESSION = $WM_CAP_START + 46
$WM_CAP_DLG_VIDEODISPLAY = $WM_CAP_START + 43
$WM_CAP_DLG_VIDEOFORMAT = $WM_CAP_START + 41
$WM_CAP_DLG_VIDEOSOURCE = $WM_CAP_START + 42
$WM_CAP_DRIVER_CONNECT = $WM_CAP_START + 10
$WM_CAP_DRIVER_DISCONNECT = $WM_CAP_START + 11
$WM_CAP_DRIVER_GET_CAPS = $WM_CAP_START + 14
$WM_CAP_DRIVER_GET_NAMEA = $WM_CAP_START + 12
$WM_CAP_DRIVER_GET_NAMEW = $WM_CAP_UNICODE_START + 12
$WM_CAP_DRIVER_GET_VERSIONA = $WM_CAP_START + 13
$WM_CAP_DRIVER_GET_VERSIONW = $WM_CAP_UNICODE_START + 13
$WM_CAP_EDIT_COPY = $WM_CAP_START + 30
$WM_CAP_END = $WM_CAP_UNICODE_END
$WM_CAP_FILE_ALLOCATE = $WM_CAP_START + 22
$WM_CAP_FILE_GET_CAPTURE_FILEA = $WM_CAP_START + 21
$WM_CAP_FILE_GET_CAPTURE_FILEW = $WM_CAP_UNICODE_START + 21
$WM_CAP_FILE_SAVEASA = $WM_CAP_START + 23
$WM_CAP_FILE_SAVEASW = $WM_CAP_UNICODE_START + 23
$WM_CAP_FILE_SAVEDIBA = $WM_CAP_START + 25
$WM_CAP_FILE_SAVEDIBW = $WM_CAP_UNICODE_START + 25
$WM_CAP_FILE_SET_CAPTURE_FILEA = $WM_CAP_START + 20
$WM_CAP_FILE_SET_CAPTURE_FILEW = $WM_CAP_UNICODE_START + 20
$WM_CAP_FILE_SET_INFOCHUNK = $WM_CAP_START + 24
$WM_CAP_GET_AUDIOFORMAT = $WM_CAP_START + 36
$WM_CAP_GET_CAPSTREAMPTR = $WM_CAP_START + 1
$WM_CAP_GET_MCI_DEVICEA = $WM_CAP_START + 67
$WM_CAP_GET_MCI_DEVICEW = $WM_CAP_UNICODE_START + 67
$WM_CAP_GET_SEQUENCE_SETUP = $WM_CAP_START + 65
$WM_CAP_GET_STATUS = $WM_CAP_START + 54
$WM_CAP_GET_USER_DATA = $WM_CAP_START + 8
$WM_CAP_GET_VIDEOFORMAT = $WM_CAP_START + 44
$WM_CAP_GRAB_FRAME = $WM_CAP_START + 60
$WM_CAP_GRAB_FRAME_NOSTOP = $WM_CAP_START + 61
$WM_CAP_PAL_AUTOCREATE = $WM_CAP_START + 83
$WM_CAP_PAL_MANUALCREATE = $WM_CAP_START + 84
$WM_CAP_PAL_OPENA = $WM_CAP_START + 80
$WM_CAP_PAL_OPENW = $WM_CAP_UNICODE_START + 80
$WM_CAP_PAL_PASTE = $WM_CAP_START + 82
$WM_CAP_SEQUENCE = $WM_CAP_START + 62
$WM_CAP_SEQUENCE_NOFILE = $WM_CAP_START + 63
$WM_CAP_SET_AUDIOFORMAT = $WM_CAP_START + 35
$WM_CAP_SET_CALLBACK_CAPCONTROL = $WM_CAP_START + 85
$WM_CAP_SET_CALLBACK_ERRORA = $WM_CAP_START + 2
$WM_CAP_SET_CALLBACK_ERRORW = $WM_CAP_UNICODE_START + 2
$WM_CAP_SET_CALLBACK_FRAME = $WM_CAP_START + 5
$WM_CAP_SET_CALLBACK_STATUSA = $WM_CAP_START + 3
$WM_CAP_SET_CALLBACK_STATUSW = $WM_CAP_UNICODE_START + 3
$WM_CAP_SET_CALLBACK_VIDEOSTREAM = $WM_CAP_START + 6
$WM_CAP_SET_CALLBACK_WAVESTREAM = $WM_CAP_START + 7
$WM_CAP_SET_CALLBACK_YIELD = $WM_CAP_START + 4
$WM_CAP_SET_MCI_DEVICEA = $WM_CAP_START + 66
$WM_CAP_SET_MCI_DEVICEW = $WM_CAP_UNICODE_START + 66
$WM_CAP_SET_OVERLAY = $WM_CAP_START + 51
$WM_CAP_SET_PREVIEW = $WM_CAP_START + 50
$WM_CAP_SET_PREVIEWRATE = $WM_CAP_START + 52
$WM_CAP_SET_SCALE = $WM_CAP_START + 53
$WM_CAP_SET_SCROLL = $WM_CAP_START + 55
$WM_CAP_SET_SEQUENCE_SETUP = $WM_CAP_START + 64
$WM_CAP_SET_USER_DATA = $WM_CAP_START + 9
$WM_CAP_SET_VIDEOFORMAT = $WM_CAP_START + 45
$WM_CAP_SINGLE_FRAME = $WM_CAP_START + 72
$WM_CAP_SINGLE_FRAME_CLOSE = $WM_CAP_START + 71
$WM_CAP_SINGLE_FRAME_OPEN = $WM_CAP_START + 70
$WM_CAP_STOP = $WM_CAP_START + 68
$cap = ""
$avi = ""
$user = ""


Func _WebcamInit()
$avi = DllOpen("avicap32.dll")
$user = DllOpen("user32.dll")
EndFunc

;===============================================================================
;
; Description:    Open's a Webcam preview screen in your gui
; Syntax:          _WebcamOpen($sHwnd, $sLeft, $sTop, $sWidth, $sHeight)
; Parameter(s):  $sHwnd  - The handle of the gui
;                  $sLeft    - Left coord. of the preview screen
;                  $sTop      - Top coord. of the preview screen
;                  $sWidth    - Width of the preview screen
;                  $sHeight   - Height of the preview screen
; Requirement(s):   A webcam
; Return Value(s):  On Success - Returns id needed for other controls
;                  On Failure - Returns -1
;
;===============================================================================
func _WebcamOpen($sHwnd, $sLeft, $sTop, $sWidth, $sHeight)
$cap = DllCall($avi, "int", "capCreateCaptureWindow", "str", "cap", "int", BitOR($WS_CHILD,$WS_VISIBLE), "int", $sLeft, "int", $sTop, "int", $sWidth, "int", $sHeight, "hwnd", $sHwnd, "int", 1)
DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_DRIVER_CONNECT, "int", 0, "int", 0)
DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_SCALE, "int", 1, "int", 0)
DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_OVERLAY, "int", 1, "int", 0)
DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_PREVIEW, "int", 1, "int", 0)
DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_PREVIEWRATE, "int", 1, "int", 0)
if @error then return -1
return $cap[0]
EndFunc

;===============================================================================
;
; Description:    Creates a Snapshot from a webcam
; Syntax:          _WebcamSnap($sId, $sFile)
; Parameter(s):  $sId      - Id (returned from _WebcamOpen)
;                  $sFile    - File to save the snapshot to (*.bmp)
; Requirement(s):   A webcam
; Return Value(s):  On Success - Returns 1
;                  On Failure - Returns 0
;
;===============================================================================
Func _WebcamSnap($sId, $sFile)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_GRAB_FRAME_NOSTOP, "int", 0, "int", 0)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_FILE_SAVEDIBA, "int", 0, "str", $sFile)
    if @error Then
        return 0
    Else
        return 1
    EndIf
EndFunc

;===============================================================================
;
; Description:    Closes the preview screen created with _WebcamOpen
; Syntax:          _WebcamClose($sId)
; Parameter(s):  $sId      - Id (returned from _WebcamOpen)
; Requirement(s):   A webcam
; Return Value(s):  On Success - Returns 1
;                  On Failure - Returns 0
;
;===============================================================================
Func _WebcamClose($sId)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_END, "int", 0, "int", 0)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_DRIVER_DISCONNECT, "int", 0, "int", 0)
    DllClose($user)
    DllClose($avi)
    if @error Then
        return 0
    Else
        return 1
    EndIf
EndFunc

;===============================================================================
;
; Description:    Starts recording the Webcam to a file
; Syntax:          _WebcamRecordStart($sFile, $sId)
; Parameter(s):  $sId      - Id (returned from _WebcamOpen)
;                  $sFile    - File to save the movie to (*.avi)
; Requirement(s):   A webcam
; Return Value(s):  On Success - Returns 1
;                  On Failure - Returns 0
; Note(s):        Stop recording by: _WebcamRecordStop($Id)
;
;===============================================================================
Func _WebcamRecordStart($sFile, $sId)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_FILE_SET_CAPTURE_FILEA, "int", 0, "str", $sFile)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_SEQUENCE, "int", 0, "int", 0)
    if @error Then
        return 0
    Else
        return 1
    EndIf

EndFunc

;===============================================================================
;
; Description:    Stops recording.
; Syntax:          _WebcamRecordStop($sId)
; Parameter(s):  $sId      - Id (returned from _WebcamOpen)
; Requirement(s):   A webcam
; Return Value(s):  On Success - Returns 1
;                  On Failure - Returns 0
;
;===============================================================================
Func _WebcamRecordStop($sId)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_STOP, "int", 0, "int", 0)
    if @error Then
        return 0
    Else
        return 1
    EndIf
EndFunc

Func _WebcamSetup($sId)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_DLG_VIDEOSOURCE, "int", 0, "int", 0)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_DLG_VIDEODISPLAY, "int", 0, "int", 0)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_DLG_VIDEOFORMAT, "int", 1, "int", 0)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_DLG_VIDEOCOMPRESSION, "int", 0, "int", 0)
EndFunc
Edited by AoRaToS
  • Like 1

s!mpL3 LAN Messenger

Current version 2.9.8.8 [30/09/2015]

Download Here

s!mpL3

Share this post


Link to post
Share on other sites
TheNorwegianUser

Try this, it's part of a test I was doing, Webcam.au3 is needed, I have it if you want it

Edit: this doesn't a picture (if that what's you meant by screenshot above) but just test it to see if your webcam works. Press Esc to exit

PS: I use Windows 7 x64

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <Webcam.au3>

$gui = GUICreate("Webcam", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOOLWINDOW)
$Label = GUICtrlCreateLabel("", 5, 0, 100, 18)
_WebcamInit()
$webcam = _WebcamOpen($gui,20, 20, @DesktopWidth - 40, @DesktopHeight - 40)
;_WebcamSetup($webcam)
GUISetState(@SW_SHOW)


While 1
    Sleep(10)
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then
        _WebcamClose($webcam)
        Exit
    EndIf
Sleep(1)
WEnd

Yea, would be nice :oops:

Btw, Is this supposed to be in there? :

;If $checksum <> PixelChecksum(20,20, @DesktopWidth - 20, @DesktopHeight - 20, 5) Then
    ;   $Count = $Count + 1
    ;   GUICtrlSetData($Label, "Changes: " & $Count)
    ;EndIf
    ;$coord = PixelSearch(10, 10, @DesktopWidth - 10, @DesktopHeight - 10, 0x00CA00, 40, 2, $gui)
    ;If Not @error Then
    ;   ConsoleWrite(@CRLF & "X and Y are:" & $coord[0] & "," & $coord[1])
    ;EndIf
    ;ConsoleWrite(@CRLF & "Color: " & PixelGetColor(20, 20, $gui))

Edit: Nvm, you removed it:)

Edit 2: Thanks, it works :bye:

Edit 3: Weird... It worked the first time, but then it asks for a webcam to use, and then it doesn't work.. :S

Edited by TheNorwegianUser

Share this post


Link to post
Share on other sites
AoRaToS

That was just part of some motion sensing tests I think, I was working on something recently...

Glad it works for you also :oops:


s!mpL3 LAN Messenger

Current version 2.9.8.8 [30/09/2015]

Download Here

s!mpL3

Share this post


Link to post
Share on other sites
TheNorwegianUser

Maybe _WebcamClose($webcam) doesn't close your camera correctly for some reason :oops:

You're probably right, it worked again when i turned my computer off and on, but doesn't work now again... :/

Share this post


Link to post
Share on other sites
TheNorwegianUser

Try this, it's part of a test I was doing, Webcam.au3 is needed, I have it if you want it

Edit: this doesn't a picture (if that what's you meant by screenshot above) but just test it to see if your webcam works. Press Esc to exit

Edit2: added Webcam.au3 to take a picture just use _WebcamSnap

PS: I use Windows 7 x64

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <Webcam.au3>

$gui = GUICreate("Webcam", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOOLWINDOW)
$Label = GUICtrlCreateLabel("", 5, 0, 100, 18)
_WebcamInit()
$webcam = _WebcamOpen($gui,20, 20, @DesktopWidth - 40, @DesktopHeight - 40)
;_WebcamSetup($webcam)
GUISetState(@SW_SHOW)


While 1
    Sleep(10)
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then
        _WebcamClose($webcam)
        Exit
    EndIf
Sleep(1)
WEnd

Webcam.au3

#include-once
#include <GUIConstants.au3>

$WM_CAP_START = 0x400
$WM_CAP_UNICODE_START = $WM_CAP_START +100
$WM_CAP_PAL_SAVEA = $WM_CAP_START + 81
$WM_CAP_PAL_SAVEW = $WM_CAP_UNICODE_START + 81
$WM_CAP_UNICODE_END = $WM_CAP_PAL_SAVEW
$WM_CAP_ABORT = $WM_CAP_START + 69
$WM_CAP_DLG_VIDEOCOMPRESSION = $WM_CAP_START + 46
$WM_CAP_DLG_VIDEODISPLAY = $WM_CAP_START + 43
$WM_CAP_DLG_VIDEOFORMAT = $WM_CAP_START + 41
$WM_CAP_DLG_VIDEOSOURCE = $WM_CAP_START + 42
$WM_CAP_DRIVER_CONNECT = $WM_CAP_START + 10
$WM_CAP_DRIVER_DISCONNECT = $WM_CAP_START + 11
$WM_CAP_DRIVER_GET_CAPS = $WM_CAP_START + 14
$WM_CAP_DRIVER_GET_NAMEA = $WM_CAP_START + 12
$WM_CAP_DRIVER_GET_NAMEW = $WM_CAP_UNICODE_START + 12
$WM_CAP_DRIVER_GET_VERSIONA = $WM_CAP_START + 13
$WM_CAP_DRIVER_GET_VERSIONW = $WM_CAP_UNICODE_START + 13
$WM_CAP_EDIT_COPY = $WM_CAP_START + 30
$WM_CAP_END = $WM_CAP_UNICODE_END
$WM_CAP_FILE_ALLOCATE = $WM_CAP_START + 22
$WM_CAP_FILE_GET_CAPTURE_FILEA = $WM_CAP_START + 21
$WM_CAP_FILE_GET_CAPTURE_FILEW = $WM_CAP_UNICODE_START + 21
$WM_CAP_FILE_SAVEASA = $WM_CAP_START + 23
$WM_CAP_FILE_SAVEASW = $WM_CAP_UNICODE_START + 23
$WM_CAP_FILE_SAVEDIBA = $WM_CAP_START + 25
$WM_CAP_FILE_SAVEDIBW = $WM_CAP_UNICODE_START + 25
$WM_CAP_FILE_SET_CAPTURE_FILEA = $WM_CAP_START + 20
$WM_CAP_FILE_SET_CAPTURE_FILEW = $WM_CAP_UNICODE_START + 20
$WM_CAP_FILE_SET_INFOCHUNK = $WM_CAP_START + 24
$WM_CAP_GET_AUDIOFORMAT = $WM_CAP_START + 36
$WM_CAP_GET_CAPSTREAMPTR = $WM_CAP_START + 1
$WM_CAP_GET_MCI_DEVICEA = $WM_CAP_START + 67
$WM_CAP_GET_MCI_DEVICEW = $WM_CAP_UNICODE_START + 67
$WM_CAP_GET_SEQUENCE_SETUP = $WM_CAP_START + 65
$WM_CAP_GET_STATUS = $WM_CAP_START + 54
$WM_CAP_GET_USER_DATA = $WM_CAP_START + 8
$WM_CAP_GET_VIDEOFORMAT = $WM_CAP_START + 44
$WM_CAP_GRAB_FRAME = $WM_CAP_START + 60
$WM_CAP_GRAB_FRAME_NOSTOP = $WM_CAP_START + 61
$WM_CAP_PAL_AUTOCREATE = $WM_CAP_START + 83
$WM_CAP_PAL_MANUALCREATE = $WM_CAP_START + 84
$WM_CAP_PAL_OPENA = $WM_CAP_START + 80
$WM_CAP_PAL_OPENW = $WM_CAP_UNICODE_START + 80
$WM_CAP_PAL_PASTE = $WM_CAP_START + 82
$WM_CAP_SEQUENCE = $WM_CAP_START + 62
$WM_CAP_SEQUENCE_NOFILE = $WM_CAP_START + 63
$WM_CAP_SET_AUDIOFORMAT = $WM_CAP_START + 35
$WM_CAP_SET_CALLBACK_CAPCONTROL = $WM_CAP_START + 85
$WM_CAP_SET_CALLBACK_ERRORA = $WM_CAP_START + 2
$WM_CAP_SET_CALLBACK_ERRORW = $WM_CAP_UNICODE_START + 2
$WM_CAP_SET_CALLBACK_FRAME = $WM_CAP_START + 5
$WM_CAP_SET_CALLBACK_STATUSA = $WM_CAP_START + 3
$WM_CAP_SET_CALLBACK_STATUSW = $WM_CAP_UNICODE_START + 3
$WM_CAP_SET_CALLBACK_VIDEOSTREAM = $WM_CAP_START + 6
$WM_CAP_SET_CALLBACK_WAVESTREAM = $WM_CAP_START + 7
$WM_CAP_SET_CALLBACK_YIELD = $WM_CAP_START + 4
$WM_CAP_SET_MCI_DEVICEA = $WM_CAP_START + 66
$WM_CAP_SET_MCI_DEVICEW = $WM_CAP_UNICODE_START + 66
$WM_CAP_SET_OVERLAY = $WM_CAP_START + 51
$WM_CAP_SET_PREVIEW = $WM_CAP_START + 50
$WM_CAP_SET_PREVIEWRATE = $WM_CAP_START + 52
$WM_CAP_SET_SCALE = $WM_CAP_START + 53
$WM_CAP_SET_SCROLL = $WM_CAP_START + 55
$WM_CAP_SET_SEQUENCE_SETUP = $WM_CAP_START + 64
$WM_CAP_SET_USER_DATA = $WM_CAP_START + 9
$WM_CAP_SET_VIDEOFORMAT = $WM_CAP_START + 45
$WM_CAP_SINGLE_FRAME = $WM_CAP_START + 72
$WM_CAP_SINGLE_FRAME_CLOSE = $WM_CAP_START + 71
$WM_CAP_SINGLE_FRAME_OPEN = $WM_CAP_START + 70
$WM_CAP_STOP = $WM_CAP_START + 68
$cap = ""
$avi = ""
$user = ""


Func _WebcamInit()
$avi = DllOpen("avicap32.dll")
$user = DllOpen("user32.dll")
EndFunc

;===============================================================================
;
; Description:    Open's a Webcam preview screen in your gui
; Syntax:          _WebcamOpen($sHwnd, $sLeft, $sTop, $sWidth, $sHeight)
; Parameter(s):  $sHwnd  - The handle of the gui
;                  $sLeft    - Left coord. of the preview screen
;                  $sTop      - Top coord. of the preview screen
;                  $sWidth  - Width of the preview screen
;                  $sHeight   - Height of the preview screen
; Requirement(s):   A webcam
; Return Value(s):  On Success - Returns id needed for other controls
;                  On Failure - Returns -1
;
;===============================================================================
func _WebcamOpen($sHwnd, $sLeft, $sTop, $sWidth, $sHeight)
$cap = DllCall($avi, "int", "capCreateCaptureWindow", "str", "cap", "int", BitOR($WS_CHILD,$WS_VISIBLE), "int", $sLeft, "int", $sTop, "int", $sWidth, "int", $sHeight, "hwnd", $sHwnd, "int", 1)
DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_DRIVER_CONNECT, "int", 0, "int", 0)
DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_SCALE, "int", 1, "int", 0)
DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_OVERLAY, "int", 1, "int", 0)
DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_PREVIEW, "int", 1, "int", 0)
DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_PREVIEWRATE, "int", 1, "int", 0)
if @error then return -1
return $cap[0]
EndFunc

;===============================================================================
;
; Description:    Creates a Snapshot from a webcam
; Syntax:          _WebcamSnap($sId, $sFile)
; Parameter(s):  $sId      - Id (returned from _WebcamOpen)
;                  $sFile    - File to save the snapshot to (*.bmp)
; Requirement(s):   A webcam
; Return Value(s):  On Success - Returns 1
;                  On Failure - Returns 0
;
;===============================================================================
Func _WebcamSnap($sId, $sFile)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_GRAB_FRAME_NOSTOP, "int", 0, "int", 0)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_FILE_SAVEDIBA, "int", 0, "str", $sFile)
    if @error Then
        return 0
    Else
        return 1
    EndIf
EndFunc

;===============================================================================
;
; Description:    Closes the preview screen created with _WebcamOpen
; Syntax:          _WebcamClose($sId)
; Parameter(s):  $sId      - Id (returned from _WebcamOpen)
; Requirement(s):   A webcam
; Return Value(s):  On Success - Returns 1
;                  On Failure - Returns 0
;
;===============================================================================
Func _WebcamClose($sId)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_END, "int", 0, "int", 0)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_DRIVER_DISCONNECT, "int", 0, "int", 0)
    DllClose($user)
    DllClose($avi)
    if @error Then
        return 0
    Else
        return 1
    EndIf
EndFunc

;===============================================================================
;
; Description:    Starts recording the Webcam to a file
; Syntax:          _WebcamRecordStart($sFile, $sId)
; Parameter(s):  $sId      - Id (returned from _WebcamOpen)
;                  $sFile    - File to save the movie to (*.avi)
; Requirement(s):   A webcam
; Return Value(s):  On Success - Returns 1
;                  On Failure - Returns 0
; Note(s):        Stop recording by: _WebcamRecordStop($Id)
;
;===============================================================================
Func _WebcamRecordStart($sFile, $sId)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_FILE_SET_CAPTURE_FILEA, "int", 0, "str", $sFile)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_SEQUENCE, "int", 0, "int", 0)
    if @error Then
        return 0
    Else
        return 1
    EndIf

EndFunc

;===============================================================================
;
; Description:    Stops recording.
; Syntax:          _WebcamRecordStop($sId)
; Parameter(s):  $sId      - Id (returned from _WebcamOpen)
; Requirement(s):   A webcam
; Return Value(s):  On Success - Returns 1
;                  On Failure - Returns 0
;
;===============================================================================
Func _WebcamRecordStop($sId)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_STOP, "int", 0, "int", 0)
    if @error Then
        return 0
    Else
        return 1
    EndIf
EndFunc

Func _WebcamSetup($sId)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_DLG_VIDEOSOURCE, "int", 0, "int", 0)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_DLG_VIDEODISPLAY, "int", 0, "int", 0)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_DLG_VIDEOFORMAT, "int", 1, "int", 0)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_DLG_VIDEOCOMPRESSION, "int", 0, "int", 0)
EndFunc

How do i make it take a screenshot?

Share this post


Link to post
Share on other sites
martin

If you mean snapshot rather than screenshot then have you tried the _WebcamSnap function which I see is in the code you posted.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
TheNorwegianUser

If you mean snapshot rather than screenshot then have you tried the _WebcamSnap function which I see is in the code you posted.

Yea, but how do i call that function?

Share this post


Link to post
Share on other sites
AoRaToS

It really depends on when you want a snapshot to be taken.

You can call it immediately after the cam has loaded so you just add it to your code, or pressing a Hotkey can call it or when some other event triggers it. For example you monitor mouse behavior, after the mouse being idle for a few minutes if it moves you a snapshot.

Someone else had made a script that would lock your computer when it was idle for a bit and ask for a passcode to login, if you would enter the passcode wrong it would take a snapshot and record the time you tried to login. So it all depends on your project.


s!mpL3 LAN Messenger

Current version 2.9.8.8 [30/09/2015]

Download Here

s!mpL3

Share this post


Link to post
Share on other sites
TheNorwegianUser

It really depends on when you want a snapshot to be taken.

You can call it immediately after the cam has loaded so you just add it to your code, or pressing a Hotkey can call it or when some other event triggers it. For example you monitor mouse behavior, after the mouse being idle for a few minutes if it moves you a snapshot.

Someone else had made a script that would lock your computer when it was idle for a bit and ask for a passcode to login, if you would enter the passcode wrong it would take a snapshot and record the time you tried to login. So it all depends on your project.

So i should just add this to the script where i want it to take a snapshot?

DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_GRAB_FRAME_NOSTOP, "int", 0, "int", 0)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_FILE_SAVEDIBA, "int", 0, "str", $sFile)

When i do that, i get these errors:

C:Program Files (x86)AutoIt3IncludeWebcam.au3(89,54) : WARNING: $sId: possibly used before declaration.
    DllCall($user, "int", "SendMessage", "hWnd", $sId,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Program Files (x86)\AutoIt3\Include\Webcam.au3(90,109) : WARNING: $sFile: possibly used before declaration.
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_FILE_SAVEDIBA, "int", 0, "str", $sFile)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Program Files (x86)\AutoIt3\Include\Webcam.au3(89,54) : ERROR: $sId: undeclared global variable.
    DllCall($user, "int", "SendMessage", "hWnd", $sId,

And you have alredy written this, but i don't see how it returns $sId, because $sId isn't written in _WebcamOpen.

; Parameter(s):  $sId     - Id (returned from _WebcamOpen)
;                 $sFile    - File to save the snapshot to (*.bmp)

Share this post


Link to post
Share on other sites
AoRaToS

If you've added the whole webcam.au3 to your script or you have included it, all you need to do is add this:

_WebcamSnap($webcam, "C:image.bmp")


s!mpL3 LAN Messenger

Current version 2.9.8.8 [30/09/2015]

Download Here

s!mpL3

Share this post


Link to post
Share on other sites
TheNorwegianUser

Now it just shows black all the time... Maybe i did somehting wrong when i added the other stuff i wanted?

#include-once
#NoTrayIcon
#include <EditConstants.au3>
#include <ScrollBarConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <ProgressConstants.au3>
#include <GuiEdit.au3>
#include <Misc.au3>
#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>

$WM_CAP_START = 0x400
$WM_CAP_UNICODE_START = $WM_CAP_START +100
$WM_CAP_PAL_SAVEA = $WM_CAP_START + 81
$WM_CAP_PAL_SAVEW = $WM_CAP_UNICODE_START + 81
$WM_CAP_UNICODE_END = $WM_CAP_PAL_SAVEW
$WM_CAP_ABORT = $WM_CAP_START + 69
$WM_CAP_DLG_VIDEOCOMPRESSION = $WM_CAP_START + 46
$WM_CAP_DLG_VIDEODISPLAY = $WM_CAP_START + 43
$WM_CAP_DLG_VIDEOFORMAT = $WM_CAP_START + 41
$WM_CAP_DLG_VIDEOSOURCE = $WM_CAP_START + 42
$WM_CAP_DRIVER_CONNECT = $WM_CAP_START + 10
$WM_CAP_DRIVER_DISCONNECT = $WM_CAP_START + 11
$WM_CAP_DRIVER_GET_CAPS = $WM_CAP_START + 14
$WM_CAP_DRIVER_GET_NAMEA = $WM_CAP_START + 12
$WM_CAP_DRIVER_GET_NAMEW = $WM_CAP_UNICODE_START + 12
$WM_CAP_DRIVER_GET_VERSIONA = $WM_CAP_START + 13
$WM_CAP_DRIVER_GET_VERSIONW = $WM_CAP_UNICODE_START + 13
$WM_CAP_EDIT_COPY = $WM_CAP_START + 30
$WM_CAP_END = $WM_CAP_UNICODE_END
$WM_CAP_FILE_ALLOCATE = $WM_CAP_START + 22
$WM_CAP_FILE_GET_CAPTURE_FILEA = $WM_CAP_START + 21
$WM_CAP_FILE_GET_CAPTURE_FILEW = $WM_CAP_UNICODE_START + 21
$WM_CAP_FILE_SAVEASA = $WM_CAP_START + 23
$WM_CAP_FILE_SAVEASW = $WM_CAP_UNICODE_START + 23
$WM_CAP_FILE_SAVEDIBA = $WM_CAP_START + 25
$WM_CAP_FILE_SAVEDIBW = $WM_CAP_UNICODE_START + 25
$WM_CAP_FILE_SET_CAPTURE_FILEA = $WM_CAP_START + 20
$WM_CAP_FILE_SET_CAPTURE_FILEW = $WM_CAP_UNICODE_START + 20
$WM_CAP_FILE_SET_INFOCHUNK = $WM_CAP_START + 24
$WM_CAP_GET_AUDIOFORMAT = $WM_CAP_START + 36
$WM_CAP_GET_CAPSTREAMPTR = $WM_CAP_START + 1
$WM_CAP_GET_MCI_DEVICEA = $WM_CAP_START + 67
$WM_CAP_GET_MCI_DEVICEW = $WM_CAP_UNICODE_START + 67
$WM_CAP_GET_SEQUENCE_SETUP = $WM_CAP_START + 65
$WM_CAP_GET_STATUS = $WM_CAP_START + 54
$WM_CAP_GET_USER_DATA = $WM_CAP_START + 8
$WM_CAP_GET_VIDEOFORMAT = $WM_CAP_START + 44
$WM_CAP_GRAB_FRAME = $WM_CAP_START + 60
$WM_CAP_GRAB_FRAME_NOSTOP = $WM_CAP_START + 61
$WM_CAP_PAL_AUTOCREATE = $WM_CAP_START + 83
$WM_CAP_PAL_MANUALCREATE = $WM_CAP_START + 84
$WM_CAP_PAL_OPENA = $WM_CAP_START + 80
$WM_CAP_PAL_OPENW = $WM_CAP_UNICODE_START + 80
$WM_CAP_PAL_PASTE = $WM_CAP_START + 82
$WM_CAP_SEQUENCE = $WM_CAP_START + 62
$WM_CAP_SEQUENCE_NOFILE = $WM_CAP_START + 63
$WM_CAP_SET_AUDIOFORMAT = $WM_CAP_START + 35
$WM_CAP_SET_CALLBACK_CAPCONTROL = $WM_CAP_START + 85
$WM_CAP_SET_CALLBACK_ERRORA = $WM_CAP_START + 2
$WM_CAP_SET_CALLBACK_ERRORW = $WM_CAP_UNICODE_START + 2
$WM_CAP_SET_CALLBACK_FRAME = $WM_CAP_START + 5
$WM_CAP_SET_CALLBACK_STATUSA = $WM_CAP_START + 3
$WM_CAP_SET_CALLBACK_STATUSW = $WM_CAP_UNICODE_START + 3
$WM_CAP_SET_CALLBACK_VIDEOSTREAM = $WM_CAP_START + 6
$WM_CAP_SET_CALLBACK_WAVESTREAM = $WM_CAP_START + 7
$WM_CAP_SET_CALLBACK_YIELD = $WM_CAP_START + 4
$WM_CAP_SET_MCI_DEVICEA = $WM_CAP_START + 66
$WM_CAP_SET_MCI_DEVICEW = $WM_CAP_UNICODE_START + 66
$WM_CAP_SET_OVERLAY = $WM_CAP_START + 51
$WM_CAP_SET_PREVIEW = $WM_CAP_START + 50
$WM_CAP_SET_PREVIEWRATE = $WM_CAP_START + 52
$WM_CAP_SET_SCALE = $WM_CAP_START + 53
$WM_CAP_SET_SCROLL = $WM_CAP_START + 55
$WM_CAP_SET_SEQUENCE_SETUP = $WM_CAP_START + 64
$WM_CAP_SET_USER_DATA = $WM_CAP_START + 9
$WM_CAP_SET_VIDEOFORMAT = $WM_CAP_START + 45
$WM_CAP_SINGLE_FRAME = $WM_CAP_START + 72
$WM_CAP_SINGLE_FRAME_CLOSE = $WM_CAP_START + 71
$WM_CAP_SINGLE_FRAME_OPEN = $WM_CAP_START + 70
$WM_CAP_STOP = $WM_CAP_START + 68
$cap = ""
$avi = ""
$user = ""
$Count=1
$Password="Password"



$1=MouseGetPos(0)
While 1
If _IsPressed("1B") Then
  Exit
EndIf
$2=MouseGetPos(0)
If $1<>$2 Then
  ExitLoop
EndIf
    Sleep(10)
WEnd
$gui = GUICreate("Webcam", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOOLWINDOW)
$Label = GUICtrlCreateLabel("", 5, 0, 100, 18)
_WebcamInit()
$webcam = _WebcamOpen($gui,20, 20, @DesktopWidth - 40, @DesktopHeight - 40)
;_WebcamSetup($webcam)
GUISetState(@SW_SHOW)
Sleep(1000)

_WebcamSnap($webcam, @ScriptDir & "DivScreenshot" & $Count & ".bmp")
$Count = $Count + 1
Sleep(500)

$btn = 6
If $btn = 6 Then
    $Locked = GUICreate("Desktop Locker", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOPMOST)
    GUISetBkColor(0x000000, $Locked)
    $Progress1 = GUICtrlCreateProgress((@DesktopWidth - 400) / 2, @DesktopHeight / 2 + 20, 400, 10)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlCreatePic("lock.gif", 430, 130, 164, 144)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    $WrongPw = GUICtrlCreateEdit("", 10, 14, 300, @DesktopHeight - 14, BitOR($ES_AUTOVSCROLL, $ES_READONLY), 0)
    $InputPw = GUICtrlCreateInput("", @DesktopWidth / 2 - 100, @DesktopHeight / 2 - 10, 200, 20, BitOR($ES_CENTER, $ES_PASSWORD), 0)
    GUICtrlCreateLabel("Desktop Locker", @DesktopWidth / 2 - 125, @DesktopHeight / 2 - 95, 260, 50, $ES_CENTER, 0)
    GUICtrlSetFont(-1, 30, 800, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0xFFFFFF)
    GUICtrlSetBkColor(-1, 0x000000)
    GUICtrlCreateLabel("Please enter a password to unlock the screen.", @DesktopWidth / 2 - 185, @DesktopHeight / 2 - 50, 400, 20, $ES_CENTER, 0)
    GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0xFFFFFF)
    GUICtrlSetBkColor(-1, 0x000000)
    GUICtrlSetFont($WrongPw, 12, 800, 0, "MS Sans Serif")
    GUICtrlSetColor($WrongPw, 0xFFFFFF)
    GUICtrlSetBkColor($WrongPw, 0x000000)
    GUICtrlSetFont($InputPw, 12, 800, 0, "MS Sans Serif")
    GUICtrlSetColor($InputPw, 0xFFFFFF)
    GUICtrlSetBkColor($InputPw, 0x000000)
    WinSetState("[CLASS:Shell_TrayWnd]", "", @SW_HIDE)
    GUISetState(@SW_SHOW, $Locked)
    _MouseTrap(@DesktopWidth, @DesktopHeight)
    While 1
  $msg = GUIGetMsg()
  If $msg = $GUI_EVENT_CLOSE Then
   _WebcamClose($webcam)
   Exit
  EndIf
        If _IsPressed("0D") Then
            If GUICtrlRead($InputPw) == '' Then
                ToolTip("Forgot your password. Please enter the correct", 509, 375, "", 1, 3)
    ToolTip("")
            ElseIf GUICtrlRead($InputPw) == $Password Then
                For $i = 0 To 100 Step 10
                    GUICtrlSetData($Progress1, $i)
                    Sleep(50)
                Next
                GUISetState(@SW_HIDE, $Locked)
                WinSetState("[CLASS:Shell_TrayWnd]", "", @SW_SHOW)
                _MouseTrap()
                ExitLoop
            Else
                GUICtrlSetData($WrongPw, _RandomMsg() & @CRLF & GUICtrlRead($WrongPw))
                ToolTip("The password is incorrect ..try again.", 509, 375, "", 3, 3)
                GUICtrlSetData($InputPw, "")
    _WebcamSnap($webcam, @ScriptDir & "DivScreenshot" & $Count & ".bmp")
    $Count = $Count + 1
    Sleep(500)
                ToolTip("")
            EndIf
        EndIf
        If Not WinActive("Desktop Locker") Then
            WinActivate("Desktop Locker")
            _MouseTrap(@DesktopWidth, @DesktopHeight)
            GUICtrlCreateLabel("MESS WITH THE BEST DIE LIKE THE REST!", Random(@DesktopWidth - 540), Random(@DesktopHeight - 30), 540, 30)
            GUICtrlSetFont(-1, 20, 800, 0, "MS Sans Serif")
            GUICtrlSetColor(-1, 0xFF0000)
            GUICtrlSetBkColor(-1, 0x000000)
        EndIf
    WEnd
Else
    Exit
EndIf
Func _RandomMsg()
    Local $RandomMsg[13]
    $RandomMsg[0] = "Wrong Password!"
    $RandomMsg[1] = "Keep Out."
    $RandomMsg[2] = "Top Secret."
    $RandomMsg[3] = "Give Up!"
    $RandomMsg[4] = "Don't Touch!"
    $RandomMsg[5] = "Please Enter Correct Password."
    $RandomMsg[6] = "Try Again!"
    $RandomMsg[7] = "Stop pushing my buttons."
    $RandomMsg[8] = "Hahahhahahahha"
    $RandomMsg[9] = "hahhahahahahaahahhahaahhah"
$RandomMsg[10] = "MESS WITH THE BEST DIE LIKE THE REST"
$RandomMsg[11] = "You won't guess it!"
$RandomMsg[12] = "LMAO"
    Return $RandomMsg[Random(13)]
EndFunc   ;==>_RandomMsg



Func _WebcamInit()
$avi = DllOpen("avicap32.dll")
$user = DllOpen("user32.dll")
EndFunc
;===============================================================================
;
; Description:    Open's a Webcam preview screen in your gui
; Syntax:         _WebcamOpen($sHwnd, $sLeft, $sTop, $sWidth, $sHeight)
; Parameter(s):  $sHwnd  - The handle of the gui
;                 $sLeft    - Left coord. of the preview screen
;                 $sTop   - Top coord. of the preview screen
;                 $sWidth    - Width of the preview screen
;                 $sHeight   - Height of the preview screen
; Requirement(s):   A webcam
; Return Value(s):  On Success - Returns id needed for other controls
;                 On Failure - Returns -1f
;
;===============================================================================
func _WebcamOpen($sHwnd, $sLeft, $sTop, $sWidth, $sHeight)
$cap = DllCall($avi, "int", "capCreateCaptureWindow", "str", "cap", "int", BitOR($WS_CHILD,$WS_VISIBLE), "int", $sLeft, "int", $sTop, "int", $sWidth, "int", $sHeight, "hwnd", $sHwnd, "int", 1)
DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_DRIVER_CONNECT, "int", 0, "int", 0)
DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_SCALE, "int", 1, "int", 0)
DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_OVERLAY, "int", 1, "int", 0)
DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_PREVIEW, "int", 1, "int", 0)
DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_PREVIEWRATE, "int", 1, "int", 0)
if @error then return -1
return $cap[0]
EndFunc
;===============================================================================
;
; Description:    Creates a Snapshot from a webcam
; Syntax:         _WebcamSnap($sId, $sFile)
; Parameter(s):  $sId     - Id (returned from _WebcamOpen)
;                 $sFile    - File to save the snapshot to (*.bmp)
; Requirement(s):   A webcam
; Return Value(s):  On Success - Returns 1
;                 On Failure - Returns 0
;
;===============================================================================
Func _WebcamSnap($sId, $sFile)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_GRAB_FRAME_NOSTOP, "int", 0, "int", 0)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_FILE_SAVEDIBA, "int", 0, "str", $sFile)
    if @error Then
        return 0
    Else
        return 1
    EndIf
EndFunc
;===============================================================================
;
; Description:    Closes the preview screen created with _WebcamOpen
; Syntax:         _WebcamClose($sId)
; Parameter(s):  $sId     - Id (returned from _WebcamOpen)
; Requirement(s):   A webcam
; Return Value(s):  On Success - Returns 1
;                 On Failure - Returns 0
;
;===============================================================================
Func _WebcamClose($sId)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_END, "int", 0, "int", 0)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_DRIVER_DISCONNECT, "int", 0, "int", 0)
    DllClose($user)
    DllClose($avi)
    if @error Then
        return 0
    Else
        return 1
    EndIf
EndFunc
;===============================================================================
;
; Description:    Starts recording the Webcam to a file
; Syntax:         _WebcamRecordStart($sFile, $sId)
; Parameter(s):  $sId     - Id (returned from _WebcamOpen)
;                 $sFile    - File to save the movie to (*.avi)
; Requirement(s):   A webcam
; Return Value(s):  On Success - Returns 1
;                 On Failure - Returns 0
; Note(s):      Stop recording by: _WebcamRecordStop($Id)
;
;===============================================================================
Func _WebcamRecordStart($sFile, $sId)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_FILE_SET_CAPTURE_FILEA, "int", 0, "str", $sFile)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_SEQUENCE, "int", 0, "int", 0)
    if @error Then
        return 0
    Else
        return 1
    EndIf
EndFunc
;===============================================================================
;
; Description:    Stops recording.
; Syntax:         _WebcamRecordStop($sId)
; Parameter(s):  $sId     - Id (returned from _WebcamOpen)
; Requirement(s):   A webcam
; Return Value(s):  On Success - Returns 1
;                 On Failure - Returns 0
;
;===============================================================================
Func _WebcamRecordStop($sId)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_STOP, "int", 0, "int", 0)
    if @error Then
        return 0
    Else
        return 1
    EndIf
EndFunc
Func _WebcamSetup($sId)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_DLG_VIDEOSOURCE, "int", 0, "int", 0)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_DLG_VIDEODISPLAY, "int", 0, "int", 0)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_DLG_VIDEOFORMAT, "int", 1, "int", 0)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_DLG_VIDEOCOMPRESSION, "int", 0, "int", 0)
EndFunc

Share this post


Link to post
Share on other sites
TheNorwegianUser

Same problem with my friends computer. Works the first time, but after that it doesn't work. Except that now i cant even make it work the first time either.

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  

×