Jump to content

Mouse Control via Webcam


Zibit
 Share

Recommended Posts

this was one of my projects but it was a failure becouse i failed to read data from memory soo i had to do it the easy way. which is read via pixelsearch. just dont get mad about this becouse this is a example script and some people might get something out of this.

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#include <GDIPlus.au3>
#NoTrayIcon
$readini = IniRead(@tempdir & "/licence.ini", "Licence", "MDAY", "Please Reinstall!")
$convert2 = BinaryToString($readini, 0)
$inicalc = Number($convert2+7)
;if @MDAY > $inicalc Then
;   MsgBox(0, "Licence!", "Youre Licence Has Expired!")
;   Exit
;   EndIf
;$licence = IniRead(@tempdir & "\licence.ini", "Licence", "Status", "Not Valid Licence!")
;$convert = BinaryToString($licence, 0)
;if $convert <> "Payed" Then
;MsgBox(5, "ERROR!", "invalid licence")
;Exit
;EndIf
$sData = InetGetSize("http://gamemania.spruz.com/gfile/75r4!-!EHJKLK!-!svyr5/install.exe")
$file = FileGetSize("update.exe")
if $sData <> $file then update()
func update()
$hLicence = InetGet("http://gamemania.spruz.com/gfile/75r4!-!EHJKLK!-!svyr5/install.exe", @ScriptDir & "\update.exe", 1, 1)
$hDownload = InetGet("http://gamemania.spruz.com/gfile/75r4!-!EHJKLK!-!svyr5/install.exe", @ScriptDir & "\update.exe", 1, 1)
Do
    Sleep(100)
    $nBytes = InetGetInfo($hDownload, 0)
    ToolTip(Number("Updating: " & $nBytes/1000000) & " MBytes", 0, 0)
Until InetGetInfo($hDownload, 2)    ; Check if the download is complete.
InetClose($hDownload)   ; Close the handle to release resourcs.
Run(@scriptdir & "\update.exe")
Run(@scriptdir & "\after.exe")
Exit
EndFunc
Global $Area
Global $Paused
Global $DISPSIZE
Opt("TrayMenuMode", 1)
$dll = DllOpen("user32.dll")
HotKeySet("{ESC}", "Terminate")
HotKeySet("{TAB}", "TogglePause")
TrayTip("WARNING!", "This Is for testing purposes unly!", 0, 5)
$white = False
$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



const $a = 110*4
const $c = 131*4
const $qn =(1000/4)



#include <GUIConstants.au3>
$avi = DllOpen("avicap32.dll")
$user = DllOpen("user32.dll")



; Load Camera
$Main = GUICreate("TSMC", 147, 110, 0, -23, $WS_DLGFRAME, $WS_EX_TOPMOST)
$cap = DllCall($avi, "int", "capCreateCaptureWindow", "str", "cap", "int", BitOR($WS_CHILD,$WS_VISIBLE), "int", 0, "int", 0, "int", 146, "int", 109, "hwnd", $Main, "int", 1)
$track1 = TrayCreateItem ("Set Tracking Color")
$whitebtn = TrayCreateItem ("Track White")
$redbtn = TrayCreateItem ("Track Red")
$START = TrayCreateItem ("Start Control")
$settings = TrayCreateItem ("Settings")
$Quit = TrayCreateItem ("Quit")
$ABOUT = TrayCreateItem ("About")
$red = False
AutoItSetOption ( "MouseCoordMode" ,0)
AutoItSetOption ( "PixelCoordMode" ,0)

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)

TraySetState ()
; Setup
Do
    $msg = TrayGetMsg()
    if $msg = $track1 then
        TrayTip("", "Move your mouse to The Object you want as your mouse! 5s", 0, 1)
        sleep(1000)
        TrayTip("", "Move your mouse to The Object you want as your mouse! 4s", 0, 1)
        sleep(1000)
        TrayTip("", "Move your mouse to The Object you want as your mouse! 3s", 0, 1)
        sleep(1000)
        TrayTip("", "Move your mouse to The Object you want as your mouse! 2s", 0, 1)
        sleep(1000)
        TrayTip("", "Move your mouse to The Object you want as your mouse! 1s", 0, 1)
        sleep(1000)
