DynamicRookie Posted January 4, 2018 Posted January 4, 2018 Hi. I've been developing a Security Camera Toolkit I want it to play a sound when movement is detected, and when NoCameraMovement function is called, save mouse position, and move the mouse constantly back to his main position so camera doesnt move ("Because it constantly moves left/right to check the area, but the only way to stop the movement is moving your mouse constantly to the center") and both of the functions are not working What's wrong with my script? expandcollapse popup#include <GUIConstantsEx.au3> HotKeySet("{f1}", "_Check_For_Movement") HotKeySet("{v}", "NoCameraMovement") HotKeySet("{f2}", "_sleep") Opt('MustDeclareVars', 1) Local $_MS_POS = 0 MainGUI() Func MainGUI() Local $Button1, $Button2, $msg GUICreate("Sec_Camera_Tool") Opt("GUICoordMode", 2) $Button1 = GUICtrlCreateButton("MS_Check", 10, 30, 100) $Button2 = GUICtrlCreateButton("RC_Tool", 0, -1) GUISetState() ; Run the GUI until the window is closed While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button1 call ("_Check_For_Movement") Case $msg = $Button2 call ("NoCameraMovement") EndSelect WEnd EndFunc Func _Check_For_Movement() While 1 Local $MovementCheck = PixelChecksum ( 0, 0, 1279, 1023, 1) $MovementCheck = PixelChecksum ( 0, 0, 1279, 1023, 1) If IsArray($MovementCheck) = True Then SoundPlay("beep.mp3") EndIf WEnd EndFunc Func NoCameraMovement() while 1 $_MS_POS = MouseGetPos() MouseMove($_MS_POS[0], $_MS_POS[1], 5) WEnd EndFunc func _sleep() while 1 sleep(1000) WEnd EndFunc Any help is appreciated
benners Posted January 4, 2018 Posted January 4, 2018 A few things seem wrong Not a problem that would stop the script from running but don't declare functions in a loop I'm not sure if a while loop automatically sleeps but I always add a sleep to stop the CPU being hammered PixelChecksum doesn't return an array (think it's a double) so the sound will never play Once any of the functions with a while loop (except main) run it will block the controls on the gui so the buttons won't work, only the HotKeys will interrupt them. If you press a Hotkey again it will start another instance of the function which may already be running just interrupted. With the NoCameraMovement function, the function is just going to move the mouse to where it already is so it only seems it's not working. I had a play and tried to use Adlib functions instead of the while loops. Don't know if this is any use . The console writes are just to show things are running and stopping, they're not needed for the script. To test the movement, I ran the Check_For_Movement function and moved an open window into the area and the sound played It could probably be improved but try this expandcollapse popup#include <GUIConstantsEx.au3> HotKeySet("{f1}", "Start_CheckForMovement") HotKeySet("{v}", "Start_NoCameraMovement") HotKeySet("{f2}", "Start_PauseScript") Opt('MustDeclareVars', 1) Global _ $g_sRunningFunc = '' ; keep track of the running adlib function Global _ $g_iMouseX = 500, _ ;_ mouse main X postion $g_iMouseY = 500, _ ;_ mouse main Y position $g_iPixelChecksum = PixelChecksum(0, 0, 1279, 1023, 1) MainGUI() Func MainGUI() Local $Button1, $Button2, $msg GUICreate("Sec_Camera_Tool") Opt("GUICoordMode", 2) $Button1 = GUICtrlCreateButton("MS_Check", 10, 30, 100) $Button2 = GUICtrlCreateButton("RC_Tool", 0, -1) GUISetState() ; Run the GUI until the window is closed While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button1 Start_CheckForMovement() Case $msg = $Button2 Start_NoCameraMovement() EndSelect WEnd StopAdlib() ; stop polling EndFunc ;==>MainGUI Func Start_CheckForMovement() StopAdlib() ;_ stop previous polling $g_sRunningFunc = 'Check_For_Movement' ;_ update the variable AdlibRegister($g_sRunningFunc) ;_ start polling every second EndFunc ;==>Start_CheckForMovement Func Check_For_Movement() ConsoleWrite($g_sRunningFunc & @CRLF) If PixelChecksum(0, 0, 1279, 1023, 1) <> $g_iPixelChecksum Then SoundPlay('C:\Windows\Media\Windows Notify.wav', 1) EndFunc ;==>Check_For_Movement Func Start_PauseScript() StopAdlib() ;_ stop previous polling $g_sRunningFunc = 'PauseScript' ;_ update the variable AdlibRegister($g_sRunningFunc, 1000) ;_ start polling every second EndFunc ;==>Start_PauseScript Func PauseScript() ConsoleWrite($g_sRunningFunc & @CRLF) EndFunc ;==>PauseScript Func Start_NoCameraMovement() StopAdlib() ;_ stop previous polling $g_sRunningFunc = 'NoCameraMovement' ;_ update the variable AdlibRegister($g_sRunningFunc) ;_ start polling every second EndFunc ;==>Start_NoCameraMovement Func NoCameraMovement() ; you'll have to esc this when it's running to close the GUI ConsoleWrite($g_sRunningFunc & @CRLF) Local $ai_Pos = MouseGetPos() If $ai_Pos[0] <> $g_iMouseX Or $ai_Pos[1] <> $g_iMouseY Then MouseMove($g_iMouseX, $g_iMouseY, 5) EndFunc ;==>NoCameraMovement Func StopAdlib($s_Func = $g_sRunningFunc) If Not $s_Func Then Return ConsoleWrite('stopping ' & $s_Func & @CRLF) AdlibUnRegister($s_Func) $g_sRunningFunc = '' ; clear the running function EndFunc ;==>StopAdlib
DynamicRookie Posted January 5, 2018 Author Posted January 5, 2018 13 hours ago, benners said: expandcollapse popup#include <GUIConstantsEx.au3> HotKeySet("{f1}", "Start_CheckForMovement") HotKeySet("{v}", "Start_NoCameraMovement") HotKeySet("{f2}", "Start_PauseScript") Opt('MustDeclareVars', 1) Global _ $g_sRunningFunc = '' ; keep track of the running adlib function Global _ $g_iMouseX = 500, _ ;_ mouse main X postion $g_iMouseY = 500, _ ;_ mouse main Y position $g_iPixelChecksum = PixelChecksum(0, 0, 1279, 1023, 1) MainGUI() Func MainGUI() Local $Button1, $Button2, $msg GUICreate("Sec_Camera_Tool") Opt("GUICoordMode", 2) $Button1 = GUICtrlCreateButton("MS_Check", 10, 30, 100) $Button2 = GUICtrlCreateButton("RC_Tool", 0, -1) GUISetState() ; Run the GUI until the window is closed While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button1 Start_CheckForMovement() Case $msg = $Button2 Start_NoCameraMovement() EndSelect WEnd StopAdlib() ; stop polling EndFunc ;==>MainGUI Func Start_CheckForMovement() StopAdlib() ;_ stop previous polling $g_sRunningFunc = 'Check_For_Movement' ;_ update the variable AdlibRegister($g_sRunningFunc) ;_ start polling every second EndFunc ;==>Start_CheckForMovement Func Check_For_Movement() ConsoleWrite($g_sRunningFunc & @CRLF) If PixelChecksum(0, 0, 1279, 1023, 1) <> $g_iPixelChecksum Then SoundPlay('C:\Windows\Media\Windows Notify.wav', 1) EndFunc ;==>Check_For_Movement Func Start_PauseScript() StopAdlib() ;_ stop previous polling $g_sRunningFunc = 'PauseScript' ;_ update the variable AdlibRegister($g_sRunningFunc, 1000) ;_ start polling every second EndFunc ;==>Start_PauseScript Func PauseScript() ConsoleWrite($g_sRunningFunc & @CRLF) EndFunc ;==>PauseScript Func Start_NoCameraMovement() StopAdlib() ;_ stop previous polling $g_sRunningFunc = 'NoCameraMovement' ;_ update the variable AdlibRegister($g_sRunningFunc) ;_ start polling every second EndFunc ;==>Start_NoCameraMovement Func NoCameraMovement() ; you'll have to esc this when it's running to close the GUI ConsoleWrite($g_sRunningFunc & @CRLF) Local $ai_Pos = MouseGetPos() If $ai_Pos[0] <> $g_iMouseX Or $ai_Pos[1] <> $g_iMouseY Then MouseMove($g_iMouseX, $g_iMouseY, 5) EndFunc ;==>NoCameraMovement Func StopAdlib($s_Func = $g_sRunningFunc) If Not $s_Func Then Return ConsoleWrite('stopping ' & $s_Func & @CRLF) AdlibUnRegister($s_Func) $g_sRunningFunc = '' ; clear the running function EndFunc ;==>StopAdlib Line7 : ("directory") Global $g_sRunningFunc Global ^Error Error: Unable To Parse Line I used the same code but it somehow gives me that error.
benners Posted January 5, 2018 Posted January 5, 2018 It runs and checks (Ctrl + F5) ok on mine. below is the SciTE output. I use the full SciTE install package and the latest AutoIt releases if that makes any difference. Googling the error doesn't yield any similar issues. Try putting the Global calls on one line like Global $g_sRunningFunc = ''" and see if that helps. >"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /Prod /AU3check /in "D:\New AutoIt v3 Script.au3" +>11:30:28 Starting AutoIt3Wrapper v.17.224.935.0 SciTE v.3.7.3.0 Keyboard:00000809 OS:WIN_7/Service Pack 1 CPU:X64 OS:X64 Environment(Language:0409) CodePage:0 utf8.auto.check:4 +> SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE UserDir => C:\Users\Benners\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper SCITE_USERHOME => C:\Users\Benners\AppData\Local\AutoIt v3\SciTE >Running AU3Check (3.3.14.2) from:C:\Program Files (x86)\AutoIt3 input:D:\New AutoIt v3 Script.au3 +>11:30:28 AU3Check ended.rc:0 +>11:30:28 AutoIt3Wrapper Finished. >Exit code: 0 Time: 0.487
DynamicRookie Posted January 5, 2018 Author Posted January 5, 2018 (edited) 5 hours ago, benners said: It runs and checks (Ctrl + F5) ok on mine. below is the SciTE output. I use the full SciTE install package and the latest AutoIt releases if that makes any difference. Googling the error doesn't yield any similar issues. Try putting the Global calls on one line like Global $g_sRunningFunc = ''" and see if that helps. >"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /Prod /AU3check /in "D:\New AutoIt v3 Script.au3" +>11:30:28 Starting AutoIt3Wrapper v.17.224.935.0 SciTE v.3.7.3.0 Keyboard:00000809 OS:WIN_7/Service Pack 1 CPU:X64 OS:X64 Environment(Language:0409) CodePage:0 utf8.auto.check:4 +> SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE UserDir => C:\Users\Benners\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper SCITE_USERHOME => C:\Users\Benners\AppData\Local\AutoIt v3\SciTE >Running AU3Check (3.3.14.2) from:C:\Program Files (x86)\AutoIt3 input:D:\New AutoIt v3 Script.au3 +>11:30:28 AU3Check ended.rc:0 +>11:30:28 AutoIt3Wrapper Finished. >Exit code: 0 Time: 0.487 Hi benners Thanks so much for helping me in this script, it is really necessary for my job, but.. It keeps giving me errors, may you give me information about which AutoIt version u using, Maybe that's why it's not working Error console information Line 8 (File "C:/*directory*/test.au3) Global $g_iMouseX = 500, Global $g_iMouseY=500, Global $g_iPixelCheckSum = PixelCheckSum(0,0,1279,1023,1) Global $g_iMouseX = 500, Global^ ERROR Error: Missing separator character after keyword Used the same code, but putted global in the same line: expandcollapse popup#include <GUIConstantsEx.au3> HotKeySet("{f1}", "Start_CheckForMovement") HotKeySet("{v}", "Start_NoCameraMovement") HotKeySet("{f2}", "Start_PauseScript") Opt('MustDeclareVars', 1) Global $g_sRunningFunc = '' ; keep track of the running adlib function Global $g_iMouseX = 500, _ ;_ mouse main X postion Global $g_iMouseY = 500, _ ;_ mouse main Y position Global $g_iPixelChecksum = PixelChecksum(0, 0, 1279, 1023, 1) MainGUI() Func MainGUI() Local $Button1, $Button2, $msg GUICreate("Sec_Camera_Tool") Opt("GUICoordMode", 2) $Button1 = GUICtrlCreateButton("MS_Check", 10, 30, 100) $Button2 = GUICtrlCreateButton("RC_Tool", 0, -1) GUISetState() ; Run the GUI until the window is closed While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button1 Start_CheckForMovement() Case $msg = $Button2 Start_NoCameraMovement() EndSelect WEnd StopAdlib() ; stop polling EndFunc ;==>MainGUI Func Start_CheckForMovement() StopAdlib() ;_ stop previous polling $g_sRunningFunc = 'Check_For_Movement' ;_ update the variable AdlibRegister($g_sRunningFunc) ;_ start polling every second EndFunc ;==>Start_CheckForMovement Func Check_For_Movement() ConsoleWrite($g_sRunningFunc & @CRLF) If PixelChecksum(0, 0, 1279, 1023, 1) <> $g_iPixelChecksum Then SoundPlay('C:\Windows\Media\Windows Notify.wav', 1) EndFunc ;==>Check_For_Movement Func Start_PauseScript() StopAdlib() ;_ stop previous polling $g_sRunningFunc = 'PauseScript' ;_ update the variable AdlibRegister($g_sRunningFunc, 1000) ;_ start polling every second EndFunc ;==>Start_PauseScript Func PauseScript() ConsoleWrite($g_sRunningFunc & @CRLF) EndFunc ;==>PauseScript Func Start_NoCameraMovement() StopAdlib() ;_ stop previous polling $g_sRunningFunc = 'NoCameraMovement' ;_ update the variable AdlibRegister($g_sRunningFunc) ;_ start polling every second EndFunc ;==>Start_NoCameraMovement Func NoCameraMovement() ; you'll have to esc this when it's running to close the GUI ConsoleWrite($g_sRunningFunc & @CRLF) Local $ai_Pos = MouseGetPos() If $ai_Pos[0] <> $g_iMouseX Or $ai_Pos[1] <> $g_iMouseY Then MouseMove($g_iMouseX, $g_iMouseY, 5) EndFunc ;==>NoCameraMovement Func StopAdlib($s_Func = $g_sRunningFunc) If Not $s_Func Then Return ConsoleWrite('stopping ' & $s_Func & @CRLF) AdlibUnRegister($s_Func) $g_sRunningFunc = '' ; clear the running function EndFunc ;==>StopAdlib Edited January 5, 2018 by DynamicRookie
benners Posted January 5, 2018 Posted January 5, 2018 The AutoIt version is 3.3.14.2. With the one line globals you will need to remove the ", _" characters from the end. The _ is a line break. Try Global $g_sRunningFunc = '' ; keep track of the running adlib function Global $g_iMouseX = 500 ;_ mouse main X postion Global $g_iMouseY = 500 ;_ mouse main Y position Global $g_iPixelChecksum = PixelChecksum(0, 0, 1279, 1023, 1)
DynamicRookie Posted January 5, 2018 Author Posted January 5, 2018 Just now, benners said: The AutoIt version is 3.3.14.2. With the one line globals you will need to remove the ", _" characters from the end. The _ is a line break. Try Global $g_sRunningFunc = '' ; keep track of the running adlib function Global $g_iMouseX = 500 ;_ mouse main X postion Global $g_iMouseY = 500 ;_ mouse main Y position Global $g_iPixelChecksum = PixelChecksum(0, 0, 1279, 1023, 1) Fixed! I dont know how to tell you how grateful i am for your help, really, but now it gives this error Line 16 (File "C:\*directory*\test.au3 Local $Button1, $Button2, $msg ^ERROR Unable to parse Line
benners Posted January 5, 2018 Posted January 5, 2018 Looks like for some reason the issue is with declaring multiple variables on one line. Never heard of that before. Swap the MainGUI func in the script for this one Func MainGUI() GUICreate("Sec_Camera_Tool") Opt("GUICoordMode", 2) Local $Button1 = GUICtrlCreateButton("MS_Check", 10, 30, 100) Local $Button2 = GUICtrlCreateButton("RC_Tool", 0, -1) GUISetState() ; Run the GUI until the window is closed While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Button1 Start_CheckForMovement() Case $Button2 Start_NoCameraMovement() EndSwitch WEnd StopAdlib() ; stop polling EndFunc ;==>MainGUI
DynamicRookie Posted January 5, 2018 Author Posted January 5, 2018 (edited) 10 minutes ago, benners said: Looks like for some reason the issue is with declaring multiple variables on one line. Never heard of that before. Swap the MainGUI func in the script for this one Func MainGUI() GUICreate("Sec_Camera_Tool") Opt("GUICoordMode", 2) Local $Button1 = GUICtrlCreateButton("MS_Check", 10, 30, 100) Local $Button2 = GUICtrlCreateButton("RC_Tool", 0, -1) GUISetState() ; Run the GUI until the window is closed While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Button1 Start_CheckForMovement() Case $Button2 Start_NoCameraMovement() EndSwitch WEnd StopAdlib() ; stop polling EndFunc ;==>MainGUI Thanks for your help, i know it may be annoying that my script never gets fixed, but i hope you wont leave me with the problem Now the MainGui issue is fixed, but it gives this error at this function Func Start_CheckForMovement() StopAdlib() ;_ stop previous polling $g_sRunningFunc = 'Check_For_Movement' ;_ update the variable AdlibRegister($g_sRunningFunc) ;_ start polling every second EndFunc ;==>Start_CheckForMovement At the 2nd line which in the full code is 40. It says Line 40 (File "C:\*directory*\test.au3") StopAdlib() ^ ERROR Error: Unable to parse line. Edited January 5, 2018 by DynamicRookie Bad typed error
BrewManNH Posted January 5, 2018 Posted January 5, 2018 The error message shows a space between Stop and Adlib. 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 GudeHow 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
benners Posted January 5, 2018 Posted January 5, 2018 (edited) Are you using the full SciTE editor package from here. If not download and try that. There seems far too many issues with compiling for something not to be a miss. Edited January 5, 2018 by benners
DynamicRookie Posted January 5, 2018 Author Posted January 5, 2018 Just now, BrewManNH said: The error message shows a space between Stop and Adlib. No, i missed it when typing it
DynamicRookie Posted January 5, 2018 Author Posted January 5, 2018 3 minutes ago, benners said: Are you using the full SciTE editor package from here. If not download and try that Installed, but it gives me the same error I hate my pc
benners Posted January 5, 2018 Posted January 5, 2018 I'm stumped as to the reason. You could try usiing Call to run the functions I have attached an exe compiled on my PC. If you feel safe running it you could try that SecCameraTool.7z
DynamicRookie Posted January 5, 2018 Author Posted January 5, 2018 1 minute ago, benners said: I'm stumped as to the reason. You could try usiing Call to run the functions I have attached an exe compiled on my PC. If you feel safe running it you could try that SecCameraTool.7z Runs good, but it detects movement where no movement is happening And RC_Check crashes the app
benners Posted January 5, 2018 Posted January 5, 2018 I'll have a look at the movement function. RC_Check should just keep moving the mouse to a default position. Does it move the mouse or crash?
DynamicRookie Posted January 5, 2018 Author Posted January 5, 2018 2 minutes ago, benners said: I'll have a look at the movement function. RC_Check should just keep moving the mouse to a default position. Does it move the mouse or crash? Just crashes. My objective is to capture the exact position of the mouse and if it gets moved to another place, move it back to the position it captured until you pause the script.
benners Posted January 5, 2018 Posted January 5, 2018 Try this one. I have changed the function calls to use Call. See if that helps with the compile. You need to find out why it is such a pain to compile a normal script. Also attached the exe. I put some labels on to compare the values of the PixelChecksums. Fingers crossed expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile=SecCameraTool.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <GUIConstantsEx.au3> HotKeySet("{f1}", "Start_CheckForMovement") HotKeySet("{f2}", "Start_PauseScript") HotKeySet("{v}", "Start_NoCameraMovement") Opt('MustDeclareVars', 1) Global $g_sRunningFunc = '' ; keep track of the running adlib function Global $g_iDefaultMouseX = 0 ;_ mouse main X postion Global $g_iDefaultMouseY = 0 ;_ mouse main Y position Global $g_iPixelChecksum = 0 Global $g_aiNewMousePos = '' ;_ array for the new mouse positions Global $g_idNewChecksum_lbl = 0 ;_ label for the new checksum value Global $g_idOldChecksum_lbl = 0 ;_ label for the default checksum value MainGUI() Func MainGUI() GUICreate("Sec_Camera_Tool", 400, 400) Local $id_MSCheck_btn = GUICtrlCreateButton("MS_Check", 32, 24, 75, 25) Local $id_RCTool_btn = GUICtrlCreateButton("RC_Tool", 128, 24, 75, 25) GUICtrlCreateLabel("New PixelCheckSum", 24, 80, 103, 17) GUICtrlCreateLabel("Old PixelCheckSum", 24, 112, 97, 17) $g_idNewChecksum_lbl = GUICtrlCreateLabel("Waiting...", 136, 80, 76, 17) $g_idOldChecksum_lbl = GUICtrlCreateLabel("Waiting...", 136, 112, 100, 17) GUISetState() ; Run the GUI until the window is closed While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $id_MSCheck_btn Start_CheckForMovement() Case $id_RCTool_btn Start_NoCameraMovement() EndSwitch WEnd Call('StopAdlib') ; stop polling EndFunc ;==>MainGUI Func Start_CheckForMovement() Call('StopAdlib') ; stop previous polling $g_iPixelChecksum = PixelChecksum(0, 0, 1279, 1023, 1) ; get the starting value for the screen area GUICtrlSetData($g_idOldChecksum_lbl, $g_iPixelChecksum) ; update the label $g_sRunningFunc = 'Check_For_Movement' ;_ update the variable AdlibRegister($g_sRunningFunc) ;_ start polling every second EndFunc ;==>Start_CheckForMovement Func Check_For_Movement() ;ConsoleWrite($g_sRunningFunc & @CRLF) If PixelChecksum(0, 0, 1279, 1023, 1) <> $g_iPixelChecksum Then SoundPlay('C:\Windows\Media\Windows Notify.wav', 1) GUICtrlSetData($g_idNewChecksum_lbl, PixelChecksum(0, 0, 1279, 1023, 1)) EndFunc ;==>Check_For_Movement Func Start_PauseScript() Call('StopAdlib') ; stop previous polling $g_sRunningFunc = 'PauseScript' ;_ update the variable AdlibRegister($g_sRunningFunc, 1000) ;_ start polling every second EndFunc ;==>Start_PauseScript Func PauseScript() ;~ ConsoleWrite($g_sRunningFunc & @CRLF) EndFunc ;==>PauseScript Func Start_NoCameraMovement() Call('StopAdlib') ; stop previous polling Local $ai_Pos = MouseGetPos() ;_ get the current mouse position $g_iDefaultMouseX = $ai_Pos[0] ;_ Update the global mouse position $g_iDefaultMouseY = $ai_Pos[1] ;_ Update the global mouse position $g_sRunningFunc = 'NoCameraMovement' ;_ update the variable AdlibRegister($g_sRunningFunc) ;_ start polling every second EndFunc ;==>Start_NoCameraMovement Func NoCameraMovement() ; you'll have to esc this when it's running to close the GUI ;ConsoleWrite($g_sRunningFunc & @CRLF) $g_aiNewMousePos = MouseGetPos() ; get the current mouse position If $g_aiNewMousePos[0] <> $g_iDefaultMouseX Or $g_aiNewMousePos[1] <> $g_iDefaultMouseY Then MouseMove($g_iDefaultMouseX, $g_iDefaultMouseY, 5) EndFunc ;==>NoCameraMovement Func StopAdlib($s_Func = $g_sRunningFunc) If Not $s_Func Then Return ;ConsoleWrite('stopping ' & $s_Func & @CRLF) AdlibUnRegister($s_Func) $g_sRunningFunc = '' ; clear the running function EndFunc ;==>StopAdlib SecCameraTool.7z
DynamicRookie Posted January 5, 2018 Author Posted January 5, 2018 3 minutes ago, benners said: Try this one. I have changed the function calls to use Call. See if that helps with the compile. You need to find out why it is such a pain to compile a normal script. Also attached the exe. I put some labels on to compare the values of the PixelChecksums. Fingers crossed expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile=SecCameraTool.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <GUIConstantsEx.au3> HotKeySet("{f1}", "Start_CheckForMovement") HotKeySet("{f2}", "Start_PauseScript") HotKeySet("{v}", "Start_NoCameraMovement") Opt('MustDeclareVars', 1) Global $g_sRunningFunc = '' ; keep track of the running adlib function Global $g_iDefaultMouseX = 0 ;_ mouse main X postion Global $g_iDefaultMouseY = 0 ;_ mouse main Y position Global $g_iPixelChecksum = 0 Global $g_aiNewMousePos = '' ;_ array for the new mouse positions Global $g_idNewChecksum_lbl = 0 ;_ label for the new checksum value Global $g_idOldChecksum_lbl = 0 ;_ label for the default checksum value MainGUI() Func MainGUI() GUICreate("Sec_Camera_Tool", 400, 400) Local $id_MSCheck_btn = GUICtrlCreateButton("MS_Check", 32, 24, 75, 25) Local $id_RCTool_btn = GUICtrlCreateButton("RC_Tool", 128, 24, 75, 25) GUICtrlCreateLabel("New PixelCheckSum", 24, 80, 103, 17) GUICtrlCreateLabel("Old PixelCheckSum", 24, 112, 97, 17) $g_idNewChecksum_lbl = GUICtrlCreateLabel("Waiting...", 136, 80, 76, 17) $g_idOldChecksum_lbl = GUICtrlCreateLabel("Waiting...", 136, 112, 100, 17) GUISetState() ; Run the GUI until the window is closed While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $id_MSCheck_btn Start_CheckForMovement() Case $id_RCTool_btn Start_NoCameraMovement() EndSwitch WEnd Call('StopAdlib') ; stop polling EndFunc ;==>MainGUI Func Start_CheckForMovement() Call('StopAdlib') ; stop previous polling $g_iPixelChecksum = PixelChecksum(0, 0, 1279, 1023, 1) ; get the starting value for the screen area GUICtrlSetData($g_idOldChecksum_lbl, $g_iPixelChecksum) ; update the label $g_sRunningFunc = 'Check_For_Movement' ;_ update the variable AdlibRegister($g_sRunningFunc) ;_ start polling every second EndFunc ;==>Start_CheckForMovement Func Check_For_Movement() ;ConsoleWrite($g_sRunningFunc & @CRLF) If PixelChecksum(0, 0, 1279, 1023, 1) <> $g_iPixelChecksum Then SoundPlay('C:\Windows\Media\Windows Notify.wav', 1) GUICtrlSetData($g_idNewChecksum_lbl, PixelChecksum(0, 0, 1279, 1023, 1)) EndFunc ;==>Check_For_Movement Func Start_PauseScript() Call('StopAdlib') ; stop previous polling $g_sRunningFunc = 'PauseScript' ;_ update the variable AdlibRegister($g_sRunningFunc, 1000) ;_ start polling every second EndFunc ;==>Start_PauseScript Func PauseScript() ;~ ConsoleWrite($g_sRunningFunc & @CRLF) EndFunc ;==>PauseScript Func Start_NoCameraMovement() Call('StopAdlib') ; stop previous polling Local $ai_Pos = MouseGetPos() ;_ get the current mouse position $g_iDefaultMouseX = $ai_Pos[0] ;_ Update the global mouse position $g_iDefaultMouseY = $ai_Pos[1] ;_ Update the global mouse position $g_sRunningFunc = 'NoCameraMovement' ;_ update the variable AdlibRegister($g_sRunningFunc) ;_ start polling every second EndFunc ;==>Start_NoCameraMovement Func NoCameraMovement() ; you'll have to esc this when it's running to close the GUI ;ConsoleWrite($g_sRunningFunc & @CRLF) $g_aiNewMousePos = MouseGetPos() ; get the current mouse position If $g_aiNewMousePos[0] <> $g_iDefaultMouseX Or $g_aiNewMousePos[1] <> $g_iDefaultMouseY Then MouseMove($g_iDefaultMouseX, $g_iDefaultMouseY, 5) EndFunc ;==>NoCameraMovement Func StopAdlib($s_Func = $g_sRunningFunc) If Not $s_Func Then Return ;ConsoleWrite('stopping ' & $s_Func & @CRLF) AdlibUnRegister($s_Func) $g_sRunningFunc = '' ; clear the running function EndFunc ;==>StopAdlib SecCameraTool.7z It can finally compile without errors, The RC Check is working just divine. Thanks a lot for your help The only error is that PixelCheckSum is always detecting something when nothing changed. And that's the only error. I dont know how to express how grateful i am for your help
benners Posted January 5, 2018 Posted January 5, 2018 Yay. No problem, That is what this forum is for. Still pissing me off about the PixelCheckSum. It doesnt take much to set it off, a colour change by highlighting some thing.? Before you run the press the MS_Check button move the gui to the right of your monitor. It could be the action of clicking the button if it is the scan area. Ask on the forum about the issues with SciTE and what we have discussed here. It's a headscratcher for me and you shouldn't need to use call to run the StopAdlib function
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now