Two keypresses

Hello!
I'm new to Java 3D (I've been messing with it for quite a while, but have only recently committed to learning it). I'm trying to make a simple program that follows a sphere around with a third-person camera. Thus far, everything works: The sphere moves forward and backward and rotates side to side by the arrow keys.
Of course, the movement is triggered by my behavior class, waking up on AWTEvents. Is there a way to make it respond to more than one key press (i.e. to cause the ball to rotate and move forward at the same time)? Generally, in 2D apps, I store the keypresses in boolean variables and use a thread to cause movement (the AWTEvent queue only updates the booleans). How can I implement this in a Java 3D app?
Thanks in advance.

I haven't been able to do it with keyEvent but you could try using mousePressed in the MouseEvent Class or use an action listener

Similar Messages

  • [solved] xorg 1.8 strange keyboard behavior

    I've updated to xorg 1.8 on my MSI VR630 laptop.
    But now some keys trigger two keypress events.
    Examples:
    * [Del] triggers [Del] and [Print]
    * [Down] triggers [Down] and [Enter]
    * [Ins] triggers [Ins] and [/]
    and so on.
    EDIT:
    I overlooked that kbd setings had been overwritten by /etc/X11/xorg.conf.d/10-evdev.conf.
    Had to disable evdev keyboard section.
    Last edited by ColdSphinX (2010-05-13 13:10:07)

    Nothing ?
    Switchng off hal deamon and cleaning ~/.kde* has no effect...
    So, after searching on google again an again, still nothing found.... even among the Ubuntu specific issue where post are terminated
    with "wait next version of the package", the windows-style answer.
    I will continue my attempts to fix this... but my conclusion about this is that hal was more precise in his behavior than udev...

  • Event help please!!!

    Hello
    In a game I am currently making I have had some problems with The keyPressed() and keyReleased() methods. If i press spacebar to fire (its in keyReleased()) while i'm moving, my ship will stop (since the moving is controlled with keyPressed()). Also, on my computer I can move diagonally (ie hold two keys at once) but on my friends computer he can't. Third, my high score screen glitches if SHIFT is held down. So here are my questions:
    Is there any way to use keyPressed() and keyReleased() at the same time, or do they always conflict?
    Why is my friend's computer not registering two keyPressed()s at the same time, and is there any way i can fix this?
    Is there any way to check if a key pressed/released/hit is a key that gives a valid ASCII character?
    Any help is truly appreciated!!!

    You need another thread I am betting. You should not do any work in the event thread. just get the data out of the event thread but your work should all be done in another thread, or else just what you are talking about will happen. when the event thread is interrupted, your app will stop.

  • HT201794 spanish keyboard on american imac

    I live and bought my MAC in USA, however, I bought a keyboard Mexico to be able to use all the special characters in the Spanish vocabulary but my MAC does not respond to the characters I type. I have tried changing the keybord settings in System Preferences but haven't been succesful.

    System Preferences / Language & Text / Input Sources
    Tick Keyboard & Character Viewer as well as Spanish and Spanish - ISO. When that is done, a little flag will pop in the menubar. There you will find which keyboard layout is active, US will always be there. Using the Keyboard Viewer also found there, you will need to experiment which of the two Spanish layouts matches your keyboard. The Keyboard Viewer will also show you were all the characters are laid out, including those that require two keypresses: just hold down Option and see which keys light up in dark yellow.

  • 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 :)

  • Major issues with keypress being necessary

    We are outsourcing development of an application (image
    viewer) in FL2.0 and have come up against a big brick wall.
    The viewer is supposed to download an image when first run,
    however it will not. After debugging in ADC these two errors are
    shown: FTPA016/FTPA017
    Can
    be seen here->
    It seems that (perhaps only in Japan which is our target
    audience) data cannot be downloaded unless there is a keypress from
    the user. I guess this is to prevent movies from running up user
    bills without them knowing about it. The thing is we have put in a
    fix so that the user needs to press # twice and they should be able
    to see the image. However nothing happens.
    I wonder if anyone has come up against this issue before?
    Any help would be much appreciated.

    This forum is primarily to help people who have problems downloading, installing, and/or setting up Adobe software.  Your posting appears to focus on a problem with using some Adobe software, though it is not clear which one(s).  Your best bet will be to post in the appropriate product forum.  If you need help finding the right product forum, there is a drop down list on the page linked below where you can navigate to all of the forums.
    http://forums.adobe.com/index.jspa?view=discussions
    There is a Creative Suites forum in that list as well if your problem involves suite level matters.

  • Help on simple two player Pong!!

    I am fairly new to java. But I know quit a bit already. I want my to write a program that is just pong and has two paddles. One player controls one and the second player controls the other. Can anyone help me with it here is my code: ( I have tryed a switch statement for handling the keyboard but it doesn't work can anyone help me?)
    import java.awt.*;
    public class Pong extends java.applet.Applet
              int x = 245;
              int y = 145;
              int xVelocity = 3;
              int yVelocity = 3;
              int playerOneY = 105;
              int playerOneY2 = 110;
              int playerTwoY = 105;
              int playerTwoY2 = 110;
              Color ballColor = new Color(25, 120, 190);
              Color panelColor = new Color(220, 35, 70);
         public void paint(Graphics g)
                   while(true)
                   g.setColor(panelColor);
                   g.fillRect(0,playerOneY,5,playerOneY2);
                   g.fillRect(495,playerTwoY,500,playerTwoY2);     
                   g.setColor(Color.lightGray);
                   g.fillRect(0,305,510,310);
                   g.fillRect(0,0,510,5);
                   g.setColor(Color.white);
                   g.fillOval(x,y,25,25);
                   x += xVelocity;
                   y += yVelocity;
                   g.setColor(ballColor);
                   g.fillOval(x,y,25,25);
                   // bounces off paddles
                   if((y < playerOneY) && (y > playerOneY2))
                        if(x<0)
                             xVelocity = +xVelocity;     
                   if((y < playerTwoY) && (y > playerTwoY2))
                        if(x>500)
                             xVelocity = -xVelocity;
                   //bounce off top walls
                   if((y > 285) || (y < 25))
                        yVelocity = -yVelocity;     
                   if((y < 0) || (y > 285))
                        yVelocity = +yVelocity;
                   g.setColor(ballColor);
                   g.fillOval(x,y,25,25);
                   for(int i=0; i<20000000; i++);
                   repaint();
    }

    Heres soem suggestions.... To to keyboard interaction, you need to import java.awt.event.*
    then have your class implement KeyListener or use a KeyAdapter , then addKeyListener(this) in the constructor or else where, then implement each of the key event methods, but just use the keyPressed(KeyEvent e) method, then in that, get the key code, like this:
    public void keyPressed(KeyEvent e)
            int key = e.getKeyCode() //gets the code of the key pressed
             switch(key)
                     case KeyEvent.VK_LEFT: blahblah();  break;
    }

  • Problem w/sql and two sequential select stmts

    hi,
    i'm way over my head with this pl/sql. i'm really
    an application devleoper but our db person left me hanging.
    any help appreciated.
    i (think) need two sequential sql statements. i
    know a record's id in the "Master" table. using the
    record id i need to look up the "subTbl" name from
    the "Master" table. now i know the name of the
    "subTbl" but have to use that in the select from
    "subTbl". i can't seem to get the nested select
    statments correct. my subTable is dynamic (could be one
    of 15-18 tbls) and they all have different schema.
    i'm not sure how to take that "subTbl"
    value and extract the clob from the sub table...
    please help me oh sql wizards!
    thanks,
    craig
    Master
    ======
    id | subTbl | createDate
    1 "A" blah
    2 "B" blah
    3 "A" blah
    A
    =
    id | f1 | f2 | f3 | f4 | clob
    1 x x x x stuff1
    3 x x x x stuff3
    B
    =
    id | f1 | f5 | f6 | f7 | clob
    2 x x x x stuff2
    C .... there are many sub-Tables
    =
    null

    I just wanted to comment on this thread in case anyone else comes across it while searching for streamzap issues. Thanks to the OP I used his config, but I spent the past 2 hours pulling my hair out trying to figure out why I couldn't get it to work even though everything seemed to be working in IRW and even the XBMC log was showing keypresses from the remote. Turns out there is a couple errors in the OP's config which was borking the whole config file.
    <forward>>></forward>
    <reverse><<</reverse>
    <skipplus>>>|</skipplus>
    <skipminus>|<<</skipminus>
    The way these are presented with the  "<<" it screws up the xml coding. I personally just removed those entries and that fixed it for me, but I think if you want to use those buttons you need to use the ascii codes for those symbols.
    Hope this helps someone else. :-)
    kevin

  • Problems with the slight delay of keyPressed.

    Hi all!
    I just joined the wonderful sdn network, so HELLO EVERYONE :D
    I studyed some java in unversity, but never in depth, and ive recently found myself yearning after it, so recently i decided to try and teach myself!
    Unfortuantly ive hit abit of a problem, im trying to make a pacman game, hopfully develop it beyond the original and make it more innovative.
    Ive come across two problems
    1. My applet doesnt seem to have any focus until ive clicked onto it - i cant figure out what needs the focus and which focus method i should use or where the code should go!
    2. Although ive got my pacman displayed with a nice munching motion (which im quite proud of ^_^ ) and he moves when the specific keys are pressed, theres a slight delay when i try and change direction, or when i first keyPress. Hopefully you can see what i mean when you run my code, or maybe you already know what im talking about!
    I have a feeling its to do with the keyPressed code, since it only kicks in when the key is down, rather then when its keyDowning(if thats even a word!) is there a way to remove that delay so movement is seamless?
    So id be very grateful if you could advise me on what my first mistake was, and what i could do with my second problem!
    Thank you, my code is below, and please feel free to share some POSTIVE critisim, on my code, or advice on what steps to take next or in coding in general!
    CHEERS!
    sskenth
    4 classes - AnimationThread, Pacman, PaintSurface, Room
    import java.applet.*;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.geom.*;
    class AnimationThread extends Thread
         JApplet c;
         int threadSpeed = 20; // this allows the pacman speed to be reduced i.e. negative slow pill... change to 100 for slow!
         public AnimationThread(JApplet c)
              this.c=c;
         public void run()
              while(true)
                   c.repaint();
                   try
                        Thread.sleep(threadSpeed);
                   catch(InterruptedException ex)
                        //swallow the exception
    import java.awt.geom.*;
    import java.awt.event.*;
    class Pacman extends Arc2D.Float //implements KeyListener //setArc(double x, double y, double w, double h, double angSt, double angExt, int closure)
              private int diameter;
              private int x_speed,y_speed;
              private int width = Room.WIDTH;
              private int height = Room.HEIGHT;
              private     int mouth = 10;// mouth is the amount it opens by! -1 is opening, +1 is closing
                             // mouth - =1 makes it spin!
              public Pacman(int diameter)
                   super((int)(Math.random() * (Room.WIDTH - 20) + 1), (int)(Math.random() * (Room.HEIGHT - 20) + 1),diameter,diameter,210,300,2);
                   this.diameter = diameter;
                   //this.x_speed = (int)(Math.random()*5+1);
                   //this.y_speed = (int)(Math.random()*5+1);
                   this.x_speed = 10;
                   this.y_speed = 10;
         public void move(int e)
                   if(e == KeyEvent.VK_UP)
                   this.setAngleStart(120);
                   super.y -=y_speed;
                   if(e == KeyEvent.VK_DOWN)
                   this.setAngleStart(300);
                   super.y +=y_speed;
                   if(e == KeyEvent.VK_LEFT)
                   this.setAngleStart(210);
                   super.x -=x_speed;
                   if(e == KeyEvent.VK_RIGHT)
                   this.setAngleStart(30);
                   super.x +=x_speed;
                   //System.out.println(direction);
              public void mouth()
                        if(this.getAngleExtent()  >= 360)
                        mouth = -10;
                        if(this.getAngleExtent()  <= 270)
                        mouth = 10;
                   double angExt = this.getAngleExtent();
                   this.setAngleExtent(angExt +=mouth);
                   //     System.out.println(getAngleExtent());
    import java.awt.event.*;
    import java.applet.*;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.geom.*;
    import java.util.*;
    class PaintSurface extends JComponent
              public ArrayList<Pacman> pacmans = new ArrayList<Pacman>();
              public static Pacman pacman;
              public PaintSurface()
                    pacman = new Pacman(50); //diameter of pacman
                   //for(int i = 0; i <10; i++)
                        //pacmans.add(new Pacman(50));
              public void paint (Graphics g)
                   Graphics2D g2 = (Graphics2D)g;
                   g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
                   //g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.50F)); //adds transparency
                   g2.setColor(Color.YELLOW);
                   //for(Pacman pacman: pacmans)
                        //pacman.move();
                        pacman.mouth();
                        g2.fill(pacman);
    import java.applet.*;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.geom.*;
    import java.awt.event.*;
    public class Room extends JApplet implements KeyListener
              public static final int WIDTH = 1000;
              public static final int HEIGHT = 300;
              private PaintSurface canvas;
              public void init()
                   this.setSize(WIDTH, HEIGHT);
                   canvas = new PaintSurface();
                   this.add(canvas,BorderLayout.CENTER);
                   Thread t = new AnimationThread(this);
                   t.start();
                   addKeyListener(this);
                   //canvas.requestFocus();
                   this.requestFocusInWindow();
              //frame.pack();  //Realize the components.
                  //This button will have the initial focus.
                 // button.requestFocusInWindow();
              public void keyReleased(KeyEvent e)
                             //System.out.println("KeyRELEASED "+e);
                             //int keyCode = e.getKeyCode();
                             //     PaintSurface.pacman.move(keyCode);
                        public void keyPressed(KeyEvent e)
                        //System.out.println("KeyRELEASED "+e);
                        int keyCode = e.getKeyCode();
                                  PaintSurface.pacman.move(keyCode);
                        public void keyTyped(KeyEvent e)

    Well i did as you both said, and it worked! thought id just put the code up for anyone who was wondering what it looked like, just replace the pacman class above with this new one and start the thread!
    import java.awt.geom.*;
    import java.awt.event.*;
    class Pacman extends Arc2D.Float implements Runnable //implements KeyListener //setArc(double x, double y, double w, double h, double angSt, double angExt, int closure)
              private int diameter;
              public int x_speed,y_speed;
              private int width = Room.WIDTH;
              private int height = Room.HEIGHT;
              private     int mouth = 10;// mouth is the amount it opens by! -1 is opening, +1 is closing
                             // mouth - =1 makes it spin!
              public static String direction;
              public Pacman(int diameter)
                   //super((int)(Math.random() * (Room.WIDTH - 20) + 1), (int)(Math.random() * (Room.HEIGHT - 20) + 1),diameter,diameter,210,300,2);
                   super(100 , 100,diameter,diameter,210,300,2);
                   this.diameter = diameter;
                   //this.x_speed = (int)(Math.random()*5+1);
                   //this.y_speed = (int)(Math.random()*5+1);
                   this.x_speed = 10;
                   this.y_speed = 10;
                   //Thread t = new GameLoop(this);
                   //t.start();
         public void move(int e)
                   if(e == KeyEvent.VK_UP)
                   this.setAngleStart(120);
                   direction = "UP";
                   //movement();
                   //super.y -=y_speed;
                   if(e == KeyEvent.VK_DOWN)
                   this.setAngleStart(300);
                   direction = "DOWN";
                   //movement();
                   //super.y +=y_speed;
                   if(e == KeyEvent.VK_LEFT)
                   this.setAngleStart(210);
                   direction = "LEFT";
                   //movement();
                   //super.x -=x_speed;
                   if(e == KeyEvent.VK_RIGHT)
                   this.setAngleStart(30);
                   direction = "RIGHT";
                   //movement();
                   //super.x +=x_speed;
         /*public void move(String s)
                   if(direction == "UP")
                   super.y -=y_speed;
                   if(direction == "DOWN")
                   super.y +=y_speed;
                   if(direction == "LEFT")
                   super.x -=x_speed;
                   if(direction == "RIGHT")
                   super.x +=x_speed;
              public void mouth()
                        if(this.getAngleExtent()  >= 360)
                        mouth = -10;
                        if(this.getAngleExtent()  <= 270)
                        mouth = 10;
                   double angExt = this.getAngleExtent();
                   this.setAngleExtent(angExt +=mouth);
                   //     System.out.println(getAngleExtent());
              public void movement()
                   if(direction == "UP")
                   super.y -=y_speed;
                   if(direction == "DOWN")
                   super.y +=y_speed;
                   if(direction == "LEFT")
                   super.x -=x_speed;
                   if(direction == "RIGHT")
                   super.x +=x_speed;
                        if((direction == null) || (direction  ==""))
         public void run()
              while(true)
                        movement();
                   if((direction == null) || (direction  ==""))
                   try
                        Thread.sleep(20);
                   catch(InterruptedException e)
    }

  • [BUG] first keypress when screen is dim does not go through

    If you have a program such as Messaging open and let the screen dim by not being active for a while and then go to enter text, the first keypress is lost.  It appears that the first keypress resets the screen timer and brings the brightness back up to full, but this can be disruptive for a user who is trying to enter text.  The problem is exacerbated by the fact that the second keypress causes a capital letter to be entered, requiring two presses of the backspace key to remove the letter and start again.
    Post relates to: Pre p100eww (Sprint)

    If the phone is activated you dial either 999 or 112 within the UK .
    Don't rely on the emergency button it's not supported by UK mobile operators
    112 works everywhere in the EU though the UK don't advertise the fact which I stupid.

  • Event handling betwwen two canvas classes

    Hi again!
    I have two canvas classes: MainCanvas and SubCanvas.
    SunCanvas has keyPressed() method implemented and it's working perfectlly. The only problem is when a certain key is pressed, say Select, I want MainCanvas to be notified.
    anybody have an idea?
    I tried with CommandListener but I can't work it out. Can i 'active' an event through Cammandlistener maybe?
    cheers
    Indy

    You have two choices here.
    The first is like you said using CommandListener. If you add a Command to your SubCanvas, and then set the MainCanvas as the CommandListener, then the MainCanvas gets notified if the command is selected through the commandAction() method:
    class SubCanvas extends Canvas {
      Command something = new Command("Hi",Command.OK,1);
      public SubCanvas(MainCanvas mc) {
        addCommand(something);
        setCommandListener(mc);
    class MainCanvas extends Canvas implements CommandListener {
      public void commandAction(Command c, Displayable d) {
    }The second option is to keep a reference to the MainCanvas instance in SubCanvas, and use this reference to call your own callback function:
    class SubCanvas extends Canvas {
      MainCanvas mc
      public SubCanvas(MainCanvas mc) {
        this.mc = mc
      void keyPressed(int keyCode) {
        if (keyCode == theKeyThatCallsMainCanvas) {
          mc.callbackFunction();
    class MainCanvas extends Canvas {
      public void callbackFunction() {
    }shmoove

  • Two buttons pressing

    I know some Java and I have to make a program that will press two buttons like this:
    If i press the button START it will
    1. Wait 5000 milliseconds
    2. Press F5
    3. Wait 100 milliseconds
    4. Press Enter
    5. Wait 2000 milliseconds
    and then over and over again from step 2, until i press the button STOP
    I don't think that it will work in applet, because when you minimize applet, it stops working. Am I right?
    So I will have to use the standard Java. Right?
    And by the way. What is the function for automatic press of some king of button?

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class RobotDemo {
        private final JButton startButton = new JButton("Start");
        private final JButton stopButton = new JButton("Stop");
        private final ButtonActionListener listener = new ButtonActionListener();
        private final JTextArea display = new JTextArea(10, 40);
        private final String newline = System.getProperty("line.separator");
        private PhantomKeyPresser phantom;
        public RobotDemo() {
            initGui();
        public static void main(String[] args) {
            new RobotDemo();
        private void initGui() {
            JFrame frame = new JFrame("RobotDemo");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            display.setEditable(false);
            frame.getContentPane().add(new JScrollPane(display), BorderLayout.CENTER);
            startButton.addActionListener(listener);
            stopButton.addActionListener(listener);
            stopButton.setEnabled(false);
            JPanel buttonPanel = new JPanel();
            buttonPanel.add(startButton);
            buttonPanel.add(stopButton);
            frame.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
            display.addKeyListener(new KeyAdapter() {
                public void keyPressed(KeyEvent e) {
                    display("Somebody pressed: " + KeyEvent.getKeyText(e.getKeyCode()));
            display.requestFocus();
        private void display(final String message) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    display.append(message);
                    display.append(newline);
        private class ButtonActionListener implements ActionListener {
            public void actionPerformed(ActionEvent evt) {
                if (evt.getSource() == startButton) {
                    startButton.setEnabled(false);
                    stopButton.setEnabled(true);
                    startPhantom();
                } else if (evt.getSource() == stopButton) {
                    startButton.setEnabled(true);
                    stopButton.setEnabled(false);
                    stopPhantom();
        private void startPhantom() {
            phantom = new PhantomKeyPresser();
            Thread t = new Thread(phantom);
            t.start();
        private void stopPhantom() {
            phantom.stop();
        private class PhantomKeyPresser implements Runnable {
            private boolean iShouldKeepRunning = true;
            private Robot robot;
            public void run(){
                display("The phantom has been started!");
                try {
                    robot = new Robot();
                } catch (Exception e) {
                    throw new RuntimeException(e);
                display("The phantom waits for 5 seconds...");
                sleep(5000);
                while (iShouldKeepRunning) {
                    display("The phantom presses the F5 key...");
                    robot.keyPress(KeyEvent.VK_F5);
                    sleep(100);
                    display("The phantom presses the Enter key...");
                    robot.keyPress(KeyEvent.VK_ENTER);
                    sleep(2000);
            public void stop() {
                iShouldKeepRunning = false;
                display("The phantom has been stopped!");
            private void sleep(long millis) {
                try {
                    Thread.sleep(millis);
                } catch (InterruptedException e) {
                    e.printStackTrace();
    }

  • To display consecutive words from an array on a keypress. Event listeners not working.

    I need to display a series of words consecutively on a black background. A new word presented each time the Enter key is pressed (It is necessary that its the same key each time i.e the Enter Key). The words are arranged in an array. I have created a function for each Keypress and a listener. Also, as the previous word is replaced by the next, I have a removeChild() to get rid of the the last word.
    I have a removeEventListener set up also, to avoid any problems with the listeners. I have been at this a long time without sucess. It must be a listener problem (i.e I have not got the listeners focussed properly?) or a display problem. It only ever displays one word. Please see below code for the display of two of the words from the array which is called cvcwords. The main problem is that the words do not display one after the other (indeed not at all, except for the first one) when the enter key is pressed. Very much as a powerpoint presentation would, thats the idea anyway. I have just a sample of the code below. any help appreciated.
    var cvcwords : Array = ["bad", "mod", "hud", "mit", "sat", "fog", "puc",];
    this.stage.addEventListener(KeyboardEvent.KEY_DOWN, modKeyDown);
                                  function modKeyDown(e : KeyboardEvent) : void {
                                            if (e.keyCode == Keyboard.ENTER) {
                                                      removeChild(myText);               // to remove previous word from screen
                                                      myText.text = cvcwords[1];        //to display element one of the array
                                                      addChild(myText);
                                            } else if (e.keyCode == Keyboard.SPACE) { //this is for another seperate option
                                                      myText.text = "try again";
                                                      addChild(myText);
                   this.stage.removeEventListener(KeyboardEvent.KEY_DOWN, modKeyDown);
                                  this.stage.addEventListener(KeyboardEvent.KEY_DOWN, hudKeyDown);
                                  function hudKeyDown(e : KeyboardEvent) : void {
                                            if (e.keyCode == Keyboard.ENTER) {
                                                      removeChild(myText);  //to remove previous word from the screen      
                                                      myText.text = cvcwords[2];
                                                      addChild(myText);
                                            } else if (e.keyCode == Keyboard.SPACE) {
                                                      myText.text = "do again";
                                                      addChild(myText);
                   this.stage.removeEventListener(KeyboardEvent.KEY_DOWN, hudKeyDown);

    Based on what I see of your code, the following is all you might need...
    var cvcwords : Array = ["bad", "mod", "hud", "mit", "sat", "fog", "puc",];
    var counter:int = 0;
    stage.addEventListener(KeyboardEvent.KEY_DOWN, modKeyDown);
    function modKeyDown(e : KeyboardEvent) : void {
        if (e.keyCode == Keyboard.ENTER) {
            myText.text = cvcwords[counter];      
            counter++;
        } else if (e.keyCode == Keyboard.SPACE) {
            myText.text = "try again";
            addChild(myText);
            stage.removeEventListener(KeyboardEvent.KEY_DOWN, modKeyDown);
    When you test this in Flash, in the player you need to be sure to select the Diable Keyboard Shortcuts option found under the Control option in the top toolbar
    If you really mean to have them try again, you probably do not want to remove the event listener

  • How to link two keyevents together ?

    I need to detect “Shift + 1 “ and “1” separately, as these two will trigger different tasks. Normal keys like “1”,”a” can be detected in KeyTyped function (KeyEvent.KEY TYPED) and Shift can be detected from keyPressed function (KeyEvent.KEYPRESSED).
    But how can I link these two together ?
    It is possible that user gives “Shift + 1” and then gives “2”.
    But in my program how can I make out that this “Shift” is linked to “1” and not to “2” ?

    tech_cheetah wrote:
    From the APIs I have figured out that I can use this method to check if shift was pressed
    public boolean isShiftDown()
    The problem with this is that it will still catch sequences such as
    [shift down] 2 1 ...
    So you wouldn't have the sequence you were looking for, but maybe that's ok?
    If you search for my KeyboardCommands class, you'll see there is a way to map arbitrary character sequences (not just shift/control, etc) to an Action. This might be what you're looking for

  • Alt+ key in KeyPressed Event

    hi,
    I would like to get the KeyPressed Event for 'Alt+O' keyEvents. How to find two keystrokes combined. thanks in advance.

    You may want to read the KeyEvent class description in the API documentation.
    http://java.sun.com/j2se/1.4/docs/api/java/awt/event/KeyEvent.html

Maybe you are looking for