Multiple key simultaneous presses

Dear people
please does anyone know using the key.isDown handle how many
simultaneous key presses Actionscript 2 can handle, I can't get it
to recognise more than 3 simultaneous max.

I got this to work:
//ctrl + shift + pageUp + pageDwn + End
var myListener:Object = new Object();
myListener.onKeyDown = function() {
if ((Key.isDown(16)) && (Key.isDown(17)) &&
(Key.isDown(33)) &&
(Key.isDown(34)) && (Key.isDown(35))) {
trace("here");
Key.addListener(myListener);
Dan Smith > adobe community expert
Flash Helps >
http://www.smithmediafusion.com/blog/?cat=11
http://www.dsmith.tv
"lajettee" <[email protected]> wrote in
message
news:funaeg$76s$[email protected]..
> Dear people
>
> please does anyone know using the key.isDown handle how
many simultaneous
> key
> presses Actionscript 2 can handle, I can't get it to
recognise more than 3
> simultaneous max.
>
>
>
> if ((Key.isDown(65)) && (Key.isDown(66))
&& (Key.isDown(67)) &&
> (Key.isDown(68))) {
>
> .....do this.....
>
> }
>

Similar Messages

  • Thinkpad keyboard problem - some keys generate multiple keys when pressed

    thinkpad keyboard problem - some keys generate multiple keys when pressed
    For example, "t" generates "tr", "y" generates "yu", "backspace" generates "backspace" plus "IBM access connections", "m" generates "mn" and "n" generates "mn".  Not all keys are wrong. 
    For what it's worth, the odd behaviour started shortly after a trip to Miami in which I had a meeting at a cafe in which we were undercover but it was pouring cats and dogs - it was like having a meeting in a sauna - so I am wondering if the high humidity could have caused the behaviour.
    I tried replacing the keyboard but the new keyboard has the same problem.  
    The machine in question is a Thinkpad T23 running Windows XP Pro
    Any help would be appreciated as I am now in Los Angeles using a borrowed Mac! :-) 

    i have something along the lines of the same problem.
    http://bbs.archlinux.org/viewtopic.php?id=56777
    my conclusion is something in the last system update screwed it up.

  • Bluetooth Wireless Keyboard acting as if keys are pressed

    I've had an Apple Aluminum Bluetooth keyboard for over two years, and last week (after a fresh install of OS X Lion on my late 2009 Mac Mini) all of a sudden the Mac is acting as if multiple keys are pressed when nothing is touching the keyboard. I have updated all software, replaced the batteries, deleted and re-paired the keyboard (which was a massive struggle as it acted as if keys were depressed even during the pairing process). Nothing has ever been spilled on the keyboard. The only way to make the sound of the "phantom depressed key" go away and regain full control of the computer, is to remove the batteries from the keyboard.
    Strangely, the problem seemed to have been resolved somehow after I placed the "Show character viewer" icon in the main menu (ie. where there is usually a US/other nationality flag). After doing so, all of a sudden the problem disappeared.
    Now, exactly a week later, the problem has reappeared.
    Can anyone explain why a keyboard would act this way? Has anyone had a similar problem? Is there a fix?
    I'm a longtime reader of theese support discussion boards, but this is the first time I've posted. Let me know if there's information that I can provide that would help us solve this issue.
    Cheers.

    I have similar issue: both left and right shift keys time to time being pressed, it disappears after a while...but once I couldn't log in as the shift option puts caps lock on....really annoying.
    The only reason in my case is the keyboard cleaning that I have done recently...
    There is no quick fix for this I am afraid.
    Options:
    1.Apple replaces the keyboard you pay around £200 I think....
    2. Buy new keyboard on Ebay and replace it yourself £40....
    http://www.ifixit.com/Guide/MacBook+Pro+13-Inch+Unibody+Mid+2010+Keyboard+Replac ement/23632#s61162
    Anyway lets see.

  • Detecting multiple key presses

    Using the code below I am trying to detect keypresses for a java applet which involves holding down of several keys at once. I have 2 problems, probably related. Firstly I can only detect 3-4 simultaneous keys being held down and secondly the keyPressed and released! events are continually fired while a key is held down not just when it was first pressed as you would think. I would like to be able to detect up to a maximum of 16 keys being held down at once, is this possible? I am working on a unix system in x-windows which I think accounts for the auto-repeat problem, but why am I having trouble detecting multiple simultaneous keys being held down?
    It there a boolean function I can call to check the state of given keys at a given time, that would be very useful?
    Any help is appreciated.
    Ian
    public void keyPressed(KeyEvent e) {
    int keyCode = e.getKeyCode();
    switch(keyCode){
    case java.awt.event.KeyEvent.VK_O: //o
         odown=true;
    break;
    case java.awt.event.KeyEvent.VK_P: //p
         pdown=true;
    break;
    case java.awt.event.KeyEvent.VK_Q: //q
         qdown=true;
    break;
    case java.awt.event.KeyEvent.VK_W: //w
         up=true;
    break;
    case java.awt.event.KeyEvent.VK_A: //a
         left=true;
    break;
    case java.awt.event.KeyEvent.VK_S: //s
         down=true;
    break;
    case java.awt.event.KeyEvent.VK_D: //d
         right=true;
    break;
    }//method keypressed
    public void keyTyped(KeyEvent e) {
    }//method keytyped
    public void keyReleased(KeyEvent e) {
    int keyCode = e.getKeyCode();
    switch(keyCode){
    case java.awt.event.KeyEvent.VK_O: //o
         odown=false;
    break;
    case java.awt.event.KeyEvent.VK_P: //p
         pdown=false;
    break;
    case java.awt.event.KeyEvent.VK_Q: //q
    qdown=false;
    break;
    case java.awt.event.KeyEvent.VK_W: //w
         up=false;
    break;
    case java.awt.event.KeyEvent.VK_A: //a
         left=false;
    break;
    case java.awt.event.KeyEvent.VK_S: //s
         down=false;
    break;
    case java.awt.event.KeyEvent.VK_D: //d
         right=false;
    break;
    }//method keyReleased

    Did you ever find a solution to this problem. I am experiencing a similar problem. I want to be able to disable the auto-repeat function of the keyboard, so that I can tell if the user is holding down the key, or pressing it several times.
    If you have found a solution please let me know at [email protected]
    Thanks,
    Ben Newton

  • How do you register multiple key presses at the same time?

    Hi. I'm trying to write a first person game in OpenGL and I'm having some trouble with key listening. Right now I just use the basic AWT KeyListener. The problem that arises is that whenever I hold down a key, such as a movement key, there is a short pause after it moves me in the appropriate direction, and only after the pause does it start continuously moving me. In addition to that, I can't press multiple keys at once to get diagonal movement (I use WASD for movement). Is there something I can do with AWT to fix both of these problems, or is there something other than AWT that I should use that would be better?

    the pause is the typomatic rate of the keyboard, you can avoid that by using the keyPressed and setting a flag then a sleep(myDelayTime).... if they keyRelease--and clearing of the flag--hasn't happened after the sleep, then you're key is still down so keep firing, moving, or what ever.

  • Multiple Key Pressing

    When I hold Tab + w space doesn't work click (I have my controls set as this for a game).
    Is there anyway to make it so i can hold those two keys and have spacebar work?
    Im on a MacBook Pro Retina 13 inch with latest version of yosemite
    Thanks for the help

    Here is an example of both multiple key press and repeat delay ignore. It is a terrible example of animation. Do not us this animation loop in a game. It will flicker far too much.import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Test extends JFrame implements Runnable {
      boolean upPressed=false, downPressed=false, leftPressed=false, rightPressed=false;
      public Test() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        addKeyListener(new KeyAdapter() {
          public void keyPressed(KeyEvent ke) {
         switch (ke.getKeyCode()) {
           case KeyEvent.VK_UP: upPressed = true; break;
           case KeyEvent.VK_DOWN: downPressed = true; break;
           case KeyEvent.VK_LEFT: leftPressed = true; break;
           case KeyEvent.VK_RIGHT: rightPressed = true; break;
          public void keyReleased(KeyEvent ke) {
         switch (ke.getKeyCode()) {
           case KeyEvent.VK_UP: upPressed = false; break;
           case KeyEvent.VK_DOWN: downPressed = false; break;
           case KeyEvent.VK_LEFT: leftPressed = false; break;
           case KeyEvent.VK_RIGHT: rightPressed = false; break;
        setSize(250,250);
        setVisible(true);
        Thread timer = new Thread(this);
        timer.start();
      public static void main(String[] args) {
        new Test();
      public void run() {
        while (true) {
          repaint();
          try { Thread.sleep(30);} catch (Exception e) {}
      public void paint(Graphics g) {
        g.setColor(Color.white);
        g.fillRect(0,0,getWidth(), getHeight());
        g.setColor(Color.black);
        g.drawString("Up",40,40);
        if (upPressed) g.drawString("Pressed",100,40);
        g.drawString("Down",40,60);
        if (downPressed) g.drawString("Pressed",100,60);
        g.drawString("Left",40,80);
        if (leftPressed) g.drawString("Pressed",100,80);
        g.drawString("Right",40,100);
        if (rightPressed) g.drawString("Pressed",100,100);
    }

  • Multiple key press's with Bluetooth Keyboard

    I'm ready to update my mac to a new G5 imac and fancy getting the wireless bluetooth keyboard and mouse with it.
    I have one question, has anyone experienced problems when holding down multiple keys on the keyboard and moving the mouse all at once (Using illustrator)?
    In my office I have the misfortune of having to use a PC, I have had a number of wireless keyboard and mouse combos, all of them when using Illustrator and photoshop can not handle multiple key press's and mouse movement.
    ie if I'm duplicating an object by dragging a copy of it across the screen, on the PC it will work but it always "releases" after a couple of seconds and drops the copy in the where I don't want it which gets very frustrating (this only happens with wireless).
    As I do a lot of work at home, I hoping this wont be the case with the mac's bluetooth K & M.
    thanks
    Russell

    The shift key works just fine on my Bluetooth keyboard.  So I would imagine this is an issue with your keyboard.

  • Multiple key press

    Hai all
    How can a j2me application withstand multiple key press while doing some process.
    Please help me with some ideas
    Thanks
    Jinesh

    Problem is, Redtruck, I can only get FCP to register one press of t. I can reasign select all tracks forward to a single t but when i go to select track forward and press t it asks me if i want to reassign t to this command and then overrides the select all forward shortcut (which reverts back to tttt automatically).
    I can't seem to find a way to enter multiple "t"s when assigning a shortcut.
    I hope this makes sense (I'm almost confusing myself).

  • Default button being clicked multiple times when enter key is pressed

    Hello,
    There seems to be a strange difference in how the default button behaves in JRE 1.4.X versus 1.3.X.
    In 1.3.X, when the enter key was pressed, the default button would be "pressed down" when the key was pressed, but wouldn't be fully clicked until the enter key was released. This means that only one event would be fired, even if the enter key was held down for a long time.
    In 1.4.X however, if the enter key is pressed and held for more than a second, then the default button is clicked multiple times until the enter key is released.
    Consider the following code (which is just a dialog with a button on it):
    public class SimpleDialog extends JDialog implements java.awt.event.ActionListener
    private JButton jButton1 = new JButton("button");
    public SimpleDialog()
    this.getContentPane().add(jButton1);
    this.getRootPane().setDefaultButton(jButton1);
    jButton1.addActionListener(this);
    this.pack();
    public void actionPerformed(ActionEvent e)
    if (e.getSource() == jButton1)
    System.out.println("button pressed");
    public static void main(String[] args)
    new SimpleDialog().show();
    When you compile and run this code under 1.3.1, and hold the enter key down for 10 seconds, you will only see one print line statement.
    However, if you compile and run this code under 1.4.1, and then hold the enter key down for 10 seconds, you will see about 100 print line statements.
    Is this a bug in 1.4.X or was this desired functionality (e.g. was it fixing some other bug)?
    Does anyone know how I can make it behave the "old way" (when the default button was only clicked once)?
    Thanks in advance if you have any advice.
    Dave

    Hello all,
    I think I have found a solution. The behaviour of the how the default button is triggered is contained withing the RootPaneUI. So, if I override the default RootPaneUI used by the UIDefaults with my own RootPaneUI, I can define that behaviour for myself.
    Here is my simple dialog with a button and a textfield (when the focus is NOT on the button, and the enter key is pressed, I don't want the actionPerformed method to be called until the enter key is released):
    package focustests;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.util.*;
    public class SimpleDialog extends JDialog implements java.awt.event.ActionListener
    private JButton jButton1 = new JButton("button");
    public SimpleDialog()
    this.getContentPane().add(new JTextField("a text field"), BorderLayout.NORTH);
    this.getContentPane().add(jButton1, BorderLayout.SOUTH);
    this.getRootPane().setDefaultButton(jButton1);
    jButton1.addActionListener(this);
    this.pack();
    public void actionPerformed(ActionEvent e)
    if (e.getSource() == jButton1)
    System.out.println("button pressed");
    public static void main(String[] args)
    javax.swing.UIManager.getDefaults().put("RootPaneUI", "focustests.MyRootPaneUI");
    new SimpleDialog().show();
    and the MyRootPaneUI class controls the behaviour for how the default button is handled:
    package focustests;
    import javax.swing.*;
    * Since we are using the Windows look and feel in our product, we should extend from the
    * Windows laf RootPaneUI
    public class MyRootPaneUI extends com.sun.java.swing.plaf.windows.WindowsRootPaneUI
    private final static MyRootPaneUI myRootPaneUI = new MyRootPaneUI();
    public static javax.swing.plaf.ComponentUI createUI(JComponent c) {
    return myRootPaneUI;
    protected void installKeyboardActions(JRootPane root) {
    super.installKeyboardActions(root);
    InputMap km = SwingUtilities.getUIInputMap(root,
    JComponent.WHEN_IN_FOCUSED_WINDOW);
    if (km == null) {
    km = new javax.swing.plaf.InputMapUIResource();
    SwingUtilities.replaceUIInputMap(root,
    JComponent.WHEN_IN_FOCUSED_WINDOW, km);
    //when the Enter key is pressed (with no modifiers), trigger a "pressed" event
    km.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ENTER,
    0, false), "pressed");
    //when the Enter key is released (with no modifiers), trigger a "release" event
    km.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ENTER,
    0, true), "released");
    ActionMap am = SwingUtilities.getUIActionMap(root);
    if (am == null) {
    am = new javax.swing.plaf.ActionMapUIResource();
    SwingUtilities.replaceUIActionMap(root, am);
    am.put("press", new HoldDefaultButtonAction(root, true));
    am.put("release", new HoldDefaultButtonAction(root, false));
    * This is a copy of the static nested class DefaultAction which was
    * contained in the JRootPane class in Java 1.3.1. Since we are
    * using Java 1.4.1, and we don't like the way the new JRE handles
    * the default button, we will replace it with the old (1.3.1) way of
    * doing things.
    static class HoldDefaultButtonAction extends AbstractAction {
    JRootPane root;
    boolean press;
    HoldDefaultButtonAction(JRootPane root, boolean press) {
    this.root = root;
    this.press = press;
    public void actionPerformed(java.awt.event.ActionEvent e) {
    JButton owner = root.getDefaultButton();
    if (owner != null && SwingUtilities.getRootPane(owner) == root) {
    ButtonModel model = owner.getModel();
    if (press) {
    model.setArmed(true);
    model.setPressed(true);
    } else {
    model.setPressed(false);
    public boolean isEnabled() {
    JButton owner = root.getDefaultButton();
    return (owner != null && owner.getModel().isEnabled());
    This seems to work. Does anyone have any comments on this solution?
    Tjacobs, I still don't see how adding a key listeners or overriding the processKeyEvent method on my button would help. The button won't receive the key event unless the focus is on the button. There is no method "enableEvents(...)" in the AWTEventMulticaster. Perhaps you have some code examples? Thanks anyway for your help.
    Dave

  • IBook G4 – multiple characters show up when a single key is pressed

    My iBook G4 was recently in a fire at my apartment. I lost everything but my laptop happened to be lying on the floor and was undamaged by heavy amounts of smoke and soot. I cleaned the exterior of the iBook up with a soft damp cloth. I used this on the keypad as well.
    After the fire and cleanup the keyboard is acting erratic. When I press "p" for example I get an input of "p0-" or "p[9" Obviously multiple keys are being pressed down at once but there isn't any particles or trash in the keys as far as I can tell. I've lifted out the keypad and blown it out (with my lungs) and have yet to purchase any compressed air to try this method further.
    The strange thing is that sometimes the keyboard works just fine. Moments later, however, multiple keys will begin being pressed.
    Has anyone had this issue?
    As a side note, does anyone have any hints on removing the smoke smell from an apple product (white plastic) that's been in a house fire?
    Thanks in advance,
    Jenkin

    You say it wasn't damaged in the fire, but it sounds like it's possible that the heat maybe "welded" the 2 top rows' keys together, or did it get wet when the fire was being put out? It's possible that a new keyboard might fix the problem, but you should look first at the cable that connects it and inspect it for damage.
    Take the keyboard out and see if you can see something catching when you press the QWERTY keys. Also using compressed air to blow it out would be worth a try.

  • Recognizing multiple key presses in As3

    Hi,
    I have a simple game with three keyboard inputs - left, right and fire
    I want to be able to log when a key is pressed and released. In the game, you can be in the following states:
    None
    Left only - keyz on the keyboard
    Right only - keyc on the keyboard
    Fire only - keyx on the keyboard
    Left and Fire - keyz and Keyx on the keyboard
    Right and Fire - Keyc and Keyx on the keyboard
    When Left key is pressed for example, it should log LeftKeypressStart and when it is released, it shoul log leftKeyPressStop. The same should happen to Right and Fire keys when they are pressed individually.
    Now, for the game to be in  Left and Fire state either of the three conditions are true:
    Left key can be pressed and held down before the fire button is pressed and held down or
    Fire button is pressed and held down before left is pressed and held down or
    Both keys pressed down simultenuosly (although this condition will rarely occur as we are not robots)
    Similar conditions should be true for the game to be in the Right and Fire State
    Now considering the first condition,when Left key is down, I want the game to log LeftKeypressStart but as soon as the Fire key is down, it should log LeftKeyPressStop and also Log LeftandFireKeypressStart. Then if Fire is released first, I want it to log LeftandFirKeypressStop and then log LeftKeyStart. but if Left is released first, it should log  LeftandFirKeypressStop and then lof FireKeyPressStart.
    This is what I have at the minute:
    private function onKeyPress (evt:KeyboardEvent)
    if (evt.keyCode == 67 && evt.keyCode !=88 && evt.keyCode != 90)
    //log Right  
    else if (evt.keyCode != 67 && evt.keyCode !=88 && evt.keyCode == 90 )
    //log Left
    else if (evt.keyCode != 67 && evt.keyCode !=90 && evt.keyCode == 88)
    //log Fire
    else if (evt.keyCode == 67 && evt.keyCode !=90 && evt.keyCode == 88 )
    //log RF
    private function onKeyRelease(evt:KeyboardEvent)
    if (evt.keyCode == 67 && evt.keyCode !=88 && evt.keyCode != 90)
    //stop right
    else if (evt.keyCode != 67 && evt.keyCode !=88 && evt.keyCode == 90 )
    //stop Left
    else if (evt.keyCode != 67 && evt.keyCode !=90 && evt.keyCode == 88)
    //stop Fire
    else if (evt.keyCode == 67 && evt.keyCode == 88  && evt.keyCode !=90 )
    // stop RF    

    There can only be one evt.keyCode per keypress, so your approach will not work.  All you need to do is determine which key caused the function to execute.  If you want to keep track of which keys are down, just create three Boolean variables, as in...
    var leftDown:Boolean = false;
    var rightDown:Boolean = false;
    var fireDown:Boolean = false;
    and set those values to true or false and make use of them in whatever other code you intend.
    private function onKeyPress (evt:KeyboardEvent)
    if (evt.keyCode == 67)
                 rightDown = true  
    else if (evt.keyCode ==88)
                 leftDown = true
    else if (evt.keyCode == 88)
                 fireDown = true
    // process per whatever values are true/false
    and in the key up function set them back to false in a similar fashion.

  • How come multiple audiotags in ebook can play all together in the last version of ibooks and ios6 while before they fade eachother when play key is pressed ?

    in ipad1 with ios5.1.1 and latest ibooks app audiotags stop the last music played when the new music starts
    in ipad3 with ios6 and latest ibooks let all the music play together with a resulting mess
    in ipad2 with ios6  ibooks fade the last tag that is playing when the play key is pressed in the new audiotag

    Gah. So It looks like the first version of the song on your iPod is the definitive version of a song (as is the case in iTunes). So in order to ensure that the version you want plays, you have to:
    1. make that the only version in iTunes (or first in the file structure)
    2. update Genius
    3. sync your iPod
    BOO. Too much work (I'm still going to do it though...)
    I would really like a feature that allowed you to specify which song would be chosen (the existing rating system would seem to be easiest).
    Another solution I thought of still requires a lot of work. This is assuming you prefer It would go something like this:
    1. Create an directory structure at the root of your library that would prioritize tracks, such as:
    a) Albums (for full length albums)
    b) Collections (for best ofs etc.)
    c) EPs (for singles or remix albums)
    e) Live Performances
    -assuming you prefer album versions over remixes over live versions, or more directly:
    a) High Priority
    b) Low Priority
    2. Place Each Album or individual tracks in their appropriate folder.
    3. Reset your iPod
    4. Sync
    The directory structure will intrinsically place higher priority versions on you iPod first, making them a priority version there. Pain in the...

  • IsKeyDown - Multiple key detection ?

    does anyone know of how to read two keys or check two keys are down/pressed?
    I am trying to do a game where the object can mover diagonally so i need the game to react differently if 2 cursor keys are down?
    Any ideas about the isKeyDown() function?
    The keypressed/ keyreleased function i think will only detect one at a time.
    cheers all

    Try this quick Swing App I knocked up using Sun One. It shows multiple key detection, doesn't mind simultaneous key presses.
    I wrote the code for clarity more than anything else.
    Run it, see what it does and how it reacts to the cursor keys being pressed.
    * KeyEvents.java
    * Created on 05 December 2002, 16:21
    package andy.apps.KeyEvents;
    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.*;
    public class KeyEvents extends javax.swing.JFrame {
        /** Creates new form KeyEvents */
        public KeyEvents() {
            initComponents();
            upPanel.registerKeyboardAction(new UpOnListener(), KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0, false), JComponent.WHEN_IN_FOCUSED_WINDOW);
            upPanel.registerKeyboardAction(new UpOffListener(), KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0, true), JComponent.WHEN_IN_FOCUSED_WINDOW);
            downPanel.registerKeyboardAction(new DownOnListener(), KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0, false), JComponent.WHEN_IN_FOCUSED_WINDOW);
            downPanel.registerKeyboardAction(new DownOffListener(), KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0, true), JComponent.WHEN_IN_FOCUSED_WINDOW);
            leftPanel.registerKeyboardAction(new LeftOnListener(), KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0, false), JComponent.WHEN_IN_FOCUSED_WINDOW);
            leftPanel.registerKeyboardAction(new LeftOffListener(), KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0, true), JComponent.WHEN_IN_FOCUSED_WINDOW);
            rightPanel.registerKeyboardAction(new RightOnListener(), KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0, false), JComponent.WHEN_IN_FOCUSED_WINDOW);
            rightPanel.registerKeyboardAction(new RightOffListener(), KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0, true), JComponent.WHEN_IN_FOCUSED_WINDOW);
        class UpOnListener implements ActionListener {
            public void actionPerformed(ActionEvent e) {
                KeyEvents.this.upPanel.setBackground(Color.black);
        class UpOffListener implements ActionListener {
            public void actionPerformed(ActionEvent e) {
                KeyEvents.this.upPanel.setBackground(Color.white);
        class DownOnListener implements ActionListener {
            public void actionPerformed(ActionEvent e) {
                KeyEvents.this.downPanel.setBackground(Color.black);
        class DownOffListener implements ActionListener {
            public void actionPerformed(ActionEvent e) {
                KeyEvents.this.downPanel.setBackground(Color.white);
        class LeftOnListener implements ActionListener {
            public void actionPerformed(ActionEvent e) {
                KeyEvents.this.leftPanel.setBackground(Color.black);
        class LeftOffListener implements ActionListener {
            public void actionPerformed(ActionEvent e) {
                KeyEvents.this.leftPanel.setBackground(Color.white);
        class RightOnListener implements ActionListener {
            public void actionPerformed(ActionEvent e) {
                KeyEvents.this.rightPanel.setBackground(Color.black);
        class RightOffListener implements ActionListener {
            public void actionPerformed(ActionEvent e) {
                KeyEvents.this.rightPanel.setBackground(Color.white);
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        private void initComponents() {
            upPanel = new javax.swing.JPanel();
            leftPanel = new javax.swing.JPanel();
            downPanel = new javax.swing.JPanel();
            rightPanel = new javax.swing.JPanel();
            getContentPane().setLayout(new java.awt.GridLayout(2, 2));
            addWindowListener(new java.awt.event.WindowAdapter() {
                public void windowClosing(java.awt.event.WindowEvent evt) {
                    exitForm(evt);
            upPanel.setBorder(new javax.swing.border.TitledBorder("Up"));
            upPanel.setBackground(new java.awt.Color(255, 255, 255));
            getContentPane().add(upPanel);
            leftPanel.setBorder(new javax.swing.border.TitledBorder("Left"));
            leftPanel.setBackground(new java.awt.Color(255, 255, 255));
            getContentPane().add(leftPanel);
            downPanel.setBorder(new javax.swing.border.TitledBorder("Down"));
            downPanel.setBackground(new java.awt.Color(255, 255, 255));
            getContentPane().add(downPanel);
            rightPanel.setBorder(new javax.swing.border.TitledBorder("Right"));
            rightPanel.setToolTipText("null");
            rightPanel.setBackground(new java.awt.Color(255, 255, 255));
            getContentPane().add(rightPanel);
            pack();
        /** Exit the Application */
        private void exitForm(java.awt.event.WindowEvent evt) {
            System.exit(0);
         * @param args the command line arguments
        public static void main(String args[]) {
            new KeyEvents().show();
        // Variables declaration - do not modify
        private javax.swing.JPanel upPanel;
        private javax.swing.JPanel leftPanel;
        private javax.swing.JPanel rightPanel;
        private javax.swing.JPanel downPanel;
        // End of variables declaration
    }

  • Moving Sprite with arrow keys, simultaneous directions

    Hi everyone.
    I'm trying to create a small arcade style game, you control a
    small ship, shoot at incoming targets, try to dogde their shots,
    etc. I'm working on the ship's movement right now, using the arrow
    keys to control it. Getting it to move one direction at a time is
    easy, but sometimes I need to move it diagonally, otherwise I think
    gameplay will suffer considerably.
    I have tried several things but I never seem to be able to
    tell Flash that two keys are being pressed simultaneously. Can
    anyone tell me how I might achieve this?
    Thank you.

    This format should allow detection of multiple keys at once:
    stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
    function keyPressed(ev:KeyboardEvent):void {
    var pressedKey:uint = ev.keyCode;
    if(pressedKey == Keyboard.LEFT) {
    leftDown = true;
    if(pressedKey == Keyboard.RIGHT) {
    rightDown = true;
    if(pressedKey == Keyboard.UP) {
    upDown = true;
    if(pressedKey == Keyboard.DOWN) {
    downDown = true;
    ship.addEventListener(Event.EnterFrame, moveShip);
    }

  • How to get Multiple Key Combinations

    Hi,
    I am trying to get the event for multiple key combinations, ie some thing like "*Ctrl + I + M*" or "*Alt + A + S + D*".
    For two key combinations ( like Ctrl+I or Ctrl+M) i am able to get, but for more than two keys combinations, can someone give an idea how to get it.
    I tried with both KeyCodeCombination and KeyCharacterCombination.
    Below is a quick example to check for the key combination demo.
    import javafx.application.Application;
    import javafx.event.EventHandler;
    import javafx.scene.Scene;
    import javafx.scene.control.Label;
    import javafx.scene.input.KeyCharacterCombination;
    import javafx.scene.input.KeyCode;
    import javafx.scene.input.KeyCodeCombination;
    import javafx.scene.input.KeyCombination;
    import javafx.scene.input.KeyEvent;
    import javafx.scene.layout.StackPane;
    import javafx.scene.paint.Color;
    import javafx.stage.Stage;
    public class KeyCombinationDemo extends Application {
         Stage stage;
         Scene scene;
         StackPane root;
         public static void main(String[] args) {
              Application.launch(args);
         @Override
         public void start(Stage stage) throws Exception {
              this.stage = stage;
              root = new StackPane();
              root.getChildren().add(new Label("Enter any Key"));
              this.scene = new Scene(root, Color.LINEN);
              stage.setTitle(this.getClass().getSimpleName());
              stage.setWidth(600);
             stage.setHeight(600);
             stage.setScene(this.scene);
             stage.show();
              final KeyCombination keyComb1=new KeyCodeCombination(KeyCode.I,KeyCombination.CONTROL_DOWN);
              final KeyCharacterCombination keyComb2 = new KeyCharacterCombination("M",KeyCombination.CONTROL_DOWN);
              this.scene.addEventHandler(KeyEvent.KEY_RELEASED, new EventHandler<KeyEvent>() {
                   @Override
                   public void handle(KeyEvent event) {
                        if(keyComb1.match(event)){
                             System.out.println("Ctrl+I pressed");
                        }else if(keyComb2.match(event)){
                             System.out.println("Ctrl+M pressed");
    }Thanks in Advance.
    Regards,
    Sai Pradeep Dandem.

    Hi John,
    Thanks for the prompt response.
    I tried the way you suggested and it worked well !! Thanks :)
    But, still i am expecting a direct way to handle this. :p
    Anyway here is code which i modified accordingly
    final String keyCombination1 = "_ALT_E_O";
    final String keyCombination2 = "_ALT_E_P";
    final String keyCombination3 = "_CONTROL_H";
    final StringBuilder key = new StringBuilder();
    this.scene.addEventHandler(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() {
         @Override
         public void handle(KeyEvent event) {
              String codeStr = event.getCode().toString();
              if(!key.toString().endsWith("_"+codeStr)){
                   key.append("_"+codeStr);
    this.scene.addEventHandler(KeyEvent.KEY_RELEASED, new EventHandler<KeyEvent>() {
         @Override
         public void handle(KeyEvent event) {
              if(key.length()>0){
                   if(key.toString().equals(keyCombination1)){
                        System.out.println("Key Combination 1 pressed");
                   }else if(key.toString().equals(keyCombination2)){
                        System.out.println("Key Combination 2 pressed");
                   }else if(key.toString().equals(keyCombination3)){
                        System.out.println("Key Combination 3 pressed");
                   key.setLength(0);
    });Thanks & Regards,
    Sai Pradeep Dandem

Maybe you are looking for

  • How to set an alerting substitution for another user as admin?

    Dear experts, having the case on of our employees went on vaction without entering a substitution for his alerts. How can I as an administrator setup a substitution for the alerts of this user? Thanks in advance, BR Matthias

  • External hard disk for use with quicksilver 2002 and intel imac 24"

    i am wanting to purchase an external hard disk to be used with both a g4 and an intel imac 24". i am considering a seagate barracuda 500gb or 750gb and purchasing an external case separately. interfaces - usb2, firewire 400 and 800. Do I need a case

  • Organizer - how do I fix missing thumbnails?

    After processing RAW files in PE9 and saving as JPEG's, there seems to be a random number of resulting files which fail to show as thumbnails in Organizer. Instead there's the grey flower/exclamation mark thumbnail. The file clearly exists - Properti

  • I am not able to access my contacts, calendar on icloud

    I am not able to access my contacts, calendar on icloud.  I get the message"unable to load...There was aproblem loading the application"  Any ideas?  I have an iphone 4 and am using Windows Vista.  Had no problems before

  • Connections from other applications.

    Hello, Is there any parameter we can set to control the number of connections from an external application. I am using J2EE application server connection pool to connect to Oracle from Java. In Applciation server setting we can configure the number o