Jump to content

need help, new, restarting a script or looping it


reese646
 Share

Go to solution Solved by reese646,

Recommended Posts

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

Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • Moderators

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
EndFunc
That works well when I test it. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • Moderators

reese646,

Please do ask if you have any questions. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • Moderators

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? :huh:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Solution

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 

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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