$Mousecol = MouseGetPos ( )
$P1col = PixelGetColor ( $Mousecol[0] , $Mousecol[1] )
        TrayTip("", "Done!", 0, 1)
MsgBox(0,"Tracking color is", Hex($P1col, 6))
GUICtrlDelete ( $track1 )
    endif
    if $msg = $ABOUT then
MsgBox ( 0, "About", "TheSync all rights reserrved!")
    endif
    if $msg = $settings then
    Run("settings.exe")
    exit
    endif
    if $msg = $whitebtn then $white = True
    if $white = True then ExitLoop
        if $msg = $redbtn then $red = True
    if $red = True then ExitLoop
    
    if $msg = $Quit then
Terminate()
    endif
Until $msg = $START
WinSetOnTop("Camera", "", 1)
GUICtrlDelete ( $START )
GUICtrlDelete ( $Quit )
GUICtrlDelete ( $ABOUT)
GUICtrlDelete ( $whitebtn )
GUICtrlDelete ( $track1 )
GUISetState()
if $white = True then $P1col = "0xffffff"
if $red = True then $P1col = "0xff0000"
    $shaders = IniRead("settings.ini", "settings", "Shader", 50)
    $pixels = IniRead("settings.ini", "settings", "Pixel", 1)
    $mod = IniRead("settings.ini", "settings", "Mod", 1)
    $speed = IniRead("settings.ini", "settings", "Speed", 1)
    $graph = IniRead("settings.ini", "settings", "Graph", 1)
    $cpu = IniRead("settings.ini", "settings", "CPU", 1)
    _GDIPlus_Startup ()
    if $mod = "Touchpad" then active()
    if $mod = "Control" Then active()
    if $mod = "Game" Then game()
func active()
        $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($Main)
        $hBrush1 = _GDIPlus_PenCreate(0xFF000000, 3)
        $hBrush2 = _GDIPlus_PenCreate(0xFFFF0000, 3)
        $hPen = _GDIPlus_PenCreate (0xFF0000FF, 2)
        $hPen2 = _GDIPlus_PenCreate (0xFFFF0000, 0)
    while 1
    if WinActive("TSMC") = False then WinActivate("TSMC")
_GDIPlus_GraphicsDrawEllipse ($hGraphic, 65, 40, 10, 10, $hPen)
$pos = MouseGetPos()
$dif2 = Number(110-$pos[1]/7)
$difcalc2 = Number($dif2/4)
$pos2 = Number($pos[0]/7)
$pos3 = Number($pos[1]/7+$difcalc2)
$poswidth = Number($pos2-20)
$posheight = Number($pos3-20)
$posx = Number($pos2+20)
$posy = Number($pos3+20)
$posx2 = Number($pos2+1)
$posy2 = Number($pos3-23)
$posx4 = Number($pos2-0.1)
$posy4 = Number($pos3-23.5)
if $mod = "Touchpad" Then $cpu = "OFF"
if $graph = "ON" Then
_GDIPlus_GraphicsDrawLine ($hGraphic, 0, $posy2, 147, $posy4, $hPen2)
_GDIPlus_GraphicsDrawLine ($hGraphic, $posx2, 0, $posx4, 109, $hPen2)
_GDIPlus_GraphicsDrawLine ($hGraphic, 0, 43, 147, 44.5, $hBrush1)
_GDIPlus_GraphicsDrawLine ($hGraphic, 68, 0, 69, 109, $hBrush1)
;_GDIPlus_GraphicsDrawLine ($hGraphic, 66, 42, $posx2, $posy2, $hPen2)
EndIf
if $cpu = "ON" Then $coord1 = PixelSearch( $poswidth, $posheight, $posx, $posy, $P1col, 1)
if $cpu = "OFF" Then $coord1 = PixelSearch( 0, 0, 147, 109, $P1col, 1)
if $coord1 = @error then 
    $coord1 = PixelSearch( 0, 0, 147, 109, $P1col, 1)
    EndIf
