Is there a way to detect two keys at the same time?

Is there a way to detect the keys if the user is holding two keys down at the same time?

yes, but you'll have to check outside of the event loop (i.e. don't check for it in the keyPressed method).
just use an array of keys that keeps track of which keys are currently down and which are up. you could use a boolean array but I use an int array because... Im not sure I've just done it probably because of my C background. anyway, basic setup:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class MultiKey extends JFrame {
     int keys[];
     public MultiKey() {
          super();
          keys = new int[256];
          Arrays.fill(keys,0); // 0 = key is up
          enableEvents(AWTEvent.KEY_EVENT_MASK);
          show();
     public void processKeyEvent(KeyEvent e) {
          // the 0xff below binds the key code to below 256
          int key = (e.getKeyCode()&0xff);
          if (e.getID() == KeyEvent.KEY_PRESSED) {
               keys[key] = 1; // 1 = key is down
          else if (e.getID() == KeyEvent.KEY_RELEASED) {
               keys[key] = 0; // 0 = key is up
     protected boolean isKeyDown(int key) {
          return (keys[key] != 0);
     protected boolean isKeyUp(int key) {
          return (keys[key] == 0);
}so now at any time in your code you can check key state by using the isKeyUp and isKeyDown methods. this is about as close as you get to input polling in java unless you use LWJGL or something similiar ;)
you can try out a full executable example at my site here - just open up the jar and start holding keys down :)

Similar Messages

  • Is there a way to show two angles at the same time in the final edit rather than switch between them with Multicam?

    Can I show two angles at the same time in the final edit rather than alternate with Multicam?

    Stack two clips on top of each other and reduce the sizes. I think that's what you want.

  • Is there a way to open two months at the same time in iCal?

    I have recurring events for every month in 2009 and want to replicate them in 2010. I do not want to just extend the stop date because there will be subtle changes to the 2010 items that I do not want changed in the 2009 versions. I would ideally like to open Jan 2009 and Jan 2010 next to each other and copy the 2009 event to the 2010 calendar (the appointment copy does not copy the recurrence info which is good). Is there a way to show either two instances of iCal running or 2 month windows?
    Thanks!

    Hi,
    If you activate iCal's Debug menu, you should find it has a 'New Calendar Window' option (Cmd-L). It is a bit of a knack to cutting and pasting correctly between windows.
    Best wishes
    John M

  • Is there any way to view two tabs at the same time w/o opening a new window?

    I would like to view one tab while I am working in another. I can do it by opening one of the tabs in a new window and tiling both windows on the screen. Is there any way to do it within one window?

    Just installed Split Panel and it looks like it will do exactly what I want.
    Thanks,
    (Don't know how this got in here twice. I'd like to delete it but can't figure out how to.)

  • Is there a way to add two windows in the same window?

    is there a way to add two windows in the same window?

    what do you mean by your first use of the word "window"? do you mean a visible frame? a section of the gui that the user doesnt see?
    or perhaps you mean you want to add multiple tabs to a single window, so that switching between tabs shows different windows?

  • Is there a way to delete multiple pictures at the same time from the iphone4s?

    Is there a way to deleter multiple pictures at the same time, from my iphone4s? I know how to delete one at a time. Thanks

    Open your Photos App > Camera Roll > At the top right corner you will see a rectangle with a right arrow, select that. Now you can select as many photos as you want and you can hit the red Delete button on the bottom right.

  • Any way to play two clips at the same time one over the other? (transprent)

    Any way to play two clips at the same time one over the other? (transprent)

    Yes.
    See the information here for a variety of ways to do this:
    http://discussions.apple.com/thread.jspa?threadID=933500&tstart=50
    http://discussions.apple.com/thread.jspa?threadID=903151&tstart=0
    http://karsten.schluter.googlepages.com/jackiechancredit
    http://www.geethree.com/slick/V_04.html

  • Data Sets - Is there a way to put two fields in the same row?

    I am working on my first Spry Data Set (in Dreamweaver CS4) which, if I can get it figured out, will eventually be used as a calendar on a client's web site. You can see the beginning of the project here:
    http://www.rieradesignco.com/calendarlist_spry.html
    My question is, can I put two or more fields on one row? Specifically, I would like the part that looks like this...
    3
    [WED]
    Fusion
    ... to look like this:
    3   [WED]   Fusion
    I tried simply moving the fields (in Design View) so that they looked like they would be in the same row, but as you can see, that didn't do the trick. (You can see what I did here, in the highlighted part of the screenshot:  http://www.rieradesignco.com/spryquestion.jpg). I also tried nesting a table within the table on my html data document that contained the three fields I needed - it worked okay, but that just makes the table more difficult to work with. I don't want to simply type the three items into one field, because it will be a long list and they all need to line up perfectly.
    Is there another way to do it?

    Change the following line to include the red coloured parts
    <div class="MasterColumn" spry:repeat="ds4" spry:setrow="ds4" spry:hover="MasterColumnHover" spry:select="MasterColumnSelected">
      <span>{Dsp_#}</span><span>{Dsp_WkDay}</span><span>{Dsp_Event}</span>
    </div>
    The add the following style rule to your document:
    .MasterColumn span {
        display: inline-block;
    I hope this helps.
    Ben

  • AddressBook - Is there a way to change multiple addresses at the same time?

    To be clear....I have 25 contacts at 1 company and that company moved.
    Is there a way to link the cards together so that when I change the address on one card it automatically updates the other 24 cards?? Rather than having to change each contact individually, which is time consuming and annoying.
    I have created a "Smart Group" for the company and all of the contacts place themselves in the group but it still won't sync the addresses.
    Can someone tell me how to do this, if it's even possible? And if it's not, I really wish it was!!
    Thanks!

    Open your Photos App > Camera Roll > At the top right corner you will see a rectangle with a right arrow, select that. Now you can select as many photos as you want and you can hit the red Delete button on the bottom right.

  • Is there a way to allow two users on the same itunes account to see their individual contacts and calendars

    I'm just looking for away to allow my wife and I to see our contacts, emails, and calendars on the macbook pro. We have a single itunes account, with two different iphones. How do we do this? Right now the computer only shows my wifes information.
    Thanks
    Josh

    Thanks GB,
    Ok, so I've gone ahead and setup another Apple ID for my Iphone so now we have two Apple IDs and two Icloud accounts. My Iphone is on my Apple ID, her Iphone, Ipad and Macbook Pro are on her ID.
    Could you give me some direction as to how to add my information to the Macbook Pro.
    - I'd like to be able to see my her and my calendars by clicking on the calendar icon dock.
    - Same with Email, can we see both emails by clicing on the email icon in the dock - I was able to do this on the Ipad but can't figure it out on the Macbook Pro
    - Contact would also be nice but I'm not sure its possible
    I know I could probably setup a second user on the computer, but that would mean logging in and out of user groups all the time which we don't really want to do.

  • Is there a way to add multiple images at the same time to Keynote 6.0?

    I just brought keynote after searching online about adding multiple images to a presentation all in one go - I couldn't do this on the powerpoint version I was using but there were multiple references on google to being able to do this on keynote. I purchased it and now can't get it to work! Any ideas anyone? Thanks

    Do you mean like dragging in multiple images and having one image go on each slide? If so, you just drag the images into the Slide List on the left instead of onto the slide. From this prior post.
    https://discussions.apple.com/message/9068283#9068283

  • If I have two appointments at the same time, they overlap in the iOS 7 calendar rather then appearing side-by-side so that I can't read one of them due to the identical colors of the two appointments.  Is there any way to fix this with a setting?

    If I have two appointments at the same time, they overlap in the iOS 7 calendar rather than appearing side-by-side in the daily view, so that I can' read both of them due to the same background color.  Is there a way to change this via a settings change?

    I fyou have "all day" event that are taking up the entire day, check the event. All day event only appear at the top of the time line (and just below the week view). I suspect they are not actually set up as all day, but have specific time frames assigned.
    In teh screen shot below, "Sample" is an all day event; NFL: CAR@SF is not.

  • Is there a way to automatically add another of the same page while a form is being filled?

    Is there a way to automatically add another of the same page while a form is being filled?
    I have a two-page form of which the second page is essentially a spreadsheet analog.  Often, there is need for for more lines than are available on the page.  Is there a way in which to add another or even multiple copies of the second page? 
    Thanks ahead...
    TG

    You can do that with a dynamic XFA form created in LiveCycle Designer, which comes with Acrobat Pro for Windows. For more information, you can ask over at the LiveCycle Designer forum.

  • Help Please.  I am setting up my macbook pro for a second user but office didn't transfer over.  Is there a way to have additional users on the same comp have office available without having to re-install it for each user?

    Help Please.  I am setting up my macbook pro for a second user but office didn't transfer over.  Is there a way to have additional users on the same comp have office available without having to re-install it for each user?

    mpr130 wrote:
    Help Please.  I am setting up my macbook pro for a second user but office didn't transfer over. Is there a way to have additional users on the same comp have office available without having to re-install it for each user?
    How did you attemp to transfer Office?
    OS X Lion: Set up a guest account

  • Is there a way for 2 ipods to share the same downloaded podcasts?

    Is there a way for 2 ipods to share the same downloaded podcasts?
    Instead of having to download 2 sets and storing 2 sets?

    Sync them both to the same iTunes library.

Maybe you are looking for

  • How to migrate from exchange 2007 to 2013 step by step tutorials please

    Hi I am running Windows Server 2008 standard, with exchange 2007 SP2 on it. We have 800 mailbox in total Our domain controllers are  Win2012 R2 and I would like to upgrade to Exchange 2013 on Windows server 2012 R2. I am running a VM, on VMware envir

  • Mp3 and wmv from Mac to WM 5 handheld

    I have a T-Mobile Dash with Windows Mobile 5. I have about 85 mp3's and a few .wmv video files I'd like to load onto my handheld (I have a memory chip installed)- from my Mac (which is 0S 10.3.9). Missing Sync will not link Windows Mobile 5 to OS 10.

  • First problem since 2009 - Yosemite

    Problem description: I have a fairly old macbook pro, purchased in 2009.  Never had any problems with it but since upgrading to yosemite it takes minutes to boot up, before the download it was seconds.  Also the spinning ball of death shows up at lea

  • More than 255 bytes in SO_NEW_DOCUMENT_ATT_SEND_API1

    I know they are some posts about this topic already but I have read them all but I still don't have the solution. I hope someone could help me with this: The problem is this: I have an internal table and I make an excell file of it which is mailed (s

  • Deleting old flat files inside a SSIS package - SSIS 2005

    Hi, after each flat file import, I need to move the acquired file into an history folder and deleting old files of 1 week ago. How can I cancel these files, acting inside my SSIS 2005 pckg? Many thanks