Keyevents

Yo, I've come up against a little problem, you see, I want to use the print screen function within java. I've seen that there is a keyEvent "VK_PRINTSCREEN", but I'm still not that advanced to know how to use it...
What I wanted to know was: is it possible? and is that the way to do it?
-keep it virtual

you should look at keylisteners....
you probably want to add one to your frame etc...
see the following
http://java.sun.com/j2se/1.4/docs/api/java/awt/event/KeyListener.html
http://java.sun.com/j2se/1.4/docs/api/java/awt/Component.html#addKeyListener(java.awt.event.KeyListener)

Similar Messages

  • KeyEvents with the TAB Key

    Hey All,
    I have a small progam with a small problem. My program is an applet with numerous textfields and I have implemented the KeyEvents event listener. What I want to have happened when I press the "Tab Key" is the cursor move from one tab to another, but when it goes to the next tab it clears out the text that is currently in the textfield. Take a look at my code segment that is giving me the problem.
    public void keyPressed(KeyEvent e)
    if(NameField == e.getSource())
              if(e.getKeyCode() == KeyEvent.VK_TAB)
                   SalaryField.setText(" ");
    I know that is works if I replace "VK_TAB" with something else like "VK_A". "NameField" and "SalaryField" are the names of mt textfields. I am currently using Java SDK 1.3.1 to program in java program, but my browser uses JVM/Runtime Enviornment 1.4.1. When I run it with my broswer nothing happens when I press tab and some for the program that I am using to progam in. I did a search in the forum and came up with I have above, but still cannot it to work. When I read APIs on 1.4.1 and 1.3.1 that both said that
    "Aside from those keys that are defined by the Java language (VK_ENTER, VK_BACK_SPACE, and VK_TAB), do not rely on the values of the VK_ constants. Sun reserves the right to change these values as needed to accomodate a wider range of keyboards in the future."
    What is going on? How can I solve this problem?
    Thanks,
    Iceman
    PS:
    My Interface is swing

    Hey All,
    Thanks for the help I got to work when I ran it with my programming program, but when I run it in a browser using the current JVM the tab key does not work. What is wrong now? Or how am I to use FocusListener now, I tried to use the getOppositeComponent(, my complier says that it is not a method of FocusListener. Even though java says in the docmentation that it is. Can I get some more help here. The questions again is How can I tab in a applet?
    Later,
    Iceman

  • Trapping KeyEvents anywhere in a JFrame for a status bar

    Hi all,
    There are a few examples of how to implement a status bar in the archives, but I haven't seen anything that tells you how to trap KeyEvents (e.g. pertaining to CapsLock etc.) which occur anywhere in a JFrame: once you start adding focusable components (particularly but not exclusively JTextComponents) to a JFrame the JFrame itself is often not sent the KeyEvents, so a rudimentary addKeyListener() is not the answer.
    Could this involve the use of KeyboardFocusManager or sthg? NB to experts: I have read the tutorial on the focus subsystem to no avail. The key seems to be to trap the event thread in some way, perhaps??
    All help greatly appreciated...
    Mike

    Add a AWTEventListener on Toolkit.getDefaultToolkit() with appropriate mask. See javadocs of addAWTEventListener method.

  • MouseEvents and KeyEvents in the same form is not working

    Hello!
    I'm newbee in java althought i've bee programing for a long time in other languages, C, C++ wich i'm proud of.
    Now i land on java and there are a lot of cuestions (nothing that cant be solved by trying and reading).
    But today i hitted my head against all posible solutions and nothing (but bad mood) came out.
    The code with trouble is this...
    public class NewJFrame extends javax.swing.JFrame
        public NewJFrame()
            initComponents();
        private void initComponents() {
            jButton1 = new javax.swing.JButton();
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            addKeyListener(new java.awt.event.KeyAdapter() {
                public void keyPressed(java.awt.event.KeyEvent evt) {
                    formKeyPressed(evt);
                public void keyReleased(java.awt.event.KeyEvent evt) {
                    formKeyReleased(evt);
                public void keyTyped(java.awt.event.KeyEvent evt) {
                    formKeyTyped(evt);
            jButton1.setText("jButton1");
            jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    jButton1MouseClicked(evt);
            pack();
        private void formKeyTyped(java.awt.event.KeyEvent evt) {
            Integer i = evt.getKeyCode();
        private void formKeyPressed(java.awt.event.KeyEvent evt) {
            Integer i = evt.getKeyCode();
        private void formKeyReleased(java.awt.event.KeyEvent evt) {
            Integer i = evt.getKeyCode();
        private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
            Integer i = evt.getButton();
        private javax.swing.JButton jButton1;
    }In debug mode i cant listen to mouse events and key events in the same form. Is that normal ?
    In case this is normal, how can i surround this "problem" and make it work.
    Thanks a lot in ahead.

    Thanks for trying to understand whats going on ...
    There is my SSCCE
    * NewJFrame.java
    * Created on 2 de mayo de 2008, 20:32
    * @author  edu
    public class NewJFrame extends javax.swing.JFrame
        public NewJFrame()
            initComponents();
            setFocusable(true);
            requestFocus();
        private void initComponents() {
            jButton1 = new javax.swing.JButton();
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            addKeyListener(new java.awt.event.KeyAdapter() {
                public void keyPressed(java.awt.event.KeyEvent evt) {
                    formKeyPressed(evt);
                public void keyReleased(java.awt.event.KeyEvent evt) {
                    formKeyReleased(evt);
                public void keyTyped(java.awt.event.KeyEvent evt) {
                    formKeyTyped(evt);
            jButton1.setText("jButton1");
            jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    jButton1MouseClicked(evt);
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 400, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jButton1)
                        .addGap(0, 0, Short.MAX_VALUE)))
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 300, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jButton1)
                        .addGap(0, 0, Short.MAX_VALUE)))
            pack();
        private void formKeyTyped(java.awt.event.KeyEvent evt) {                             
            setTitle(String.valueOf(evt.getKeyCode()));
        private void formKeyPressed(java.awt.event.KeyEvent evt) {                               
            setTitle(String.valueOf(evt.getKeyCode()));
        private void formKeyReleased(java.awt.event.KeyEvent evt) {                                
            setTitle(String.valueOf(evt.getKeyCode()));
        private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
            setTitle(String.valueOf(evt.getButton()));
        private javax.swing.JButton jButton1;
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new NewJFrame().setVisible(true);
    }It's quite simple, its suposed to show on the windows title the KeyCode (if there is any) or the MouseButton when pressed.
    The problem is: it doesnt work... (if i comment out the jButton1 related code, that means that i dont listen to MouseEvents & dont add the MouseAdapter as MouseListner to the form, the KeyEvents are raised and i can listen to them - but there are no MouseEvents - if i run the SSCCE like above i can listen to the MouseEvents, but cant listen to the KeyEvents. Can you tell me why?
    Just before posting i realized it was a focus issue ! The button got the focus and got all the events redirected towards him ! I solved it with the code
            jButton1.setFocusable(false);and it finally worked !
    Thanks!

  • How to convert a string into a collection of KeyEvents

    I'm working on a program that must interact with a 3rd party application (closed to me, I have no access to the code or anything like that). I have been unable to send data to the program by getting its OutputStream. The only thing that has worked was using a Robot object to send individual key events (i.e. robot.keyPress(KeyEvent.VK_A);). Therefore I'm looking to convert a string (many different strings actually) into a collection of their associated KeyEvents so I can send them to the other application. Does anyone know a good way of doing it, or is anyone able to help me with using the OutputStream?
    Thank you!
    (The 3rd party application is Attachmate InfoConnect, a Unisys terminal emulation program that I have to use to access a mainframe).

    Here is a code sample.     public void checknumber(int vsize){
    int total;
    String anum;
    anum = tf2.getText();
    validnumber = true;
    lines2combine = 1;     //default (an integer)
    recs2make = 1;          //default
    try{
    lines2combine = Integer.parseInt(anum);
    catch (NumberFormatException e){
              System.out.println("Entry for lines to combine not numeric");
         validnumber = false;
         d1Title = "Data Entry Error";
         d1Txt = "For number for lines to combine;";
         d2Txt = "Enter a number.";
         doMessage();

  • Handling KeyEvent (filtering KeyEvents)

    I am writing a code to learn how KeyEvents behaves and how to manipulate and even filtering some events, for example, to filter the normal behaviour of keeping pressed a key that fires a KeyPressed -> KeyTyped -> KeyReleased Events, like pressing the 'a' button, and keeping it pressed, this fires the sequence expressed before as long as the button is keeped pressed.
    From the writing a KeyListener tutorial, (http://java.sun.com/docs/books/tutorial/uiswing/events/keylistener.html), i've begin to make some tests and changing somethings around the code, but, i am not getting too far as I want to make the 'keeping pressed' behaviour as just one event, the KeyPressed, and only when the user release the key, the KeyReleased Event should be fired.
    In resume, i just want to make any keystroke to be mapped as a modifier key, such as Shift or Control, because i will need a program which only responds with a character to the user, when he releases the key and not just like the KeyTyped Event.
    I am not a programmer, i am just a psychology student who wants to learn about Java programming language and try to apply it to some ideas about how to gather information about the behaviour of people when it's method of interact (virtually) is the keyboard realm.
    Is there anything out there to help me on this trail of learning how to manipulate KeyEvents?
    Thanks in advance, and sorry for the poor english.

    Hi,
    This is a bit of a hack but works nicely. Substitute the keyPressed, KeyReleased and keyTyped methods with the following:
        /** Handle the key typed event from the text field. */
        public void keyTyped(KeyEvent e) {
        //    displayInfo(e, "KEY TYPED: ");
        /** Handle the key pressed event from the text field. */
        public void keyPressed(KeyEvent e) {
            if(key != e.getKeyChar()) {
                displayInfo(e, "KEY PRESSED: ");
                key = e.getKeyChar();
        /** Handle the key released event from the text field. */
        public void keyReleased(KeyEvent e) {
            displayInfo(e, "KEY RELEASED: ");
            key = ' ';
        }and declare a char as a class varible like this:
    // ... import statements here
    public class KeyEventDemo extends JPanel
                              implements KeyListener,
                                         ActionListener {
        JTextArea displayArea;
        JTextField typingArea;
        static final String newline = "\n";
        // This is where you'll put the char.
        char key;
        public KeyEventDemo() {
            super(new BorderLayout());
            // ... the rest of the class

  • KeyEvents and Events Handling

    Hi
    I'm a beginner in Java and am currently making a basic tetris game. I was trying to set the controls for the game using KeyEvents. BlueJ compiles the program but the controls dont work. Could u possibly tell me what's wrong with my code.
    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.*;
    public class KeyboardControl extends JPanel implements KeyListener
    public KeyboardControl(Game game)
    this.game = game;
    private Game game;
    public KeyboardControl()
    this.addKeyListener(this);
    public void keyTyped(KeyEvent evt)
    public void keyPressed(KeyEvent evt)
    int key = evt.getKeyCode();
    if (key == KeyEvent.VK_LEFT)
    game.moveLeft();
    else if (key == KeyEvent.VK_RIGHT)
    game.moveRight();
    else if (key == KeyEvent.VK_UP)
    game.rotate();
    else if (key == KeyEvent.VK_DOWN)
    game.drop();
    public void keyReleased(KeyEvent evt)
    }

    Thanks for your help, but it still dosen't work. I'm starting to wonder if it's got something to do with my methods for moveLeft(), moveRight() in the game class etc.
    This is the moveLeft() method I've defined in the game class:
    public void moveLeft()
    currentBlock.moveLeft();
    notifyListeners();
    I've also defined the moveLeft() method in another class called Block
    public void moveLeft()
              if (canMove(-1,0))
                   x--;
         }

  • Solution for wrong characters in KeyEvents generated with ALT method

    Hi everybody!
    There is still a problem with KeyEvents coming from a barcode scanner using ALT + NumPad method. Java generates KeyTyped events with random outputs when ALT key is pressed. The issue seems to have creeped in somewhere between JSE 6u3 and 6u10, as in the former it works as expected and in the latter it does not. The problem persists still, we also tested it with Java 8 (on Windows 8, Windows 7 and Ubuntu 14). The actual test client is very simple, the application is only a JFrame containing a JTextField and a JTextArea.
    The old thread: Wrong characters in KeyEvents generated from input of barcode scanner
    My solution is to register a KeyEventDispatcher that blocks the KeyEvents when the ALT method is active:
    KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(
      new AltBugFixKeyEventDispatcher());
    public class AltBugFixKeyEventDispatcher implements KeyEventDispatcher {
        private int i = -1;
        @Override
        public boolean dispatchKeyEvent(KeyEvent ke) {
            if (ke.isAltDown()) {
                switch (ke.getID()) {
                    case KeyEvent.KEY_PRESSED:
                        if(ke.getKeyCode() == KeyEvent.VK_ALT){
                            i = 0;
                        }else if(Character.isDigit(ke.getKeyChar())){
                            i++;
                        }else{
                            i = -1;
                        break;
                    case KeyEvent.KEY_RELEASED:
                        break;
                    case KeyEvent.KEY_TYPED:
                        break;
                if(i != -1){
                    return true;
            return false;

    Hi everybody!
    There is still a problem with KeyEvents coming from a barcode scanner using ALT + NumPad method. Java generates KeyTyped events with random outputs when ALT key is pressed. The issue seems to have creeped in somewhere between JSE 6u3 and 6u10, as in the former it works as expected and in the latter it does not. The problem persists still, we also tested it with Java 8 (on Windows 8, Windows 7 and Ubuntu 14). The actual test client is very simple, the application is only a JFrame containing a JTextField and a JTextArea.
    The old thread: Wrong characters in KeyEvents generated from input of barcode scanner
    My solution is to register a KeyEventDispatcher that blocks the KeyEvents when the ALT method is active:
    KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(
      new AltBugFixKeyEventDispatcher());
    public class AltBugFixKeyEventDispatcher implements KeyEventDispatcher {
        private int i = -1;
        @Override
        public boolean dispatchKeyEvent(KeyEvent ke) {
            if (ke.isAltDown()) {
                switch (ke.getID()) {
                    case KeyEvent.KEY_PRESSED:
                        if(ke.getKeyCode() == KeyEvent.VK_ALT){
                            i = 0;
                        }else if(Character.isDigit(ke.getKeyChar())){
                            i++;
                        }else{
                            i = -1;
                        break;
                    case KeyEvent.KEY_RELEASED:
                        break;
                    case KeyEvent.KEY_TYPED:
                        break;
                if(i != -1){
                    return true;
            return false;

  • Wrong characters in KeyEvents generated from input of barcode scanner

    Hi everybody, :-)
    I have a problem with KeyEvents coming from a barcode scanner. The issue seems to have creeped in somewhere between JSE 6u3 and 6u10, as in the former it works as expected and in the latter it does not. The problem persists still, we also tested it with 6u22 and 6u23 (all tests were performed on the same Windows XP machine). The actual test client is very simple, the application is only a JFrame containing a JTextField and a JTextArea.
    The barcode scanner we use connects via USB and has no special driver. The scanner already decodes the barcode that was scanned and "enters" characters in the focussed text field of the test application by emulating the Alt+NumPad behaviour (the character '5' being produced by the equivalent of holding Alt and entering "0053" on the NumPad).
    Now, what appears when the application is run in JSE 6u03 is the expected result:
    5@WM010$|
    5@WM010$|
    5@WM010$|
    5@WM010$|
    Here's the result for the same barcode when the application is run in JSE 6u10 (results for 6u23 are similar):
    5@WÞ10ä
    é@—M010$|
    5@W¥ð104|
    5°ùM0ó(▄♀
    5@W¥010$|
    é@WM010Ü\
    é@W¥010P\
    5@wy010$|
    5@m01Ð$▄
    )°W¥01è$|
    )@—0ÑÐ$|
    Well, at least it manages to get some characters right every time... ;-)
    The character values are wrong already when the KeyEvent for each is being created and posted to the EventQueue. But on the other hand, the problem is obviously tied to the JSE used, so it has to occur somewhere after Java receives the input and before a KeyEvent is generated. Since the errors are very random, we are guessing that it might be a timing problem.
    Between JSE 6u3 and 6u10, KeyEvent has received some new members (here with their typical values for my use case):
    #isSystemGenerated     true
    #primaryLevelUnicode     0     
    #rawCode     0     
    #scancode     0     
    Maybe the problem could have been introduced in the same changeset? Or maybe the values observed are meaningful in a way?
    Can anybody enlighten me, or give me a hint of any kind? I already scoured the bug database but did not find anything.
    Thanks! Any help is appreciated!
    Regards, Lars

    @mriem: Yes, I did. In all cases, it is "windows-1252". And moreover, if it were a problem with the default character set, it would not show the random behaviour it does.
    I also managed to create a reproducer that shows the behaviour:
    import static java.awt.event.KeyEvent.*;
    import java.awt.*;
    import java.util.*;
    import javax.swing.*;
    public class ScannerTest {
         private static final String TEST = "5@WM010$|";
         private static final int DELAY = 50;
         private static final Map<Character, int[]> ALT_CODES = new HashMap<Character, int[]>();
         static {
              ALT_CODES.put('5', new int[] { VK_NUMPAD0, VK_NUMPAD0, VK_NUMPAD5, VK_NUMPAD3 });
              ALT_CODES.put('@', new int[] { VK_NUMPAD0, VK_NUMPAD0, VK_NUMPAD6, VK_NUMPAD4 });
              ALT_CODES.put('W', new int[] { VK_NUMPAD0, VK_NUMPAD0, VK_NUMPAD7, VK_NUMPAD7 });
              ALT_CODES.put('M', new int[] { VK_NUMPAD0, VK_NUMPAD0, VK_NUMPAD8, VK_NUMPAD7 });
              ALT_CODES.put('0', new int[] { VK_NUMPAD0, VK_NUMPAD0, VK_NUMPAD4, VK_NUMPAD8 });
              ALT_CODES.put('1', new int[] { VK_NUMPAD0, VK_NUMPAD0, VK_NUMPAD4, VK_NUMPAD9 });
              ALT_CODES.put('$', new int[] { VK_NUMPAD0, VK_NUMPAD0, VK_NUMPAD3, VK_NUMPAD6 });
              ALT_CODES.put('|', new int[] { VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD4 });
         public static void main(String[] args) throws Exception {
              System.out.println(java.nio.charset.Charset.defaultCharset().name());
              final int delay = DELAY;
              final JFrame frame = new JFrame("ScannerTest");
              SwingUtilities.invokeAndWait(new Runnable() {
                   @Override
                   public void run() {
                        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                        JScrollPane scrollPane = new JScrollPane(new JTextArea());
                        scrollPane.setPreferredSize(new Dimension(300, 600));
                        frame.add(scrollPane);
                        frame.pack();
                        frame.setVisible(true);
              new Thread() {
                   @Override
                   public void run() {
                        try {
                             Robot robot = new Robot();
                             for (int c = 0; c < 1000; c++) {
                                  if (frame.isActive()) {
                                       for (int i = 0; i < TEST.length(); i++) {
                                            int[] codes = ALT_CODES.get(TEST.charAt(i));
                                            if (frame.isActive()
                                                      && !(codes == null || codes.length == 0)) {
                                                 robot.keyPress(VK_ALT);
                                                 for (int code : codes) {
                                                      robot.keyPress(code);
                                                      robot.keyRelease(code);
                                                 robot.keyRelease(VK_ALT);
                                            robot.delay(delay);
                                       robot.keyPress(VK_ENTER);
                                       robot.keyRelease(VK_ENTER);
                                  } else {
                                       c--;
                                       try {
                                            Thread.sleep(delay);
                                       } catch (InterruptedException e) {
                                            e.printStackTrace();
                        } catch (AWTException e) {
                             e.printStackTrace();
              }.start();
    }

  • Trapping KeyEvents

    I've been approached by a student who wants to create a game that uses the keyboard from Swing. We've tried a couple of approaches already:
    1) Making the JApplet itself the KeyListener (no effect)
    2) Adding a KeyListener to glassPane (no effect)
         getContentPane().addKeyListener(new java.awt.event.KeyListener() {
                   public void keyPressed (KeyEvent e)          {}
                   public void keyReleased (KeyEvent e)     {}
                   public void keyTyped (java.awt.event.KeyEvent e) {
                        keyTyped(e);
    We're looking for a technique that will trap the KeyEvents for the whole window. Anyone know how to do this?

    Here's the code:
    import javax.swing.*;
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    public class KeyDemoApplet extends javax.swing.JApplet implements KeyListener{
    JTextArea displayArea;
    JTextField typingArea;
    static final String newline = "\n";
    public void init() {
    typingArea = new JTextField(20);
    typingArea.addKeyListener(this);
    displayArea = new JTextArea();
    displayArea.setEditable(false);
    JScrollPane scrollPane = new JScrollPane(displayArea);
    scrollPane.setPreferredSize(new Dimension(375, 125));
    JPanel contentPane = new JPanel();
    contentPane.setLayout(new BorderLayout());
    contentPane.add(typingArea, BorderLayout.NORTH);
    contentPane.add(scrollPane, BorderLayout.CENTER);
    setContentPane(contentPane);
    typingArea.requestFocus();
    /** Handle the key typed event from the text field. */
    public void keyTyped(KeyEvent e) {
    switch (e.getKeyChar())     {
         case KeyEvent.VK_UP:     displayArea.append ("^"+newline); break;
         case KeyEvent.VK_DOWN:     displayArea.append ("V"+newline); break;
         case KeyEvent.VK_LEFT:     displayArea.append ("<"+newline); break;
         case KeyEvent.VK_RIGHT:     displayArea.append (">"+newline); break;
    /** Handle the key pressed event from the text field. */
    public void keyPressed(KeyEvent e) {}
    /** Handle the key released event from the text field. */
    public void keyReleased(KeyEvent e) {}
    * We have to jump through some hoops to avoid
    * trying to print non-printing characters
    * such as Shift. (Not only do they not print,
    * but if you put them in a String, the characters
    * afterward won't show up in the text area.)
    protected void displayInfo(KeyEvent e, String s){
    String charString, keyCodeString, modString, tmpString;
    char c = e.getKeyChar();
    int keyCode = e.getKeyCode();
    int modifiers = e.getModifiers();
    if (Character.isISOControl(c)) {
    charString = "key character = "
    + "(an unprintable control character)";
    } else {
    charString = "key character = '"
    + c + "'";
    keyCodeString = "key code = " + keyCode
    + " ("
    + KeyEvent.getKeyText(keyCode)
    + ")";
    modString = "modifiers = " + modifiers;
    tmpString = KeyEvent.getKeyModifiersText(modifiers);
    if (tmpString.length() > 0) {
    modString += " (" + tmpString + ")";
    } else {
    modString += " (no modifiers)";
    displayArea.append(s + newline
    + " " + charString + newline
    + " " + keyCodeString + newline
    + " " + modString + newline);

  • Too many KeyEvents with AWTEventListener

    I am using the AWTEventListener to record all keystrokes in my program. I have got this running fine on java 1.4, but when i run it on java 1.3 it starts behaving oddly. I am capturing a number of events (KeyEvent, MouseEvent, FocusEvent etc...) but on 1.3, the number of keyEvents i receive are far too many.
    if i hit a key which would normally produce a KEY_TYPED event, i receive (in this order):
    KEY_PRESSED
    KEY_PRESSED
    KEY_TYPED
    KEY_RELEASED
    KEY_RELEASED
    If i hit a key which does not produce a KEY_TYPED event i receive:
    KEY_PRESSED
    KEY_RELEASED
    KEY_RELEASED
    I have tried this same code on mac OS X and Win2k running java 1.3, and they both produce the same results. I also tried it on a solaris system which didn't have 1.3 installed, but did have 1.4 and 1.2. Both behaved properly producing the expected number of events (one pressed, one released, and one typed if a typed event was produced). 1.4 on windows also ran fine.
    I tried the same test using a keyEventListener instead of AWTEventListener, and the expected keystrokes were returned in versions 1.3. So this seems to be a bug affecting only the AWTEventListener. However I have searched google and the java forums and bug database and have found no record off this anywhere else. Has anyone else had this trouble?

    Since the focus event model has changed in 1.4, the KeyListeners have become incompatible as well. If you search the forum again, I'm pretty sure you'll find something useful.

  • Map KeyEvents to proper char in all locales

    I am trying to create a mini VI clone. As such, I need to intercept KeyEvents and take actions based on those keys. So for instance, when a user hits the '@' key (eg SHIFT-2 on the US keyboard) I want to have a '@' printed to the display when I am in Insert mode. This is easy on the US keyboard because I know that a SHIFTED KeyEvent.VK_2 should produce a '@'. Unfortunately this only works on the US keyboard layout. If I choose the Spanish keyboard layout the SHIFT-2 key produces a '!' There are many other examples of this disjoint.
    So how do I get a mapping of the keys so I can identify from a KeyListener what key they actually pressed in their locale? (eg if the spanish user pressed his SHIFT-2 he expects a '!' not a '@' but the KeyEvent I get is a SHIFTED VK_2 and I have no idea what keystroke he intended that to be.)

    I'm having the same problem!
    I'm using the javascript API and calling RH_ShowHelp(0, helpPath + "/CSH/iSupportHelp.htm>SecondaryWindow", HH_HELP_CONTEXT, mapId);
    Which generates this url and opens it in a new window: http://localhost/rep/Help/CSH/iSupportHelp.htm#<id=16>>wnd=SecondaryWindow
    The new window then does more script processing and ends up with this url: http://localhost/rep/help/CSH/iSupportHelp.htm#<id=16%3E%3Ewnd%3DSecondaryWindow&t=Overvie w%2FiSupport_Overview.htm
    It doesnt matter what mapId I pass in, I always get the default topic.
    We just upgraded from RH10 to RH11 and we're trying to use the new responsive html5 output.

  • Change the functionality of the keyevents  according to the scene that it i

    I am a student and I am doing my tesis about authoring tools.
    I have obtained to give the same functionality to a keyevent for all the scenes, however, I am trying to change the functionality of the keyevents according to the scene that it is at the moment but I dont know how to do this.
    can anybody help me???

    Thanks for your help.
    Could you help us in a specific issue? We have three scenes. Hscene_1, Hscene_2, Hscene_3. Pressing the green button we want that; if I am in the Hscene_1 it passes to Hscene _2 and if I am in Hscene_2 it happens to me to Hscene_3
    we are waiting your answer.
    Thanks

  • Multiple KeyEvents?

    Hello,
    i have a problem with KeyEvent handling. I've wrote an own behavior class which changes the camera positon of the view vertical in a 45� degree limit. All works fine.
    Now it is usefull to change the key Event to specific keys like up and down. After several tries i've noticed that only the KeyEvent.KeyPressed ID and the other global KeyEvents work, the VK specific keyevent not..
    Why? Can someone help?
    Thx in advance,
    Christian

    insert that just after your process stimulus called e
    WakeupOnAWTEvent ev;
    WakeupCriterion genericEvt;
    genericEvt = (WakeupCriterion) e.nextElement();
              ev = (WakeupOnAWTEvent) genericEvt;
              AWTEvent[] events;
              events = ev.getAWTEvent();
              KeyEvent eve = (KeyEvent)events[0];
              if (eve.getKeyCode()==KeyEvent.VK_RIGHT)
                   //do your action               
              }

  • KeyEvents are to KeyBindings as MouseEvents are to ???

    Hey, stupid question here.
    I've recently been told (on this forum, actually) that KeyEvents are the "old" way to handle keyboard input. The new way is to use KeyBindings and map Actions to the keys you want input from. That's all fine and good, and I finally have all of my KeyEvent stuff translated to KeyBindings and Actions.
    Now, is there a similar "new" way to do mouse input? I haven't found anything on google, so I'm thinking no. Why not though? If binding keyboard input to Actions is the better way to handle keyboard input, why is the same not true for mouse input? Or is there a better way to handle mouse input than listening for MouseEvents? Also, is there a "right" or "wrong" way to mix MouseEvents with keyboard bindings?
    Thanks,
    Kevin

    camickr wrote:
    This isn't just about KeyStrokes and Actions, its about a general programming concept. The way you want to write code is to write reusable chunks of code. As mentioned above that is all an Action is, it is a reusable piece of code. The binding allows you to easily reuse this code. Maybe it's just that what I'm using the Actions for isn't a perfect example. Actions seem to be the modular way to handle the case where you want multiple actions to perform the same function. However, what if I have mostly a 1 to 1, "this key does this, this other key does this other thing" relationship? Even in the first case where Actions make more sense, I suppose I'm failing to see the difference between an Action that's mapped to several KeyBindings (or whatever you want to trigger the Action), and a function called by several keys in a KeyListener.
    Also, is there a "right" or "wrong" way to mix MouseEvents with keyboard bindings?
    I don't know if there is a right or wrong way but the key (to me) is that you want to use the Action, not the binding. So if you know that a component has a certain Action, there is no reason you can't have a MouseEvent invoke that Action. This is the way the [List Action|http://www.camick.com/java/blog.html?name=list-action] works.
    When I say mix, I mean basically using the CTRL_DOWN_MASK in a mouse click event to distinguish between a regular mouse click and a mouse click when the ctrl key is being held down. The only way I knew to do that is by using KeyEvents and MouseEvents. Now that I've switched my KeyEvents to KeyBindings mapped to Actions, the logical next step seemed to be doing the same for the MouseEvents? I don't necessarily want the mouse to trigger the same action as some key on the keyboard, I want the keyboard to change what the mouse does when it is clicked. Does that make sense?
    Anyway, I mostly understand, I'm just still at the point where I don't really see the benefit of KeyBindings and Actions over KeyEvents in my particular circumstance. I see the benefits in general. Maybe I'm just getting too old and becoming resistant to change, haha..

  • How to get keyevents in Jframe

    Hi,
    If i make usual keylistener class for keyevents and
    add it to jframe itself, the frame doesen't get any
    of keyevents. Alltough all buttons and such components
    which has same listener added gets events (when focused).
    The frame itself is allso focused when trying this.
    I tried allso add keylistener to container and all panels
    in that frame, but it had no better effect.
    There must be a way that frame can as get keyevents as default.
    I will be very pleased of any help.

    Are you sure you added a KeyListener to the right component? If you want your frame or panel to receive KeyEvents no matter what child component has the focus (ie. generated the event) then you will need to add a keylistener to every component in the frame (you can use a loop)and just use your frame as the sole KeyListener.
    I am pretty sure that will work but I'm not sure exactly what you have already tried. If that doesn't work then it could be related to the component consuming events. They do consume some events but I thought they would call all of their listeners first.
    Jeff

Maybe you are looking for

  • Scrolling thumbnails in Muse Slideshow?

    Is it possible to have only one row of thumbnails at the bottom of a slideshow that would scroll accross as the slideshow progresses?

  • IDVD annoyance!!!

    Okay, so I'm burning a quicktime file onto a DVD through iDVD. The entire file is actually around 12.6 GB, so I had to buy a DVD with Dual Layer so that it could actually fit. When exporting this quicktime file out of Final Cut Pro, I used the best q

  • Date pick calender error

    Dear Experts, We are using SAP B1-2007 PL 42 and occurred following error. When I click the date picker in any form (window) [ex:-Sales Quotation, SO, etc....), it shows only 4 days of the week. It hides rest of 3 days (Friday, Saturday, Sunday) in e

  • Thumbnail viewing is gone!

    I used to see all my photos when I clicked on the event in thumbnail view but now it's not an option. Anyone know how I can get that back or restore old settings??

  • How to Use Bx

    Expets, How to get report fields/ Query fields in BEx Report? I dont see my Info provider in query designer. Sridhar