A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Help with Keyboard troubles

  1. #1
    lifes answer to misery
    Join Date
    Nov 2010
    Posts
    13

    Help with Keyboard troubles

    Hi, Just a quick question,

    I'm making a whack-a-mole game, in which i am using a mpd16 midi pad control unit as the controller, which is working just fine, the only problem is, if i hold down a button on the pad, it will count as if i've hit that button more than once, so what i need is a way to make it so that (there are 16 buttons on the control pad) if i hit button1, it would then disable button1, until i press another button, the way i have thought about doing it is by having a variable, lets say, "var buttonPressed:int;" now, what i would then do is have the buttonPressed variable set to the buttonCode of the button i have pressed (buttonCode being like keyCode but for the mpd i am using) and then i need some way of saying "if the buttonCode in the variable is not the same as the buttonCode of the next button pressed, do this function" which i cant quite seem to figure out, i know its probably really easy but my mind is completely blank, if anyone could help it would be much appreciated

  2. #2
    lifes answer to misery
    Join Date
    Nov 2010
    Posts
    13
    ok i have been stuck on something as simple as this for 2 days now and its really starting to irritate me, the code im using is so simple and as far as i can see it should work. If anyone can see where im going wrong could you point me in the right direction? heres basically what code im using: (also i would just like to point out, temp1 & temp2 are set up like this earlier in the code: private var temp1:int = 0; private var temp2:int = 0; and holding is just a boolean that i am using to determine whether the same button has been pressed twice.(( and padEvent is a custom event i am using, which is pretty much exactly the same as a keyboard event)

    private function keyHandler(e: padEvent):void{
    temp1 = e.buttonCode;

    if(temp1 == temp2){
    holding = true;
    }
    else{
    holding = false;
    }

    // NOW THERES MORE CODE IN HERE THAT TELLS EACH BUTTON WHAT TO DO WHICH THERES NOTHING WRONG WITH SO IVE DECIDED TO LEAVE IT OUT //

    if(!holding){
    do this
    }

    temp2 = temp1;
    holding = false;


    so my code basically says:

    on a button press:
    - temp1 = the character code of the button i have pressed
    - now check if temp1 is the same as temp2 (which it wont be the first time i press a button as temp2 is set to 0 at the start)
    - if temp1 is the same as temp2, holding = true (thus doing nothing)
    - if it isnt the same then execute the function i have made

    - and finally at the very end of the code, temp2 is set to be the same as temp1, thus temp2 is now storing which button was originally pressed, so that the next time a button is pressed, temp1 will hold the new button code, and temp2 will be holding the previous button code.


    As far as i can see this is sound logic and should just work. Unfortunately it does not and I am soon going to be throwing this laptop out of a window if it does not get resolved, so if anyone would like to save me around £800 by answering this i will be very greatful.

Tags for this Thread

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center