How do you clear the buffer of excess key presses, in Java?

Right now, in the game I am working on, if the user presses a key multiple times the actions will be performed as many times as it registers, even though I disallow key presses during the time that the action is taking place.
For example, a move of 1 space can be carried out with a key press. While the character is moving, key presses are not allowed. However, if you just press the key 5 or 25 times, the character will just keep moving, once he's done with the first one.
What I need to do is clear the buffer of key presses after an action has taken place, so that the excess keys are not registered. I know the commands to do so in C++, but not in Java.

Well, I think you've got what I was saying backwards, or I'm not understanding what you are asking correctly.
it is suppposed to return if isMoving is true, not false. If isMoving is true, it means that the moving animation, and actions are taking place, Which is a process that take about a second, for the player to move one space.
Here's the code where I process the keypresses
private void processKey(KeyEvent e) {
    if (isMoving) {return;}
    int keyCode = e.getKeyCode();
    if (!isPaused && !gameOver) {
        isMoving = true;
      if (keyCode == KeyEvent.VK_UP) {
        player.move(player.NE);
      else if (keyCode == KeyEvent.VK_DOWN) {
        player.move(player.SW);
      else if (keyCode == KeyEvent.VK_LEFT) {
        player.move(player.NW);
      else if (keyCode == KeyEvent.VK_RIGHT) {
        player.move(player.SE);
        isMoving = false;
}And in case I need to clear up what I want to happen, and the results I'm seeing. The player, in this case, moves one space in a direction, with a single press of an arrow key. That functionality is working fine, as intended. However, I don't want you to press the key twice quickly and move two spaces. I don't want you to hold down an arrow key and move continually.
That part of the functionality is what is not working.
As I understand my code, pressing the key once should set isMoving to true and, therefore further presses shouldn't register until isMoving is false again, which shouldn't happen until the player moves have finished.
But, the way that it is working now is that if I press the key 2, 3 or 20 times, as soon as one move is finished another begins. Are the key presses just sitting in the buffer somewhere waiting for isMoving to become false again? And if so, is there a function I can call to clear that buffer after a move is finished?

Similar Messages

  • How do you clear the cache in Lion?

    How do you clear the cache in Lion?

    Safari 6
    Empty Caches
    Safari > Preference > Advanced
    Checkmark the box for "Show Develop menu in menu bar".
    Develop menu will appear in the Safari menu bar.
    Click Develop and select "Empty Caches" from the dropdown.

  • How do you clear the reading list in Safari

    How do you clear the reading list in safari ?

    Safari 6 / Mountain Lion
    Section: Remove a page from the Reading List,
    http://support.apple.com/kb/PH11942?viewlocale=en_US
    Best.

  • How do you clear the download queue?

    I've reached the 3,333 track limit on my device (Android phone) and keep getting the message every time I go switch off offline mode, because I have tracks queued to download but obviously can't.How can I clear the download queue, to stop the message (and download different tracks after I undownload some others)?

    I've ran into that buying a movie. You cannot cancel it. It has to finish downloading then delete it. I tried emailing apple, they told me to do it that way. I also heard they can clear your queue(apple), but that didn't happen to me. Sorry, I looked everywhere as well. I would buy a movie on my iPad to watch on atv and I had to do it that way. I just purchase from tv now and download later on MacBook or iPad if I want it.

  • How do you clear the email history for addresses on the Z10 ?

    I would like to know how to delete the history of names on the BBZ10 please.
    You know like on outlook when you dont want an address to appear again you bring up the address and then highlight it and then hit the delete button and its gone from your history for good.
    Well how do you do it with BB's?
    I have email addresses that I have deleted from the contacts list and yet they still come up when i start to type up another email?
    Surely this must be a no brainer but I'm missing something.
    I used to have this same issue with my Torch and my 9800 before that.
    Does anybody know how to fix this problem for me please?
    I hope my explanation has been clear enough as well.
    Appreciate the solution greatly.
    thanks,
    Nap68

    #Go to Firefox > History > Clear recent history or (if no Firefox button is shown) go to Tools > Clear recent history.
    #Under "Time range to clear", select "Everything".
    #Now, click the arrow next to Details to toggle the Details list active.
    #From the details list, check ''Cache'' and ''Cookies'' and uncheck everything else.
    #Now click the ''Clear now'' button.

  • How do you clear the "Used supplies in use" message

    I had a Laserjet 1525nw printer replaced under warranty.  The service folks re-installed my original cartridges but now I get the Used Supplies in Use message and I cannot ge the information on how much supply is left in each cartridge.  How do I clear this message?

    Hi dgaraux1,
    Here is a link to a support document that will help interpret control panel and status alert messages. You exact status message in listed in the document says there is not required action on your part.
    Hope this is helpful.
    If I helped you at all it would be great if you clicked the blue kudos star!
    If I solved your post please mark it as solved to help others.
    I'm a printer tech with HP.

  • How do you clear the current song info from the top display window?

    When you first start iTunes and select Music, the display window at the top just has an Apple logo in it. Once you start playing a song, the song info shows up there. I can stop the song using Command-period (or the space bar), but the info stays there. Is there a keyboard shortcut or something simple to return the window to just the Apple logo? I cleared it inadvertently when I selected Radio, but I don't know if that will always work and I'm guessing there's a formal way to do it. (Selecting Radio while a tune is playing won't clear the info, of course.)

    Fairhavens wrote:
    ... a good manual for iTunes
    here are some:
    iTunes 101
    How to Use iTunes: Getting Started
    iTunes Keyboard Shortcuts
    JGG

  • How do you clear the recent history list (as this function was lost in one of the last app updates )?

    Since this function was apparently lost in one of the last adobe reader app updates, how now are you supposed to clear the recent history, but retain the files on my nexus tablet?

    Hello,
    That explains why I am no longer able to clear the recent history list...
    I understand that removing/deleting the files from my device will remove the files from my list. However this in not ideal for me, as I would like to be able to go back and look at the papers that I have previously read and then be able to clear the recent list. Also, if I can clear the list without removing the files from my device, I can keep track of what I have recently read, and move those files into a second folder on my device to say that I have read the papers at least once. That way I would still have the papers on my device but can clear the list and know that I have read the papers. Thus I really would like a way to clear your history from the recents list, ideally with the option of clearing individual files from the list, as well as a second option to clear all files from the recent list, while retaining the original files on the device.
    Thanks and have a good day,
              Trevor

  • WRT54G - How do you clear the log files?

    How does one "Clear" both the Incoming/Outgoing log files?
    Thanks.

    Turn the logs off and click save.  When it is confirmed that your settings were saved, go back into the logs and turn them back on.  Make sure you save your changes.  That should clear your log files.
    I hope that helps.

  • TS3992 so how do you clear the message "This iPad hasn't been backed up . . . "

    How do you get this message off the screen "This iPad hasn't been backed up in 5 weeks.  Backups happen when this iPad is plugged in, locked, . . . "

    Some users have reported that the iPad freezes on this screen. Try resetting:
    Hold both the home and power buttons at the same time until the Apple boot logo appears. No data will be lost.

  • How do you clear the chart in an AI Waveform Scan VI upon program start?

    I am using a waveform scan vi in a program. The output of the vi is set to "Waveform". What I want to do is have the program automaticly clear the waveform chart each time the program starts. Currently I must start the program, right click on the chart and select clear. I have attempted to use the chart history property node, which I assumed is the correct path to take but so far my attempts have been unsuccessful.

    Ahhh, waveforms... These got better in LV 7 I hear.
    Will this do it?
    2006 Ultimate LabVIEW G-eek.
    Attachments:
    Problem_example.vi ‏41 KB

  • How do you clear the App download page once an App has been downloaded or updated?

    Can anyone help?

    You're welcome. That was something that changed with iOS7. Presumably it's meant as transparency for those that have automatic app updateing enabled, so you can always see what your device did while you weren't looking. But it applies across the board, whether you have the auto updating on or not.

  • How do you reset the special keyboard function keys?

    I used to use an older external keyboard that had Dashboard as F4. Now I got a newer keyboard that has Launchpad as F4. I was used to the old way, so I went into the keyboard shortcut for Dashboard and set it as F4. To my disappointment, however, it only works when I hold 'fn'. (I didn't expect this, as when the key was set to F13 holding fn wasn't required.) So anyway, that is even worse, and I wanted to change it back. However, it wouldn't let me. (In Launchpad & Dock > Keyboard Shortcuts, there used to be a checkmark next to Show Launchpad with a blank area on the right, but now when I try to click Restore Defaults, it forces me to choose a key... and pressing F4 without holding fn doesn't register.) And I know I can make it use all function keys as standard function keys, but not just for F4. And if I do it for all of them, I lose the other keyboard controls and I don't want that. I don't want to have to be stuck with the FunctionFlip 3rd party tool forever... How can I actually reset they key (or ideally, make it bring up dashboard without holding down fn)? You'd think that if it's so simple to change a setting one way it would be simple to change back. I'd even delete some prefs file if i had to.

    I figured out that if you remove the ~/Library/Preferences/com.apple.symbolichotkeys.plist file and restart, that restores the keyboard.
    Second question: Is there any way to make F4 (without holding fn) bring up Dashboard on Lion that doesn't require FunctionFlip? If it matters, I have a Time Machine backup of the symbolichotkeys.plist file from when I had the older keyboard.

  • How do you clear the download list without deleting the files?

    I'm using mobile firefox on a samsung galaxy nexus. I was looking for a way to clear my download history without deleting the files from my phone (like clearing downloads on the pc)
    is this possible? how would I do it?
    if not is there an app that can do it?

    [http://www.galaxynexusforum.com/forum/galaxy-nexus-help/2935-how-erase-downloads.html http://www.galaxynexusforum.com/forum/galaxy-nexus-help/2935-how-erase-downloads.html]
    i hope you can find something of use here!

  • In iOS 7, how do you clear the "Missed" section of the Notification Center?

    The "Missed" seciton doesn't have the Clear button like the "Recent" seciton does, and I can't seem to get rid of the missed calls in that list. I even went as far as to erase all my missed and recent phone calls in the Phone list, but the notification center won't clear out.

    I've been trying to grok the new notification center on ios7 with Apple so notoriously light with the documentation so here goes:
    - missed notifications (the rightmost tab in ios7 notification center) collates all of your notifications that you got when the phone was locked (the ones you get on the lock screen only) so that you dont have to worry about unlocking the phone and losing those.
    - they sorted in reverse chronological order from newest to oldest
    - 'missed' only covers the last 24 hours so the oldest notification you will see is 24 hours old. this is seemingly by design and i guess its logical to assume people will check their phone once every 24 hours.

Maybe you are looking for