on keypress question

Discussion in 'Technology' started by Mirage, May 8, 2007.

  1. Mirage

    Mirage Administrator Staff Member V.I.P.

    Does anybody know if there is a way to set an "on keypress" that will look for any key pressed except for a specified key?

    Like on (!keypress "a") or something. I know that doesn't work though but does anybody know how to do that or if it is even possible?

  2. Mr_Snipes

    Mr_Snipes Registered Member

    What language are you trying to do it in?
  3. Doc

    Doc Trust me, I'm The Doctor. V.I.P.

    Actionscript. There's a way, I know for sure. Unfortunately, I can't remember ATM and I don't know CS3.
  4. Mr_Snipes

    Mr_Snipes Registered Member

    I guess I should look in the forum. ActionScriping I do not know. Try doing a search for ActionScripting and keypresses.
  5. Mirage

    Mirage Administrator Staff Member V.I.P.

    Sorry, I assumed most people would see what forum it was in before replying. :D

    And yeah I'm sure it is possible. The other alternative is to create 100 or so if statements for every key on the keyboard except for the one that I want pressed.... but that would be a nightmare.

    There has got to be an easier way but I searched for hours on Google and couldn't make sense of anything I found. :shake:
  6. Mr_Snipes

    Mr_Snipes Registered Member

    ActionScript Key Class

    Try using this link and see if you can make sense of it. If you are having trouble, let me know and I will talk you through it.
  7. Mirage

    Mirage Administrator Staff Member V.I.P.

    I actually was reading that page the day I made this thread.. lol! It confused me like crazy..

    All I want to do is basically create an if statement for if "any key besides x" is pressed, do whatever. Is that possible?

    I know how to do if X is pressed, but what about the opposite?
  8. Mr_Snipes

    Mr_Snipes Registered Member

    Well if you know how to make it so that when "X" is pressed it, you can have it do something. Then create that statement that you would use to have the computer do something if "X" is pressed, but don't put anything for it to do, and then put an else statement after it, and in there put what you want the computer to do for all other keypresses.

    That should solve the problem, because when "X" is pressed, the computer will find the empty if statement for that keypress, but when any other key is pressed it will execute the else statement and follow the commands inside that statement.

    Does that help?
    Last edited: May 12, 2007
  9. Mirage

    Mirage Administrator Staff Member V.I.P.

    I wonder if the else idea will work. Didn't even think of that. I will try it and post my results. :)

    EDIT: Ok that does not work. The actionscript for detecting a keypress is:

    on (keypress "key")

    not if (keypress, etc, so else does not apply here. Can you think of a way around it?
  10. Mr_Snipes

    Mr_Snipes Registered Member

    Please post here the exact code that you use to get actionscripting to recognize that the "X" key has been pressed.

Share This Page