SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard westmich's Avatar
    Join Date
    Mar 2000
    Location
    Muskegon, MI
    Posts
    2,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Playing a Sound with the OnKeyPress Event Handler

    Yes, I know there is no practical purpose for tying a sound (WAV file) into evertime a key is pressed, but I know it can be done - I just can't find an example.
    Westmich
    Smart Web Solutions for Smart Clients
    http://www.mindscapecreative.com

  2. #2
    SitePoint Zealot thirdcherry's Avatar
    Join Date
    May 2003
    Location
    CA
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What program are trying to accomplish this in?

  3. #3
    gingham dress, army boots... silver trophy redux's Avatar
    Join Date
    Apr 2002
    Location
    Salford / Manchester / UK
    Posts
    4,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, i've never tried this, but here's an educated guess...
    add the sound as an embed, making sure it does not autostart, and use javascript to trigger it.

    something like:
    Code:
    <body onkeypress="document.annoyme.play();">
    <embed src="annoyme.wav" hidden=true autostart=false loop=false name="annoyme" mastersound>
    </body>
    there's probably a better way to do this, but javascript is not my forte. moving thread to javascript forum to see if there's some more knowledgeable people who can help you out
    re·dux (adj.): brought back; returned. used postpositively
    [latin : re-, re- + dux, leader; see duke.]
    WaSP Accessibility Task Force Member
    splintered.co.uk | photographia.co.uk | redux.deviantart.com

  4. #4
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I use sound at my site; both onmouseover and onkeypress at www.unitingrhythms.com/arts/musical.html
    Its hard to create a cross-browser sound controller, so at the moment there's just ie functions.
    Code:
    function Sound(sndAction,sndObj) { if(wmp) {
    if(sndAction=="play" ) { eval(sndObj).controls.play();}
    if(sndAction=="stop" ) { eval(sndObj).controls.stop();} }}
    Which is a Windows Media Player only sound controller

    try the http://msdn.microsoft.com library for sound controls, really good info. with wmp you can also change the sound-rate, which is the speed it plays. Have a look at www.unitingrhythms.co.uk/drums/rhythms.html , and if you have wmp you can change the tone of the sounds (ie drum) good for using the same sound more than once. (open the drum in new window with different sound rate)
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •