reese646 Posted December 31, 2013 Posted December 31, 2013 Hi there, completely new to coding, and trying to solve a problem and this seems the best solution. I want a sound to go off if a region on the pc screen changes in any way, this I have achieved with a simple pixelchecksum, and i have the sound playing, the problem is that currently as you'll see the script once activated makes a sound then ends, I want the script to start again after one second. I tried just removing the exitloop but all that happened was that it the region changed from its original state it would sound the alarm every second infinitely. What I want is for the script to check the region, if theres no change reset and restart after one second, if there is a change sound the alarm, wait one second do a fresh check of the region so it takes into account the change and then monitors for another change. I tried a while loop but my code was wrong and I'm unsure if this would cure it, and a continueloop doesn't fit my need from the documentation, its a very small script so hopefully someone could help. $checksum = PixelChecksum(2000, 500, 2300, 800) While 1 If PixelChecksum(2000, 500, 2300, 800) <> $checksum Then SoundPlay(@WindowsDir & "\Media\notify.wav", 1) ExitLoop EndIf Sleep(100) WEnd many many thanks
water Posted December 31, 2013 Posted December 31, 2013 Welcome to AutoIt and the forum! Can you please describe what you try to achieve? Most of the time there are more reliable and easier ways to do what you want. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
reese646 Posted December 31, 2013 Author Posted December 31, 2013 Hi I'm basically trying to do exactly what I've said, I have a 3 screen system and am using a message software that is a pain when it comes to notifications but when turned off i get no notifications, I literally want to select the region where my contact list is and get a sensible noise whenever someone logs on or off, it has to be discrete as not to disturb me while working basically and on looking something like this seemed the simple solution
Moderators Melba23 Posted December 31, 2013 Moderators Posted December 31, 2013 reese646,You need to reset the value against which you are checking: ; Provide a way to exit HotKeySet("{ESC}", "On_Exit") ; Get an initial checksum $nCurr_Checksum = PixelChecksum(0, 0, 400, 400) ; Start the loop While 1 ; Get a new checksum $nNew_Checksum = PixelChecksum(0, 0, 400, 400) ; See if the area has changed If $nNew_Checksum <> $nCurr_Checksum Then ; If so then notify ;SoundPlay(@WindowsDir & "\Media\notify.wav", 1) ConsoleWrite("!Changed" & @CRLF) ; And reset the checksum to check against next time round $nCurr_Checksum = $nNew_Checksum EndIf ; Wait 1 sec and do it all again Sleep(1000) WEnd Func On_Exit() Exit EndFuncThat works well when I test it. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
reese646 Posted December 31, 2013 Author Posted December 31, 2013 you beat me to one my next question which was is this the right way to add an exit key HotKeySet( " {+}" , "Exit") $checksum = PixelChecksum(2000, 500, 2300, 800) While 1 If PixelChecksum(2000, 500, 2300, 800) <> $checksum Then SoundPlay(@WindowsDir & "\Media\notify.wav", 1) ExitLoop EndIf Sleep(100) WEnd Func Exit() Exit EndFunc Your code is beyond my current understanding I'll be honest but I get the general idea, I'll have a quick look at it and get straight back, thanks for the really prompt help too
Moderators Melba23 Posted December 31, 2013 Moderators Posted December 31, 2013 reese646,Please do ask if you have any questions. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
reese646 Posted December 31, 2013 Author Posted December 31, 2013 thats seems to be great, didn't work at first and had me checking all my sound settings the ; on line 14 needed removing to enable the sound it would seem. is there any way to change the response time of the sound upon change, make it faster or slower, would you just change the sleep variable? many thanks again as this is pretty much there as far as what I need
Moderators Melba23 Posted December 31, 2013 Moderators Posted December 31, 2013 reese646,Are you intending to use AutoIt in the future? If so, then as you are obviously a complete beginner (and no problem there as we all were at one point) reading the Help file (at least the first few sections - Using AutoIt, Tutorials and the first couple of References) will help you enormously. You should also look at this excellent tutorial - you will find other tutorials in the Wiki (the link is at the top of the page). As to the response time question. The Sleep command just waits for a second before the next comparison. If you want to adjust that period then all you need to do is to change the value (it is in msec). If you want to delay the sound once a change is detected, then you will need to add a Sleep line after the If $nNew_Checksum <> $nCurr_Checksum Then line - that will delay the sound after a change is detected. Does that answer the question? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Solution reese646 Posted December 31, 2013 Author Solution Posted December 31, 2013 yes that does perfectly, I am intrigued by this simple script to see what can actually be achieved, it seems like its quite a powerful tool, though as said my coding skills are limited to basic html, a little php and some sql. will have a look at the tutorials definitely. Have edited the script now, leaving in every comment added by the main contributor, this works perfectly and has been edited as to use the + key exit, and has a slightly quicker response time. ; Provide a way to exit HotKeySet("{+}", "On_Exit") ;uses the + key to exit the program ; Get an initial checksum $nCurr_Checksum = PixelChecksum(0, 0, 400, 400);alter this region to the region requiring monitoring ; Start the loop While 1 ; Get a new checksum $nNew_Checksum = PixelChecksum(0, 0, 400, 400) ;alter this to match the PixelCheckSum above ; See if the area has changed If $nNew_Checksum <> $nCurr_Checksum Then ; If so then notify SoundPlay(@WindowsDir & "\Media\notify.wav", 1) ;\media\notify.wav can be changed to any other audible file ConsoleWrite("!Changed" & @CRLF) ; And reset the checksum to check against next time round $nCurr_Checksum = $nNew_Checksum EndIf ; Wait 1 sec and do it all again Sleep(400) ;in milliseconds altering this changes how quickly the script refreshes WEnd Func On_Exit() Exit EndFunc I think this makes sense to the more experienced as I thought I'd explain my bits also so anyone else can use this as its really really handy and amazingly simple, I'm chuffed to bits with it and if anything I've put is wrong in the code (which is quite possible ) please edit it
Moderators Melba23 Posted December 31, 2013 Moderators Posted December 31, 2013 reese646,Open the AutoIt Window Info tool (Your_Install_PathAutoIt3Au3Info.exe) and select the last but one tab (Mouse). When you now drag the "gunsight" to a point, the coordinates are shown. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
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