Jump to content

Did you hear the beep?


Recommended Posts

I need to detect if the default beep was played by a program.

I'm working with this "Extra program" (looks like a DOS box) to check if an inmate is still in the building. When the inmate is no longer in the building "NO INMATE FOUND" appears in the box and a beep is played. AutoIt Window Info does not detect any of the text (visible or hidden) so, I can't use the text to make a list of people to clear from my patient roster.

Does anyone know how to check if a wav was played? The beep only plays if there is no match in the search.

Here is the code I have. It works fine for a few people, placing a MsgBox before WEnd, but I have to check over 9,000 people in the database.

CODE

;Set a hotkey combo for exit

HotKeySet("{ESC}", "MyExit")

#include <file.au3>

#include <GUIConstants.au3>

$Password = InputBox("Jail Daily Password", "Enter your daily password")

; Get the ID numbers from Sick Call List.txt

;Create arrays from the content of the file

$file = FileOpen(@DesktopDir & "\Sick Call List.txt", 0)

; Check if file opened for reading OK

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

WinActivate("Jail - EXTRA! Office Client")

WinWaitActive("Jail - EXTRA! Office Client")

; Read in lines of text until the EOF is reached

While 1

WinActivate("Jail - EXTRA! Office Client")

WinWaitActive("Jail - EXTRA! Office Client")

$line = FileReadLine($file)

If $line = "" Then ExitLoop ;Stop on empty line.

If @error = -1 Then ExitLoop

Send($Password)

Send($line)

Send("{ENTER}")

;if the inmate is not found there is a beep now. I want to write the $line element in notepad whenever there is a beep played.

WinWaitActive("Jail - EXTRA! Office Client")

WEnd

$destination = "c:\logo.bmp"

Sleep(100)

SplashImageOn("Script by JailDoctor", $destination, 150, 150)

Sleep(3000)

SplashOff()

Func MyExit()

Exit

EndFunc ;==>MyExit

Link to comment
Share on other sites

I'm trying this new things in red, but the status of the sound escapes the Function call even checking every 100 miliseconds.

Does anyone know how to check if a wav was played? The beep only plays if there is no match in the search.

CODE

;Set a hotkey combo for exit

HotKeySet("{ESC}", "MyExit")

#include <file.au3>

#include <GUIConstants.au3>

#include <Sound.au3>

$Password = InputBox("Jail Daily Password", "Enter your daily password")

Dim $mySound

Func MySound()

$sound = _SoundStatus (@WindowsDir & "\media\Windows XP Error.wav")

If $sound = "Playing" Then

$mySound = False

EndIf

EndFunc

AdlibEnable ("MySound",100)

; Get the ID numbers from Sick Call List.txt

;Create arrays from the content of the file

$file = FileOpen(@DesktopDir & "\Sick Call List.txt", 0)

; Check if file opened for reading OK

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

WinActivate("Jail - EXTRA! Office Client")

WinWaitActive("Jail - EXTRA! Office Client")

; Read in lines of text until the EOF is reached

While 1

$TheSound = True

WinActivate("Jail - EXTRA! Office Client")

WinWaitActive("Jail - EXTRA! Office Client")

$line = FileReadLine($file)

If $line = "" Then ExitLoop ;Stop on empty line.

If @error = -1 Then ExitLoop

Send($Password)

Send($line)

Send("{ENTER}")

Sleep (300)

If $TheSound = False Then

;~ MsgBox (64,"No Guy", $line & " ain't here.")

WinActivate("Untitled - Notepad")

WinWaitActive("Untitled - Notepad")

Send ($line & @LF)

WinActivate("CJIS - EXTRA! Office Client")

WinWaitActive("Jail - EXTRA! Office Client")

WEnd

$destination = "c:\logo.bmp"

Sleep(100)

SplashImageOn("Script by JailDoctor", $destination, 150, 150)

Sleep(3000)

SplashOff()

Func MyExit()

Exit

EndFunc ;==>MyExit

Edited by JailDoctor
Link to comment
Share on other sites

I'm trying this new things in red, but the status of the sound escapes the Function call even checking every 100 miliseconds.

I could be wrong, but I think _SoundStatus() only works with sounds invoked by _SoundPlay().

Are there any other changes that occur with the program interface with the beep is played?

Is there a colour change that occurs on part of the screen?

Or does the program write to a temp or log file in its folder or in the system's temp folder?

I think you really need to find some other cue to monitor rather than whether the sound is played.

Link to comment
Share on other sites

Are there any other changes that occur with the program interface with the beep is played?

Is there a colour change that occurs on part of the screen?

Or does the program write to a temp or log file in its folder or in the system's temp folder?

There are three temp files apparently created by the program interface. Two are 16 KB and one is just 1 KB. I don't know what they mean because when opened with Notepad it is just a bunch of characters.

When there is no match ---> NO INMATE RECORD FOUND is displayed at the top of the box on white letters over a black background. Next to the name field, in the middle of the box, it displays $$$ NO INMATE FOUND $$$, also in white letters. When there is a match, the display at the top is ---> ENTER DESIRED ACTION, also in white letters. But the Autoit Window Info tool doesn't show any visible or hidden text