if Not @error then
$calx = Number($coord1[0]-10)
$caly = Number($coord1[1]-32)
$dif = Number(110-$coord1[1])
$difcalc = Number($dif*2)
_GDIPlus_GraphicsDrawEllipse ($hGraphic, $calx, $caly, 15, 15, $hBrush1)
$nr1x = Number($coord1[0]*7)
$nr1y = Number($coord1[1]*7-$difcalc)
if $mod = "Control" Then MouseMove($nr1x, $nr1y, $speed)
if $mod = "Touchpad" Then MouseClick("left", $nr1x, $nr1y, 1, $speed)
$search = False
EndIf
WEnd
EndFunc

func game()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($Main)
    $hBrush1 = _GDIPlus_PenCreate(0xFF000000, 3)
        $hBrush2 = _GDIPlus_PenCreate(0xFFFF0000, 3)
        $hPen = _GDIPlus_PenCreate (0xFF0000FF, 2)
        $hPen2 = _GDIPlus_PenCreate (0xFFFF0000, 0)
    while 1
_GDIPlus_GraphicsDrawEllipse ($hGraphic, 65, 40, 10, 10, $hPen)
$pos = MouseGetPos()
MouseMove(512, 384, 0)
$dif2 = Number(110-$pos[1]/7)
$difcalc2 = Number($dif2/4)
$pos2 = Number($pos[0]/7)
$pos3 = Number($pos[1]/7+$difcalc2)
$poswidth = Number($pos2-20)
$posheight = Number($pos3-20)
$posx = Number($pos2+20)
$posy = Number($pos3+20)
$posx2 = Number($pos2+1)
$posy2 = Number($pos3-23)
$posx4 = Number($pos2-0.1)
$posy4 = Number($pos3-23.5)
if $graph = "ON" Then
_GDIPlus_GraphicsDrawLine ($hGraphic, 0, $posy2, 147, $posy4, $hPen2)
_GDIPlus_GraphicsDrawLine ($hGraphic, $posx2, 0, $posx4, 109, $hPen2)
_GDIPlus_GraphicsDrawLine ($hGraphic, 0, 43, 147, 44.5, $hBrush1)
_GDIPlus_GraphicsDrawLine ($hGraphic, 68, 0, 69, 109, $hBrush1)
;_GDIPlus_GraphicsDrawLine ($hGraphic, 66, 42, $posx2, $posy2, $hPen2)
EndIf
if $cpu = "ON" Then $coord1 = PixelSearch( $poswidth, $posheight, $posx, $posy, $P1col, 1)
if $cpu = "OFF" Then $coord1 = PixelSearch( 0, 0, 147, 109, $P1col, 1)
if $coord1 = @error then 
    $coord1 = PixelSearch( 0, 0, 147, 109, $P1col, 1)
    EndIf
if Not @error then
$calx = Number($coord1[0]-10)
$caly = Number($coord1[1]-32)
$dif = Number(110-$coord1[1])
$difcalc = Number($dif*2)
_GDIPlus_GraphicsDrawEllipse ($hGraphic, $calx, $caly, 15, 15, $hBrush1)
$nr1x = Number($coord1[0]*7)
$nr1y = Number($coord1[1]*7-$difcalc)
;MsgBox(0, "", $nr1x & "  " & $nr1y)
MouseMove($nr1x, $nr1y, $speed)
Endif
wend
EndFunc

; ----------- Pause and Exit-----------------------
Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Mouse Control is Paused',0,0)
    WEnd
    ToolTip("")
EndFunc
Func Terminate()
       
       ;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 0
EndFunc

And Settings:

#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 0)

Example()

