Page 1 of 1

Sound file doesnt play unless I press Enter?

Posted: 31 May 2018, 12:06
by chef423
When the 'Item Not Found!' box pops up, I need the .wav file to play AND I need both Enter and NumPadEnter disabled so the user must touch the screen to exit the 'Item not found!' applet box....

But, my sound only plays (when remoted in) when I press enter AFTER the 'Item not Found!' box appears.

Any ideas?

Thanks

Code: Select all

Loop {

	#IfWinActive, Item Not Found!
	$Enter::
	$NumPadEnter::
	
	SoundGet, master_mute, , mute ; this will check if volume is muted or therwise
	if ( master_mute == "On" )  
   	SoundSet, +1, , mute ; this will unmute
	SoundSet +100
	 
	SoundPlay, C:\POS\AHK\Noise.wav
	
	WinWaitClose, Item Not Found!
	SoundPlay, C:\POS\AHK\Nonexistent.wav
	SoundSet, -1, , mute ; this will mute
	Break
      }
Return

Re: Sound file doesnt play unless I press Enter?

Posted: 31 May 2018, 14:13
by DigiDon

Re: Sound file doesnt play unless I press Enter?

Posted: 31 May 2018, 14:24
by DigiDon
Not sure to have understood perfectly but to desactivate the keys you should probably do something like this

Code: Select all

#IfWinActive, Item Not Found!
$Enter::donothing
$NumPadEnter::donothing
#IfWinActive

donothing:
return

Re: Sound file doesnt play unless I press Enter?

Posted: 31 May 2018, 14:32
by MaxAstro
To play the sound, you'll probably need to use SetTimer to create a loop that checks for the window to be active. Check out these pages in the docs:

Code: Select all

SetTimer
WinActive()

Re: Sound file doesnt play unless I press Enter?

Posted: 31 May 2018, 20:54
by chef423
Thanks guys..ill read up.

Re: Sound file doesnt play unless I press Enter?

Posted: 01 Jun 2018, 09:49
by chef423
This code is close, but I do not understand why I have to press enter (on my keyboard) to get the sound to play AFTER the 'Item not found!' dialog box pops up..

Plus, the sound .wav file doesnt actually stop, its just muted and the volume is down, after I kill the 'Item not found!' box and unmute the speakers and turn the volume up, you can still hear the beep!

Code: Select all

	
	#IfWinActive, Item Not Found!
	{
	WinActivate, Item Not Found!
	$Enter::
	$NumPadEnter::
	SoundGet, master_mute, , mute ; this will check if volume is muted or therwise
	if ( master_mute == "On" )  
   	SoundSet, +1, , mute ; this will unmute
	SoundSet +100 ; Raise volume to 100%
	SoundPlay, C:\POS\AHK\Noise.wav
	
	WinWaitClose, Item Not Found!
    	SoundPlay, Nonexistent.avi
	SoundSet -100 ; Turns volume down to 0
	SoundSet, -1, , mute ; this will mute
	WinActivate, Cash Register Express
	Return
	}
	Return

Re: Sound file doesnt play unless I press Enter?

Posted: 01 Jun 2018, 11:48
by DigiDon
You did not take our remarks andyou need to read the documentation more carfully.

Re-read our previous posts.

On SoundPlay help page one can read:
To stop a file that is currently playing, use SoundPlay on a nonexistent filename as in this example: SoundPlay, Nonexistent.avi.

Re: Sound file doesnt play unless I press Enter?

Posted: 01 Jun 2018, 15:26
by chef423
DigiDon wrote:You did not take our remarks andyou need to read the documentation more carfully.

Re-read our previous posts.

On SoundPlay help page one can read:
To stop a file that is currently playing, use SoundPlay on a nonexistent filename as in this example: SoundPlay, Nonexistent.avi.

Look at my code, its in there, it does not work.

Re: Sound file doesnt play unless I press Enter?

Posted: 01 Jun 2018, 16:47
by DigiDon
Well maybe but you didn't take into account our remarks on #IfWinActive/if Winactive() and SetTimer.

Your use of #IfWinActive and labels are wrong so probably are cause to some of your problems...

Re: Sound file doesnt play unless I press Enter?

Posted: 05 Jun 2018, 11:55
by chef423
DigiDon wrote:Well maybe but you didn't take into account our remarks on #IfWinActive/if Winactive() and SetTimer.

Your use of #IfWinActive and labels are wrong so probably are cause to some of your problems...
This is as close as I can get it on my own, I have tried many variations, but unless I press Enter, the sound doesnt play, which makes no sense to me.