The box frame color doesn't change, the only constant is the Windows XP error.wav beep whenever the person is not found.

I have no idea what to do with Temp files. Is there a way to use them to keep track of changing events?

Link to comment
Share on other sites

There are three temp files apparently created by the program interface. Two are 16 KB and one is just 1 KB. I don't know what they mean because when opened with Notepad it is just a bunch of characters.

When there is no match ---> NO INMATE RECORD FOUND is displayed at the top of the box on white letters over a black background. Next to the name field, in the middle of the box, it displays $$$ NO INMATE FOUND $$$, also in white letters. When there is a match, the display at the top is ---> ENTER DESIRED ACTION, also in white letters. But the Autoit Window Info tool doesn't show any visible or hidden text

The box frame color doesn't change, the only constant is the Windows XP error.wav beep whenever the person is not found.

I have no idea what to do with Temp files. Is there a way to use them to keep track of changing events?

It sounds like the temp files are binary so they probably won't be much help and may have nothing at all to do with the changes in status. The only way to know for sure would be to check them when "NO INMATE RECORD FOUND" occurs and compare them to their state at "ENTERED DESIRED ACTION". You'd also need to run other tasks within the program and compare the files for each of those to be sure any change you detected at "NO INMATE RECORD FOUND" is unique to that event. Probably would be a very frustrating exercise,

Your only two remaining choices as near as I can tell are either using MemoryRead functions to look for changes in the actual memory space of the program (sorry, I'm no expert there) or using something like Sysinternals "filemon" utility with a filter for checking if the error.wav file is actually accessed by your program. Of course one problem with the last approach: are you sure its the error.wav that's being played and not just a sound generated by the program that sounds like it?

To test, I would rename the error.wav file to error.old and copy another wav file (like tada.wav) to error.wav, run your program and see if the sound's changed. If it hasn't then it's not the windows sound that's being used.

Link to comment
Share on other sites

There are three temp files apparently created by the program interface. Two are 16 KB and one is just 1 KB. I don't know what they mean because when opened with Notepad it is just a bunch of characters.

When there is no match ---> NO INMATE RECORD FOUND is displayed at the top of the box on white letters over a black background. Next to the name field, in the middle of the box, it displays $$$ NO INMATE FOUND $$$, also in white letters. When there is a match, the display at the top is ---> ENTER DESIRED ACTION, also in white letters. But the Autoit Window Info tool doesn't show any visible or hidden text

The box frame color doesn't change, the only constant is the Windows XP error.wav beep whenever the person is not found.

I have no idea what to do with Temp files. Is there a way to use them to keep track of changing events?

Couple of questions here.

Is it really required to read the file in one line at a time? That is the slowest method to read a file. Try _FileReadToArray()

When you say "the top of the box" are you refering to the title bar or a control that is inside the window?

When you used the Info Tool, did you make sure to activate the window before trying to read the info?

Is there any reason that you can't access the database directly to get the required information?

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Couple of questions here.

Is it really required to read the file in one line at a time? That is the slowest method to read a file. Try _FileReadToArray()

When you say "the top of the box" are you refering to the title bar or a control that is inside the window?

When you used the Info Tool, did you make sure to activate the window before trying to read the info?

Is there any reason that you can't access the database directly to get the required information?

Geesh, there goes George again, trying to make things easy :)
Link to comment
Share on other sites

Geesh, there goes George again, trying to make things easy :)

Nah, just trying to get a few things straight in my befuddled brain before I start thinking about a solution.

Todays policy = Don't try to solve a problem when you don't have all the facts. Now if I stick to todays policy I might be okay.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Sysinternals "filemon" utility with a filter for checking if the error.wav file is actually accessed by your program. Of course one problem with the last approach: are you sure its the error.wav that's being played and not just a sound generated by the program that sounds like it?

To test, I would rename the error.wav file to error.old and copy another wav file (like tada.wav) to error.wav, run your program and see if the sound's changed. If it hasn't then it's not the windows sound that's being used.

Yes, I renamed the error.wav file to error.old and selected another wav file for the Asterik event in the sound scheme for Windows Logoff. I then ran the program and the sound changed to "dududu tada" (never could sing). That was a very good recommendation ResNullius, thanks. We now know it is the Windows XP error.wav file that sounds when the guy isn't found.