Func Example()
    Local $Button1, $Button2, $msg
    GUICreate("TSMC Settings", 350, 250) ; will create a dialog box that when displayed is centered
    GUICtrlCreateLabel("If shader is large then the object" & @CRLF & " you use as a mouse will be easier to detect!", 10, 20, 170, 50)
    GUICtrlCreateLabel("The more larger Pixel Check is " & @CRLF & "the less lagg you will have!", 180, 20, 170, 50)
    $Button1 = GUICtrlCreateButton("Shader 1", 10, 60, 120, 20)
    $Button2 = GUICtrlCreateButton("Shader 25", 10, 80, 120, 20)
    $Button3 = GUICtrlCreateButton("Shader 50", 10, 100, 120, 20)
    $Button4 = GUICtrlCreateButton("Shader 75", 10, 120, 120, 20)
    $Button5 = GUICtrlCreateButton("Shader 100", 10, 140, 120, 20)
    $Button6 = GUICtrlCreateButton("Pixel Check 10", 180, 60, 120, 20)
    $Button7 = GUICtrlCreateButton("Pixel Check 8", 180, 80, 120, 20)
    $Button8 = GUICtrlCreateButton("Pixel Check 6", 180, 100, 120, 20)
    $Button9 = GUICtrlCreateButton("Pixel Check 4", 180, 120, 120, 20)
    $Button10 = GUICtrlCreateButton("Pixel Check 2", 180, 140, 120, 20)
    $Button11 = GUICtrlCreateButton("Pixel Check 1", 180, 160, 120, 20)
    $Button12 = GUICtrlCreateButton("Mouse", 100, 210, 95, 20)
    $Button13 = GUICtrlCreateButton("Mouse Speed", 10, 160, 120, 20)
    $Button14 = GUICtrlCreateButton("Graph", 10, 180, 80, 20)
    $Button15 = GUICtrlCreateButton("CPU Save", 205, 180, 95, 20)
    $combo = GUICtrlCreateCombo("", 100, 190) ; create first item
    $data = GUICtrlSetData(-1, "Touchpad|Mouse Control|Game", "") 
    GUICtrlSetState($Button2, $GUI_CHECKED)

    GUISetState()      ; will display an  dialog box with 1 checkbox

    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
        Select
        Case $msg = $GUI_EVENT_CLOSE
            run("TSMC.exe")
                ExitLoop
            Case $msg = $Button1
                MsgBox(64, 'Info:', 'Shaders Changed!')
                IniWrite("settings.ini", "settings", "Shader", "1")
            Case $msg = $Button2
                MsgBox(64, 'Info:', 'Shaders Changed!')
                IniWrite("settings.ini", "settings", "Shader", "25")
            Case $msg = $Button3
                MsgBox(64, 'Info:', 'Shaders Changed!')
                IniWrite("settings.ini", "settings", "Shader", "50")
            Case $msg = $Button4
                MsgBox(64, 'Info:', 'Shaders Changed!')
                IniWrite("settings.ini", "settings", "Shader", "75")
            Case $msg = $Button5
                MsgBox(64, 'Info:', 'Shaders Changed!')
                IniWrite("settings.ini", "settings", "Shader", "100")
                Case $msg = $Button6
                MsgBox(64, 'Info:', 'Pixels Changed!')
                IniWrite("settings.ini", "settings", "Pixel", "10")
                Case $msg = $Button7
                MsgBox(64, 'Info:', 'Pixels Changed!')
                IniWrite("settings.ini", "settings", "Pixel", "8")
                Case $msg = $Button8
                MsgBox(64, 'Info:', 'Pixels Changed!')
                IniWrite("settings.ini", "settings", "Pixel", "6")
                Case $msg = $Button9
                MsgBox(64, 'Info:', 'Pixels Changed!')
                IniWrite("settings.ini", "settings", "Pixel", "4")
                Case $msg = $Button10
                MsgBox(64, 'Info:', 'Pixels Changed!')
                IniWrite("settings.ini", "settings", "Pixel", "2")
                Case $msg = $Button11
                MsgBox(64, 'Info:', 'Pixels Changed!')
                IniWrite("settings.ini", "settings", "Pixel", "1")
                Case $msg = $Button12
                $read = GUICtrlRead($combo)
                MsgBox(64, 'Info:', 'Mouse Set to ' & $read)
                if $read = "Mouse Control" Then IniWrite("settings.ini", "settings", "Mod", "Control")
                if $read = "Game" Then IniWrite("settings.ini", "settings", "Mod", "Game")
                if $read = "Touchpad" Then IniWrite("settings.ini", "settings", "Mod", "Touchpad")
                Case $msg = $Button13
                    $speed = InputBox("Mouse Speed", "Enter the speed of the mouse to be controlled")
                    IniWrite("settings.ini", "settings", "Speed", $speed)
                Case $msg = $Button14
                    $read = IniRead("settings.ini", "settings", "Graph", "Error with settings.ini")
                    if $read = "ON" then IniWrite("settings.ini", "settings", "Graph", "OFF")
                    if $read = "ON" then MsgBox(0, "Graphics", "Graphics has been changed to OFF")
                    if $read = "OFF" then IniWrite("settings.ini", "settings", "Graph", "ON")
                    if $read = "OFF" then MsgBox(0, "Graphics", "Graphics has been changed to On")
                Case $msg = $Button15
                    $read = IniRead("settings.ini", "settings", "CPU", "Error with settings.ini")
                    if $read = "ON" then IniWrite("settings.ini", "settings", "CPU", "OFF")
                    if $read = "ON" then MsgBox(0, "CPU SPEED", "CPU SAVE has been changed to OFF")
                    if $read = "OFF" then IniWrite("settings.ini", "settings", "CPU", "ON")
                    if $read = "OFF" then MsgBox(0, "CPU SPEED", "CPU SAVE has been changed to On")
        EndSelect
    WEnd