AHK code clearly says "if my window is active, play the sound"

Code: Select all

	#IfWinActive, Item Not Found!
	$Enter::
	$NumPadEnter::
		
	if WinActive("Item Not Found!")
	SoundGet, master_mute, , mute ; this will check if volume is muted or therwise
	if ( master_mute == "On" )  
   	SoundSet, +1, , mute ; this will unmute
	SoundSet +100 ; Raise volume to 100%
	SoundPlay, C:\POS\AHK\Noise.wav
	WinWait, Item Not Found!
	WinWaitClose
    	SoundPlay, Nonexistent.avi
	SoundSet -100 ; Turns volume down to 0
	SoundSet, -1, , mute ; this will mute
	WinActivate, Cash Register Express
	Return

Re: Sound file doesnt play unless I press Enter?

Posted: 07 Jun 2018, 11:16
by chef423
Any other folks have an idea?

Re: Sound file doesnt play unless I press Enter?

Posted: 07 Jun 2018, 19:16
by grimboto

Code: Select all

	while(!WinActive("Item Not Found!")){  ;Wait for Window to become active
		
		sleep 20 
	
	}
	if WinActive("Item Not Found!")
	SoundGet, master_mute, , mute ; this will check if volume is muted or therwise
	if ( master_mute == "On" )  
   	SoundSet, +1, , mute ; this will unmute
	SoundSet +100 ; Raise volume to 100%
	SoundPlay, C:\POS\AHK\Noise.wav
	WinWait, Item Not Found!
	WinWaitClose
    	SoundPlay, Nonexistent.avi
	SoundSet -100 ; Turns volume down to 0
	SoundSet, -1, , mute ; this will mute
	WinActivate, Cash Register Express
	Return
	
	
	
	;these are hotkeys so they go below the Main part of your script
	;the way you had it set up they would run the code below them until a return was reached
	#IfWinActive, Item Not Found!
	$Enter::return
	$NumPadEnter::return
		

Re: Sound file doesnt play unless I press Enter?

Posted: 08 Jun 2018, 10:00
by chef423
grimboto wrote:

Code: Select all

	while(!WinActive("Item Not Found!")){  ;Wait for Window to become active
		
		sleep 20 
	
	}
	if WinActive("Item Not Found!")
	SoundGet, master_mute, , mute ; this will check if volume is muted or therwise
	if ( master_mute == "On" )  
   	SoundSet, +1, , mute ; this will unmute
	SoundSet +100 ; Raise volume to 100%
	SoundPlay, C:\POS\AHK\Noise.wav
	WinWait, Item Not Found!
	WinWaitClose
    	SoundPlay, Nonexistent.avi
	SoundSet -100 ; Turns volume down to 0
	SoundSet, -1, , mute ; this will mute
	WinActivate, Cash Register Express
	Return
	
	
	
	;these are hotkeys so they go below the Main part of your script
	;the way you had it set up they would run the code below them until a return was reached
	#IfWinActive, Item Not Found!
	$Enter::return
	$NumPadEnter::return
		

The beep happens on first instance of Item not found, but now the sound only plays once lol, meaning if I scan an item not in the system, great it beeps (after freshly launching the code) but if I clear it and scan another item that isnt found, the sound doesnt play again.

Re: Sound file doesnt play unless I press Enter?

Posted: 08 Jun 2018, 10:11
by DigiDon
That's normal as it should be checked regurlarly by a timer

Code: Select all

SetTimer,CheckWindow,200
return

#IfWinActive, Item Not Found!
$Enter::return
$NumPadEnter::return
#IfWinActive

CheckWindow:
if WinActive("Item Not Found!") {
  SoundGet, master_mute, , mute ; this will check if volume is muted or therwise
  if ( master_mute == "On" )  
  SoundSet, +1, , mute ; this will unmute
  SoundSet +100 ; Raise volume to 100%
  SoundPlay, C:\POS\AHK\Noise.wav
  WinWaitClose, Item Not Found!
  SoundPlay, C:\POS\AHK\Nonexistent.wav
  }
return

Re: Sound file doesnt play unless I press Enter?

Posted: 08 Jun 2018, 11:25
by chef423
Thanks DigiDon. I was about to put that in. I learned alot from your suggestions. Thanks a bundle.

Thanks to Grim as well.

Re: Sound file doesnt play unless I press Enter?

Posted: 09 Jun 2018, 02:02
by DigiDon
You're welcome. If you learned something that's what matters ;)