Yes GeoSoft I have access to the database, I just would have to enter manually 9,010 ID numbers and look at the screen each time to see (or listen for the Windows XP error.wav) if the guy is here or not. Then copy that number to another file to remove him/her from my medical roster. (Yes I will probably write a little routine to immediately remove them from the roster instead of making yet another file, provided I can pick up when the wav file is accessed.

The top of the box refers to a box similar to a DOS command prompt box. See the picture below

my_box.bmp

I used _FileReadToArray and couldn't enter the info into the box. It worked after I converted the array into a *.txt file and read each line once at a time.

Perhaps I should re-visit that option one more time.

I goggled filemon and found out it was replaced just last week by Process Monitor v1.35 by the same authors, Mark Russinovich and Bryce Cogswell. Thanks again ResNullius. It seems like a promising utility for this dilemma.

I've never used this utility so I will read it and see how to use it to check for access to my wav file and then let AutoIt know the event occurred and have Autoit handle the patient's ID number.

Link to comment
Share on other sites

Yes GeoSoft I have access to the database, I just would have to enter manually 9,010 ID numbers and look at the screen each time to see (or listen for the Windows XP error.wav) if the guy is here or not. Then copy that number to another file to remove him/her from my medical roster. (Yes I will probably write a little routine to immediately remove them from the roster instead of making yet another file, provided I can pick up when the wav file is accessed.

I think what George was refering to (and I know he'll correct me if I'm wrong) was if the database can be accessed via AutoIt, you should be able to do the whole thing programmatically, without having AutoIt have to send to the window of your program. That is, the list of IDs can be read by your script, your script can check the database for a match, and if not found, log it or alert you.
Link to comment
Share on other sites

if the database can be accessed via AutoIt, you should be able to do the whole thing programmatically, without having AutoIt have to send to the window of your program. That is, the list of IDs can be read by your script, your script can check the database for a match, and if not found, log it or alert you.

The only way to search the database (if it is a database, this is apparently a "mainframe" thingy that probably was created before windows 3, remember those days?) is to enter my password each and every time, then the id number and then I get the info I am looking for. I can not write any information into it.

Looking at the pull down menus it seems there is a possibility to write scripts in the "Extra" application. But it is beyond me how to do it. I haven't even experimented with it.

if the database can be accessed via AutoIt,

Do you mean in another form than automating the usual commands? Like, password, id number, enter, view result, capture result and send it to an array?
Link to comment
Share on other sites

The only way to search the database (if it is a database, this is apparently a "mainframe" thingy that probably was created before windows 3, remember those days?) is to enter my password each and every time, then the id number and then I get the info I am looking for. I can not write any information into it.

Looking at the pull down menus it seems there is a possibility to write scripts in the "Extra" application. But it is beyond me how to do it. I haven't even experimented with it.

Do you mean in another form than automating the usual commands? Like, password, id number, enter, view result, capture result and send it to an array?

I mean opening the database directly through something like an ODBC connection.

Then AutoIt can read the info directly from the database without going through the "Extra" application.

Using ODBC and ADO, autoit can talk to a number of different databases, even ones created before "windows 3" days.

If you can find out the extension of the database files, that might give us something to go on. I know dbf files were quite common in those days, but their were quite a few others and some proprietary formats as well.

Link to comment
Share on other sites

While it would still be best if you can access the database directly, I found another possible solution!

Download kangkeng's excellent ImageSearch UDF & dll from here:

http://www.autoitscript.com/forum/index.ph...st&p=488195

Make a screen capture of the Extra program when the "---> NO INMATE RECORD FOUND" screen appears (like the "my_box.bmp" you posted earlier)

Cut the "---> NO INMATE RECORD FOUND" portion of the image and save that portion as "noInmate.bmp".

Close your Extra program, run the following script, start the Extra program, and then force a "NO INMATE FOUND" situation.

#include <ImageSearch.au3>

AdlibEnable("_NoInmate", 100)

While 1
    Sleep(10)
WEnd

Func _NoInmate()
    $x1 = 0
    $y1 = 0

    $result = _ImageSearch("noInmate.bmp", 0, $x1, $y1, 0)

    If $result = 1 Then
        MouseMove($x1, $y1, 3)
        MsgBox(0, "No Inmate Found", "No Inmate Found")
;Else
;   MsgBox(0,"Inmate Found","Inmate Found")
    EndIf

EndFunc;==>_NoInmate

I tested this by displaying your my_box.bmp in a graphics viewer and it worked great.

Notes: Despite the documentation included with the ImageSearch UDF, the dll doesn't need to be in the windows directory, it can just be in your script dir.

Important: The image portion you save as noInmate.bmp must be taken from the same size Extra screen as you will be monitoring. If you resize the Extra program after the image portion is saved and your script is started, or if you save the portion in a differen size than 100%, the search will fail.

Edit: Of course you could put the ImageSearch directly into your processing loop as opposed to an AdLib.

Edited by ResNullius
Link to comment
Share on other sites

Ok, so I ran into a deadline. I'm on vacation since the 4th until the Monday after tomorrow.

I went in a not very elegant way but it did the job.

I found I can move the cursor and select the $$$ signs. Assign the selection to a variable and if the variable contains any character other than a dollar sign, it means the inmate is still jailed. If it is a dollar sign, the id number will enter into a text file releasedLog.txt.

At first there were no matches, so I checked what was being copied.

It turns out the dollar signs were copied as a graphic, not text when I pasted it into a blank e-mail text box I had open. Then I pasted it to Notepad to see if there was a change. Then it turned into $$$ and a paragraph mark. I have no clue how this happened.

Ok, time is running out, I just moved the cursor back to remove the paragraph and then selected the text and it worked identifying the present and absent inmates using the $$$ discrimination.

Sure it lacks elegance and was relatively slow but it did the job.

I will continue work in the more elegant version of the system so we can apply it to similar problems when I get back, (my wife wont let me take the laptop on vacation).

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