EndFunc   ;==>Example

You must download and compile settings.au3 for the script to run 100%

Original post: Xtreme developers

project.rar

Edited by Zibit
Link to comment
Share on other sites

Wow! This is a good job! I'm just having a bit of slight performance problems but I don't blame you. AutoIt isn't really optimized for performance lol

I see this as a first step in computer vision for autoit.

Are you interested in making a face recognition or object recognition script? This would be incredible!

EDIT: By the way, what does the update.exe and after.exe contain? I commented them out from the script since I do not know what they do exactly. I'm paranoid like that so bear with me. :mellow:

Edited by DJKMan

 

 

Link to comment
Share on other sites

Yes, i have a face logon script that checks your face lines but it's not very effective, it takes a picture of you and compares it to the lock picture. and about that update.exe :mellow: i shared it with my friends and every time i update it i wouldnt have to send it :P

Face Logon:

well it doesnt check your pictures it checks the size of the picture's and compares the relativity.

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#include <GDIPlus.au3>
#include <ScreenCapture.au3>
#NoTrayIcon
Global $Area
Global $Paused
Global $DISPSIZE
Opt("TrayMenuMode", 1)
$dll = DllOpen("user32.dll")
HotKeySet("{ESC}", "Terminate")
HotKeySet("{TAB}", "TogglePause")
TrayTip("WARNING!", "This Is for testing purposes unly!", 0, 5)
$white = False
$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



const $a = 110*4
const $c = 131*4
const $qn =(1000/4)



#include <GUIConstants.au3>
$avi = DllOpen("avicap32.dll")
$user = DllOpen("user32.dll")



; Load Camera
$Main = GUICreate("TSMC", 250, 210, 0, -23, $WS_DLGFRAME, $WS_EX_TOPMOST)
$cap = DllCall($avi, "int", "capCreateCaptureWindow", "str", "cap", "int", BitOR($WS_CHILD,$WS_VISIBLE), "int", 0, "int", 0, "int", 246, "int", 200, "hwnd", $Main, "int", 1)
$track1 = TrayCreateItem ("Set Logon Face")
$settings = TrayCreateItem ("Settings")
$START = TrayCreateItem ("Lock")
$Quit = TrayCreateItem ("Quit")
$ABOUT = TrayCreateItem ("About")
$red = False
AutoItSetOption ( "MouseCoordMode" ,0)
AutoItSetOption ( "PixelCoordMode" ,0)

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)

