play sound on keypress - problem

  • Hi gang and Klaus

    I have a little problem I don't seem to get buy... I am creating an installation where I will be hacking a keyboard to be able to make step-able keys.

    What I am trying to do is if Key is down it plays a certain sound and it keeps playing it until the key has been released. How I am doing this right now is like this.

    But the problem there is, as soon as key 83 is pressed and being held down the sound just starts playing over and over again from the beginning only getting small portion of the sound... Is it possible to have an action that would be "keyPressed" that states if the key is being held down keep on running the sound?

    I hope you get what I am getting at.

    Hope for a quick reply... Thanks gang.

  • Hi,

    thanks for this note, yes I will try to add something like also a "keypressed" event,

    for the moment - you could add a own custom variable to check it that key was already pressed:
    - set a variable to true when the key was pressed,
    - set it to false when released,
    - and check for this variable on keypress

    e.g.

    Code
    <action name="keydown">
    trace(keydown - keycode=,keycode);
    if(keycode == 83, if(key83_pressed != true, trace(play sound);set(key83_pressed,true););  );
    </action>
    
    
    <action name="keyup">
    trace(keyup - keycode=,keycode);
    if(keycode == 83, trace(stop sound);set(key83_pressed,false); );
    </action>

    best regards,
    Klaus

  • I have it like this now and there is no sound.

    What am I doing wrong?

  • While i have you on the topic, would it be hard to implement a fade on the keyup.. so the sound fades smoothly?

    EDIT: just to make sure I am clear fade the volume down, could happen pretty fast, its just to try and get rid of "clicks" when sounds are cut all of a sudden.

    Just some brainstorms for my own project and some future ideas for you.

    Einmal editiert, zuletzt von olihar (16. Juni 2009 um 00:01)

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!