Sound file doesnt play unless I press Enter?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
chef423
Posts: 213
Joined: 28 Aug 2016, 12:10
Contact:

Sound file doesnt play unless I press Enter?

31 May 2018, 12:06

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
DigiDon
Posts: 178
Joined: 19 May 2014, 04:55
Contact:

Re: Sound file doesnt play unless I press Enter?

31 May 2018, 14:13

EverFastAccess : Take Notes on anything the Fast way: Attach notes, Set reminders & Speed up research in 1 gesture - AHK topic
AHK Dynamic Obfuscator L - Protect your AHK code by Obfuscation - AHK topic
QuickModules for Outlook : Sort Outlook emails very quickly to multiple folders - AHK topic
Coding takes lots of time and efforts. If I have helped you or if you enjoy one of my free projects, please consider a small donation :thumbup:
Sorry I am working hard at the moment at a new job and can't commit on delays of answers & updates
DigiDon
Posts: 178
Joined: 19 May 2014, 04:55
Contact:

Re: Sound file doesnt play unless I press Enter?

31 May 2018, 14:24

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
Last edited by DigiDon on 31 May 2018, 14:35, edited 1 time in total.
EverFastAccess : Take Notes on anything the Fast way: Attach notes, Set reminders & Speed up research in 1 gesture - AHK topic
AHK Dynamic Obfuscator L - Protect your AHK code by Obfuscation - AHK topic
QuickModules for Outlook : Sort Outlook emails very quickly to multiple folders - AHK topic
Coding takes lots of time and efforts. If I have helped you or if you enjoy one of my free projects, please consider a small donation :thumbup:
Sorry I am working hard at the moment at a new job and can't commit on delays of answers & updates
MaxAstro
Posts: 557
Joined: 05 Oct 2016, 13:00

Re: Sound file doesnt play unless I press Enter?

31 May 2018, 14:32

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()
chef423
Posts: 213
Joined: 28 Aug 2016, 12:10
Contact:

Re: Sound file doesnt play unless I press Enter?

01 Jun 2018, 09:49

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
DigiDon
Posts: 178
Joined: 19 May 2014, 04:55
Contact:

Re: Sound file doesnt play unless I press Enter?

01 Jun 2018, 11:48

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.
EverFastAccess : Take Notes on anything the Fast way: Attach notes, Set reminders & Speed up research in 1 gesture - AHK topic
AHK Dynamic Obfuscator L - Protect your AHK code by Obfuscation - AHK topic
QuickModules for Outlook : Sort Outlook emails very quickly to multiple folders - AHK topic
Coding takes lots of time and efforts. If I have helped you or if you enjoy one of my free projects, please consider a small donation :thumbup:
Sorry I am working hard at the moment at a new job and can't commit on delays of answers & updates
chef423
Posts: 213
Joined: 28 Aug 2016, 12:10
Contact:

Re: Sound file doesnt play unless I press Enter?

01 Jun 2018, 15:26

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.
DigiDon
Posts: 178
Joined: 19 May 2014, 04:55
Contact:

Re: Sound file doesnt play unless I press Enter?

01 Jun 2018, 16:47

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...
EverFastAccess : Take Notes on anything the Fast way: Attach notes, Set reminders & Speed up research in 1 gesture - AHK topic
AHK Dynamic Obfuscator L - Protect your AHK code by Obfuscation - AHK topic
QuickModules for Outlook : Sort Outlook emails very quickly to multiple folders - AHK topic
Coding takes lots of time and efforts. If I have helped you or if you enjoy one of my free projects, please consider a small donation :thumbup:
Sorry I am working hard at the moment at a new job and can't commit on delays of answers & updates
chef423
Posts: 213
Joined: 28 Aug 2016, 12:10
Contact:

Re: Sound file doesnt play unless I press Enter?

05 Jun 2018, 11:55

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
grimboto
Posts: 53
Joined: 09 Jul 2014, 19:20

Re: Sound file doesnt play unless I press Enter?

07 Jun 2018, 19:16

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
		
chef423
Posts: 213
Joined: 28 Aug 2016, 12:10
Contact:

Re: Sound file doesnt play unless I press Enter?

08 Jun 2018, 10:00

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.
DigiDon
Posts: 178
Joined: 19 May 2014, 04:55
Contact:

Re: Sound file doesnt play unless I press Enter?

08 Jun 2018, 10:11

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
EverFastAccess : Take Notes on anything the Fast way: Attach notes, Set reminders & Speed up research in 1 gesture - AHK topic
AHK Dynamic Obfuscator L - Protect your AHK code by Obfuscation - AHK topic
QuickModules for Outlook : Sort Outlook emails very quickly to multiple folders - AHK topic
Coding takes lots of time and efforts. If I have helped you or if you enjoy one of my free projects, please consider a small donation :thumbup:
Sorry I am working hard at the moment at a new job and can't commit on delays of answers & updates
chef423
Posts: 213
Joined: 28 Aug 2016, 12:10
Contact:

Re: Sound file doesnt play unless I press Enter?

08 Jun 2018, 11:25

Thanks DigiDon. I was about to put that in. I learned alot from your suggestions. Thanks a bundle.

Thanks to Grim as well.
DigiDon
Posts: 178
Joined: 19 May 2014, 04:55
Contact:

Re: Sound file doesnt play unless I press Enter?

09 Jun 2018, 02:02

You're welcome. If you learned something that's what matters ;)
EverFastAccess : Take Notes on anything the Fast way: Attach notes, Set reminders & Speed up research in 1 gesture - AHK topic
AHK Dynamic Obfuscator L - Protect your AHK code by Obfuscation - AHK topic
QuickModules for Outlook : Sort Outlook emails very quickly to multiple folders - AHK topic
Coding takes lots of time and efforts. If I have helped you or if you enjoy one of my free projects, please consider a small donation :thumbup:
Sorry I am working hard at the moment at a new job and can't commit on delays of answers & updates

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: garry, marypoppins_1, mikeyww, OrangeCat, RussF and 157 guests