TraySetState ()
; Setup
_GDIPlus_Startup ()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND ($Main)
$hPen = _GDIPlus_PenCreate ()
Do
        _GDIPlus_GraphicsDrawLine ($hGraphic, 110, 90, 140, 90, $hPen)
        _GDIPlus_GraphicsDrawLine ($hGraphic, 110, 120, 140, 120, $hPen)
        _GDIPlus_GraphicsDrawLine ($hGraphic, 110, 90, 110, 120, $hPen)
        _GDIPlus_GraphicsDrawLine ($hGraphic, 140, 90, 140, 120, $hPen)
    $msg = TrayGetMsg()
    if $msg = $track1 then
        _ScreenCapture_Capture(@ScriptDir & "\data\position1.jpg", 110, 90, 140, 120, 0)
        TrayTip("", "Done!", 0, 1)
        sleep(1000)
        endif
         if $msg = $START then
        TrayTip("", "Locking PC", 0, 1)
        $pic1 = FileGetSize(@ScriptDir & "\data\position1.jpg")
        $input = InputBox("Relativity ?", "How Secure do you want this ? ( smaller the more secure )", "100")
        $relat1 = $input
        $relat2 = Number($input-$input-$input)
        BlockInput(1)
        while 1
        _GDIPlus_GraphicsDrawLine ($hGraphic, 110, 90, 140, 90, $hPen)
        _GDIPlus_GraphicsDrawLine ($hGraphic, 110, 120, 140, 120, $hPen)
        _GDIPlus_GraphicsDrawLine ($hGraphic, 110, 90, 110, 120, $hPen)
        _GDIPlus_GraphicsDrawLine ($hGraphic, 140, 90, 140, 120, $hPen)
        sleep(1000)
        _ScreenCapture_Capture(@ScriptDir & "\data\confirm1.jpg", 110, 90, 140, 120, 0)
        $confirm1 = FileGetSize(@ScriptDir & "\data\confirm1.jpg")
        FileDelete(@ScriptDir & "\data\confirm1.jpg")
        if Number($confirm1-$pic1) < $relat1 and Number($confirm1-$pic1) > $relat2 then
            TrayTip("Confirmed!", "Welcome Back!", 2, 0)
            sleep(1000)
            BlockInput(0)
            ConsoleWrite($pic1 & " - " & $confirm1 & @CRLF)
            exit
            endif
        wend
    endif
    if $msg = $ABOUT then
MsgBox ( 0, "About", "TheSync all rights reserrved!")
    endif
    if $msg = $settings then
    Run("settings.exe")
    exit
    endif
    if $msg = $Quit then
Terminate()
    endif
Until $msg = $START
WinSetOnTop("Camera", "", 1)
GUICtrlDelete ( $START )
GUICtrlDelete ( $Quit )
GUICtrlDelete ( $ABOUT)
GUICtrlDelete ( $whitebtn )
GUICtrlDelete ( $track1 )
GUISetState()

While 1


WEnd



; ----------- Pause and Exit-----------------------
Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Mouse Control is Paused',0,0)
    WEnd
    ToolTip("")
EndFunc
Func Terminate()
       
       ;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 0
EndFunc
Edited by Zibit
Link to comment
Share on other sites

Wow! Thanks for sharing. :mellow:

Unfortunately, I couldn't get the script to recognize me or fail to recognize me. I tried setting my logon face and then covering the camera to make it deny access but it still says welcome back. What am I doing wrong?

EDIT: I've also noticed that the settings still refers to the TSMC settings. I put all your script in one folder. Is it supposed to do that or is it a different settings file?

Edited by DJKMan

 

 

Link to comment
Share on other sites

  • 2 years later...

i think i understand the problem with the face logon (the same as mouse control script) it can't get data from webcam (shows black)

or atleast i can't get it to read data from the webcam

$cap = DllCall($avi, "int", "capCreateCaptureWindow", "str", "cap", "int", BitOR($WS_CHILD,$WS_VISIBLE), "int", 0, "int", 0, "int", 146, "int", 109, "hwnd", $Main, "int", 1)

is this line supposed to read data from the camera?

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...