How to Play a Sound with HotKey?

Questions, advice, how to, and everything else concerning HotkeyNet

How to Play a Sound with HotKey?

Postby jonjonz on Thu Dec 24, 2020 10:28 am

Sorry for posting this during the holidays. Reply at your convenience.

I have programmed a button to act as cool down indicator. When the hotkey is pressed it displays a button showing the letter C indicating cool down, after waiting out the required time, it changes to display B to indicate the skill is ready again.

In addition, I would like to play a sound when it reaches the end of the cool down.

I found some old posts here about using the old outdated windows media player to play sounds via HotKey, but I tried that and there were several problems with it that I could not see how to fix.

I found a small alternative command line sound file player that plays mp3 or wav files named cmdmp3win here:

cmdmp3win

I put the cmdmp3win.exe and a sound file chimes.wav in the same directory and if I type the following at the command line prompt, cmdmp3win chimes.wav - the sound plays fine and there is no gui to try and hide.

I have not been able to get it to work using a HotKey script. It includes several variations to show I tried them. I also tried START, and OPEN instead of RUN.

Is there a way to make this work or an alternative method to play a wav file via a HotKey script?

Thanks,

Script:
Code: Select all
// Test for BURST WITH cool down indicator
// The button works but sound does not

//  CREATE BUTTON AND CHANGE WHEN COOLDOWN IS DONE
//  THIS WORKS

   <Command AutoExec>
   <CreatePanel P1 800 500 65 90>
   <CreateButton alpha 800 500 25 25 ON>
   <SetButtonstyle alpha colored>
   <SetButtonColors alpha 0x7A0707 0xffffff>
   <AddButtonToPanel alpha P1>
   <TargetWin P1>
    <AlwaysOnTop on>
   <wait 1100>
   <HIDEWIN>

//   KEY TO TOGGLE BUTTON ON / OFF
      
<HOTKEY J>
//   <TOGGLE>
      <TargetWin P1>
      <SetPanelStyle P1 transparent>
      <AlwaysOnTop on>
      <SHOWWIN>
      <sendpc local>
      <SetbuttonText alpha C>
        <WAIT 3000>
//       3000 IS FOR FAST TESTING, IN GAME IT WOULD BE 15 SECONDS OR SO
        <SetbuttonText alpha B>
        <RUN cmdmp3win chimes.wav>
        <wait 1000>
        <RUN E:\PROGRAMS\HotKey\cmdmp3win chimes.wav>
        <wait 1000>
        <RUN E:\PROGRAMS\HotKey\cmdmp3win E:\PROGRAMS\HotKey\chimes.wav>
   
//   <TOGGLE>
//      <TargetWin P1>
//       <AlwaysOnTop on>
//      <HIDEWIN>
//      <CANCEL>   


Result:
Code: Select all
<TargetWin P1> completed: Window found. Target set to 0x310494 "P1"
<SetPanelStyle P1 transparent> completed
<AlwaysOnTop on> completed
<SHOWWIN> completed
<SetbuttonText alpha C> completed
<WAIT 3000> completed: 3000 milliseconds
<SetbuttonText alpha B> completed
<RUN cmdmp3win chimes.wav> failed: Operating system CreateProcess function failed; Windows reports system error 2, "The system cannot find the file specified."
<wait 1000> completed: 1000 milliseconds
<RUN E:\PROGRAMS\HotKey\cmdmp3win chimes.wav> failed: Operating system CreateProcess function failed; Windows reports system error 3, "The system cannot find the path specified."
<wait 1000> completed: 1000 milliseconds
<RUN E:\PROGRAMS\HotKey\cmdmp3win E:\PROGRAMS\HotKey\chimes.wav> failed: Operating system CreateProcess function failed; Windows reports system error 3, "The system cannot find the path specified."
jonjonz
 
Posts: 6
Joined: Tue May 12, 2009 8:28 pm

Re: How to Play a Sound with HotKey?

Postby HotkeyNet on Thu Dec 24, 2020 5:50 pm

You are obviously smart and good at software so I'm going to answer in depth. You did almost everything right but your efforts were foiled, I think, by the assumption that the various parts of Windows work the same way. Very often they don't.

You told the operating system in three different ways to run cmdmp3win. Three times the operating system replied that it can't find that file (when you added the full path the OS switched to "can't find the path" but the meaning is the same). The reason the OS can't find a file named cmdmp3win is because there is no file with that name. The actual name of the file is cmdmp3win.exe. Therefore the solution is to write cmdmp3win.exe.

You're probably thinking, "This can't be right. I tested it on the command interpreter. The command interpreter didn't need .exe."

If that's what you're thinking, you're assuming that the command interpreter and CreateProcess work the same way. But they don't. (You know you're dealing with CreateProcess here because the error messages told you so. HKN forwards your <Run> arguments to the operating system's CreateProcess function.)

Different parts of Windows work differently from each other.

If you still have a problem after adding .exe, double check the path. You may have written it wrong.
-- Freddie aka Rob
HotkeyNet
Site Admin
 
Posts: 5686
Joined: Fri Mar 28, 2008 8:36 pm

Re: How to Play a Sound with HotKey?

Postby jonjonz on Mon Dec 28, 2020 11:34 am

Wow, thanks for explaining the difference between the processes.

<OPEN cmdmp3win.exe chimes.wav> works like a charm.

Bad assumption on my part, I am just a dabbler, the only training I have had was an intro Cobol course in community college.

I used to run a website for a large library, so I had to learn bits and pieces of javascipt and php mostly so when I work with HotKey I am just winging it.

Thanks again :D
jonjonz
 
Posts: 6
Joined: Tue May 12, 2009 8:28 pm


Return to General HotkeyNet stuff

Who is online

Users browsing this forum: No registered users and 3 guests

cron