Sign in to follow this  
Followers 0
ctl

Play a sound when pressing a button

5 posts in this topic

Hello, i was wondering how could i play a sound, when i am pressing a combination of keysi used this:

SoundPlay('D:\sound.mp3', 1)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

So i want the sound to play when i press a combination of keys lie "alt+F2" or "S" or anything else, you got the point, could this be possible ? Thnaks!

Edited by ctl

Share this post


Link to post
Share on other sites

Have a look at the _IsPressed command, which you will need to run in a loop (with Sleep), or you could just set a hotkey via a shortcut for your script.


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Ok, i think i got it, its working fine, here is the code:

Any suggestions ? Could i maybe stop the sound ?

 #include <Misc.au3>
 #include <MsgBoxConstants.au3>
 
Local $hDLL = DllOpen("user32.dll")
 
 
While 1
    If _IsPressed("78", $hDLL) Then
  SoundPlay('D:\sound.mp3', 1)
           ; Wait until key is released.
        While _IsPressed("78", $hDLL)
            Sleep(1)
        WEnd
    EndIf
    Sleep(250)
WEnd
Edited by ctl

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Easy enough if you look at the Parameters and Remarks in the Help file for SoundPlay, then either use another key to stop the sound or set a value in a variable and use the original key via an Else If test.

I'm not understanding your use of the second While...Wend loop?

You should only need the one, for both start and stop.

Edited by TheSaint

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
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
Sign in to follow this  
Followers 0