Key event question

hey everyone...i'm using a key event (below)...and it works...but i am wondering how to recieve an input from a user to see what key they want to assign to that particular menuItem(without doing if statements to test every possible key)...if any one can help me please post
menuItem1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_NUMPAD1, ActionEvent.CTRL_MASK));
thanx Kevin

no...sry if i didn't explain myself enough...lets say a user wants to make a menu item called menuItem1 change to a different keyEvent. So they open a dialog and type in 1. Is there anyway to make menuItem1 have a keyEvent that is one(or what ever number or letter the user enters)??
hope that helps a little...kevin

Similar Messages

  • KEY events in MIDlets

    Hello all,
    I am basically new to J2ME MIDP development and also new to this
    forum. So apologies if this has already been covered or turns out to
    be a stupid question :) Here goes:
    I am trying to develop a MIDlet where I have a Form to accept certain
    values from the user. This is fairly straightforward and is easy to
    create with the high level Form a and TextField objects.
    Now, I wish to add a functionality to my MIDlet, in which, the user
    can press a specific key.. say the "Select" key or the "Call" key.. at
    any time during the form to start another thread of operation which
    performs something totally different... say for example, the user is
    entering values into the form and in between somewhere he presses this
    specific key and the phone start playing music. I hope you get my
    point.
    Basically I want to listen for key pressed or key held events on a
    Form object. Now I understand that Key events can be found only on the
    low-level Canvas based UIs. So is it possible to do it with Screen class
    elements..?
    Thanks,
    Nik

    You can try to use a CustomItem. What events will be delivered to the custom item depends on the implementation, though. Also these events will be only delivered when the CustomItem is focused.
    Have a look at the J2ME Polish GUI for using CustomItems for MIDP/1.0 devices as well.
    http://www.j2mepolish.org
    Best regards,
    Robert

  • Key Events

    Hi everyone,
    I have a question about key events. In the key events they have some values called as follows:
    static int KEY_LOCATION_LEFT
    static int KEY_LOCATION_NUMPAD
    static int KEY_LOCATION_RIGHT
    static int KEY_LOCATION_STANDARD
    I have seen the api and the explanation of what the above values represent
    and still do not understand what they mean.
    Is is possible for someone to explain these values to me in detail.
    What do they mean by LOCATION_LEFT - Left of what?
    What do they mean by LOCATION_RIGHT - right of what?
    What do they mean by LOCATION_STANDARD - what standard are they talking about?
    What do they mean by LOCATION_NUMPAD - are they talking about the num pad on the right of my keyboard?
    Any help is greatly appreciated
    Thank You
    Yours Sincerely
    Richard West

    First this (http://java.sun.com/docs/books/tutorial/uiswing/events/keylistener.html) tutorial is pretty helpful with this, try playing with the program there
    What do they mean by LOCATION_LEFT - Left of what?
    so far keys that produce the LEFT location things like 'left shift', 'left ctrl'....
    What do they mean by LOCATION_RIGHT - right of what?
    like left, but ie 'right shift' is a right location key
    What do they mean by LOCATION_STANDARD - what
    standard are they talking about?
    all keys that only have one instance and are NOT on the numberpad
    What do they mean by LOCATION_NUMPAD - are they
    talking about the num pad on the right of my
    keyboard?yes, NUMPAD refers to numbers and other keys on the right side of the keyboard

  • Generate Key Events without pressing key???

    Hi,
    Is it possible to generate key events without pressing a key in swing???
    i dont know if the question is logical or not, but just i want to generate some display as if the key is pressed by the user
    Ashish

    assuming c represents a text field.
    This will type the character 'a' in the text field:
    c.dispatchEvent( new KeyEvent (c, KeyEvent.KEY_TYPED, 0, 0, KeyEvent.VK_UNDEFINED, 'a') );
    This will invoke Ctrl+F1, which will show the tool tip for the text field:
    c.dispatchEvent( new KeyEvent (c, KeyEvent.KEY_PRESSED, 0, KeyEvent.CTRL_MASK, KeyEvent.VK_F1) );

  • Order of key events

    Hello,
    I have a relaitevly simple question. In what order key events are received in the containment hierachy? For instance, if I have a frame, containing a panel which contains a text field and I implement KeyListener interface for each of these components, which component would receive a key event first?
    Thanks

    I have had the same problem... not to mention I made it worse trying to reset my manual settings for iphoto!!!!
    Now all of my stuff on my comupter is out of order!! : ( It will take me months to fix this. I often use iphoto on my ipad for work and it looks like that is not going to happen now!
    I am very unhappy about this apple people!
    DPM

  • Surprising behaviour ..key pressed key event

    Hello,
    I am experiencing a supprising event key press issue. I have written below code in which my code getting called even though I didnt press any of the key,
    _entryPane.getTextArea().addKeyListener(new KeyAdapter() {
                 public void keyPressed(KeyEvent e) {             
                           doSendTypeStatus();
                     if(e.getKeyChar()==KeyEvent.VK_ENTER) {
                        if(e.isControlDown()) {As shown above , doSendTypeStatus() function getting called automatically ,i.e. with out being pressed any of the key on key board .
    Thread [AWT-EventQueue-0] (Suspended (breakpoint at line 82 in LivehelpTextEntryPanel$1))     
         LivehelpTextEntryPanel$1.keyPressed(KeyEvent) line: 82     
         TextAreaPane$MyTextArea(Component).processKeyEvent(KeyEvent) line: 5058     
         TextAreaPane$MyTextArea(JComponent).processKeyEvent(KeyEvent) line: 2388     
         TextAreaPane$MyTextArea(Component).processEvent(AWTEvent) line: 4909     
         TextAreaPane$MyTextArea(Container).processEvent(AWTEvent) line: 1569     
         TextAreaPane$MyTextArea(Component).dispatchEventImpl(AWTEvent) line: 3615     
         TextAreaPane$MyTextArea(Container).dispatchEventImpl(AWTEvent) line: 1627     
         TextAreaPane$MyTextArea(Component).dispatchEvent(AWTEvent) line: 3477     
         DefaultKeyboardFocusManager(KeyboardFocusManager).redispatchEvent(Component, AWTEvent) line: 1713     
         DefaultKeyboardFocusManager.dispatchKeyEvent(KeyEvent) line: 627     
         DefaultKeyboardFocusManager.preDispatchKeyEvent(KeyEvent) line: 831     
         DefaultKeyboardFocusManager.typeAheadAssertions(Component, AWTEvent) line: 741     
         DefaultKeyboardFocusManager.dispatchEvent(AWTEvent) line: 592     
         AgentFrame(Component).dispatchEventImpl(AWTEvent) line: 3506     
         AgentFrame(Container).dispatchEventImpl(AWTEvent) line: 1627     
         AgentFrame(Window).dispatchEventImpl(AWTEvent) line: 1606     
         AgentFrame(Component).dispatchEvent(AWTEvent) line: 3477     
         EventQueue.dispatchEvent(AWTEvent) line: 456     
         EventDispatchThread.pumpOneEventForHierarchy(int, Component) line: 201     
         EventDispatchThread.pumpEventsForHierarchy(int, Conditional, Component) line: 151     
         EventDispatchThread.pumpEvents(int, Conditional) line: 145     
         EventDispatchThread.pumpEvents(Conditional) line: 137     
         EventDispatchThread.run() line: 100     can any one please help me in resolving this issue. I am implementing typing status feature in my chat application. but due to this key event behavior , my implementation is failing completely.
    Looking for reply.
    thanks in advance
    Ani

    What is the question?
    doSendTypeStatus() function getting called automatically ,i.e. with out being pressed any of the key on key board .No, it is getting called whenever a key is pressed in the text area. It can be any key, but a key must be pressed. If you claim not to be pressing any keys, please print out the event.
    // wrong:
    if(e.getKeyChar()==KeyEvent.VK_ENTER) {
    // right:
    if(e.getKeyCode()==KeyEvent.VK_ENTER) {You should compare codes with codes, not chars
    Lastly you might want to use a document listener instead, so you also get notified when the user pastes something in the text area.

  • Which components catch a key-event?

    Hello,
    I've a question. I've a panel with severall sub-panels with textfield-editors. These have listeners to respond on a enter-key pressed event.
    When I input an illegal value somewhere, I invoke a messagedialog with a warning message. The problem is that when I press enter , the oke-button of the messagepane has the focus, the enter-key pressed event is also caught by my first panel with all the editors and shows the same message dialog again. Kinda like a loop.
    I thought that key-pressed event only where caught by the component/frame which has the focus, or am I wrong.
    Can anyone help me out here?
    Much Thanks
    Hugo Hendriks

    Normally an ActionListener is installed to an OK button, not a KeyListener. Check if you have implemented the same error handling in two places!
    Generally you can "eat" key events by e.consume(), maybe this helps:
    public void keyPressed(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_ENTER) {
    // ... do some error handling on ENTER
    e.consume();
    I think then the Frame GUI will no get the key event anymore. A modal JDialog has a local event queue (to be modal), but maybe it forwards events to the main queue ...

  • Macbook misses some key events for a few seconds

    I have noticed that for last two months or so something strange happens to my Retina MBP. Once in a couple of days it stops responding to some key events. It is like it handles only one keypress out of 4-5. Nothing seems to be wrong with the keyboard and it is not about a particular key or keys. And about 10-15 seconds later everything goes back to normal. I do not see any suspicious messages in the logs, the computer is connected to the power supply...It happens just by itself in the middle of the day, when I am typing.
    Almost looks like some interrupts get lost by the system while it is busy with something else. But I have checked the load level and running processes - nothing interesting there....And whatever it is - it happens during a very short period of time.

    Hi,
    No, I have not returned my MBP yet. In fact, I would rather avoid doing this unless I am convinced if it is a hardware issue. And I do believe it is not. Just recently I have spent some time investigating it and I have found very stroing correlation between the moments when this happens and these messages in the kernel log:
    Jan 13 10:49:54 mbp-wifi kernel[0]: Sandbox: sandboxd(96471) deny mach-lookup com.apple.coresymbolicationd
    Jan 13 10:54:31 mbp-wifi kernel[0]: Sandbox: sandboxd(96499) deny mach-lookup com.apple.coresymbolicationd
    Jan 13 10:54:31 mbp-wifi.home sandboxd[96499] ([96497]): mdworker(96497) deny mach-lookup com.apple.ls.boxd
    Jan 13 10:54:31 mbp-wifi.home sandboxd[96499] ([96498]): mdworker(96498) deny mach-lookup com.apple.ls.boxd
    Jan 13 10:56:32 mbp-wifi.home sandboxd[96504] ([96503]): mdworker(96503) deny mach-lookup com.apple.ls.boxd
    Jan 13 10:56:32 mbp-wifi.home sandboxd[96504] ([96502]): mdworker(96502) deny mach-lookup com.apple.ls.boxd
    And I have also noticed that my Spotlight database gets reconstructed too often, which means it gets corrupted.
    From all this I conclude that it is most likely the software issue and it seems to be linked to spotlight. I saw people reporting similar things. So now I am researching on how to fix it without disabling the spotlight.
    In general, I believe that the quality of Apple software is going down, it is not like 4-5 years ago And Apple does seem to care less and less about it.
    If in your case it happens all the time, not just once in a while, and you see that a particular key has problems - it is possible that we are talking about the different issues and yours might be really about the keyboard.

  • Detect key events on anything

    If I have a JFrame with many components on it, how do I detect if a key is pressed, without having to add a listener to every component? For example, how can I check for the escape key being pressed, but not having to have componentN.addKeyListener(this); for everything?
    Thanks
    US101

    The correct way to collect the key events is the following:
    from java 1.2 to java 1.3 use the FocusManager. This class can be found in the javax.swing package. You would then need to extend the DefaultFocusManager and override specific behavior.
    for java 1.4 use the KeyBoardFocusManager. This class can be found in the java.awt package.
    Please see the following for a better explanation:
    http://java.sun.com/j2se/1.4/docs/api/java/awt/doc-files/FocusSpec.html
    Thanks for your time,
    Nate

  • Catching key events in application

    I have a JFrame with a JDesktop containing lots of JInternalFrame with various of components such as JTextFields etc.
    Now, i want to have a "main" listener that will catch key events no matter which component that has focus. For example pressing CTRL+A should produce something in the application no matter which component that has focus.
    How do I implement this in an easy way?

    It doesnt seem to work to add a KeyListener to the JFrame...
    this.addKeyListener(new KeyAdapter(){
                   public void keyTyped(KeyEvent e){
                        System.out.println("KeyTyped()");
                   public void keyPressed(KeyEvent e){
                        System.out.println("KeyTyped()");
              });Adding that to the JFrame gives nothing to System.out when a JTextArea inside an JInternalFrame has focus.

  • Associating key events to a TextBox

    Hello All!
    Can anybody tell me how to associate key events with a TextBox? Something like when a certain key is pressed and released, a certain combinations of characters is inserted e.g. =-)
    I am trying to develop a simple application that allows users to type text with non-English characters, e.g. Russian and for that I have created a canvas and I am using key events i.e. KeyPressed and KeyReleased methods. Using a canvas is a bit insufficient because users cannot move the cursor freely through the text.
    I have read on te web that I can create a CustomeItem and override the KeyPressed methods but I could not do it; I could not find any simlar code example.
    Can anybody help me by providing me with a simple example or suggesting me an alternative way?
    Many thanks in advance

    {color:#008080}*Hello again!*
    I managed to create a CustomItem that overrides KeyPressed method, but now I am having difficulties making my textBox reacts to my keyPressed method.
    The early version of this CustomeItem overrides the KeyPressed method by assigning each key to a certain collection of chars. When a key is pressed, a string of these chars is drawn on the Canvas, which works fine. Now because I want to be able to edit the text, e.g. delete a certain char in the middle of the string, I want to use a TextBox or a TextField. The current problem is that my TextBox does not react to my key presses the way I want (I used setString() method); it reacts to the original key presses which print the original chars (from A through to Z and 1 through to 9).
    Is it possible to set the contents of a TextBox or TextField depending on my key presses? Could you suggest me an alternative way?
    Many thanks in advance!!{color}

  • Object Movement with Key Events

    Hi everybody!
    Im trying to move an object over the screen with keyboard buttons. The problem I have come across with is that I would like to use the right button to move right, up button to move forward, etc. but I cant push, for example, right and up buttons at the same time to make a diagonal movement. How can I solve this?
    Thank you and regards.

    I added key events to a sequence and than check them in the program.
    Something like this:
    class Car extends CustomNode {
        var keys:KeyCode[];
        public override function create(): Node {
            ImageView {
                transforms: [ Translate{ x: bind x, y: bind y }, Rotate{ angle: bind direction}]
                x: -w
                y: -h
                image: Image { url: "{__DIR__}car.png"}
                onKeyPressed: function( e: KeyEvent ) {
                    insert e.code into keys;
                    if(e.code == KeyCode.VK_UP){
                        ds = 2.0;
                    }else if(e.code == KeyCode.VK_DOWN){
                        ds = -2.0;
                    }else if(e.code == KeyCode.VK_LEFT){
                        da = -1.0;
                    }else if(e.code == KeyCode.VK_RIGHT){
                        da = 1.0;
                onKeyReleased: function( e: KeyEvent ) {
                    delete e.code from keys;
        public function move(){
              // check keys
    }

  • Binding Mouse and Key Events.

    Hi,
    When a user clicks the Ctrl + V the data from the clipboard
    is pasted into the user area. Instead of using this can we do it
    using a mouse click. For now, I am planning to bind the event code
    of these combinations (CTRL + V == 86) to the mouse click. But when
    I tried this I am unable to bind this key event to the mouse event.
    Can anyone help me out for getting out of this problem.
    Regards,
    eodC.

    No, it isn't.
    Kind regards,
      Levi

  • How to consume key events

    I would like to create a subclass of TextBox that only allows numeric input. My idea was to provide my own onKeyType() handler and consume any key events that do not correspond to digits. However, I can't find any way to consume key events from further processing. How do I do this?
    Are there any other suggestions how to accomplish the task of providing your own filter concerning valid key input?
    /Bengt

    I also wanted a kind of validators for the TextBox class of JavaFX. So I've tried solving the problem using the SwingTextField class and some Java APIs. The following is my code for a SwingTextField accepting only digits, but I do want it to be much simpler.
    import java.awt.AWTEvent;
    import java.awt.event.AWTEventListener;
    import java.awt.event.KeyEvent;
    import java.awt.Toolkit;
    import javafx.ext.swing.SwingTextField;
    import javafx.scene.Scene;
    import javafx.stage.Stage;
    import javax.swing.JComponent;
    class DigitKeyEventHookListener extends AWTEventListener {
        public-init var  source:JComponent;
        public  override function  eventDispatched( event:AWTEvent):Void {
            if (event.getSource().equals(source)) {
                var keyEvent : KeyEvent = event as KeyEvent;
                var keyCharacter = keyEvent.getKeyChar();
                var isDigit = false;
                var code = keyEvent.getKeyCode();
               if ((KeyEvent.VK_0 <= keyCharacter) and (keyCharacter <= KeyEvent.VK_9)) {
                       isDigit = true;
                if ((code ==KeyEvent.VK_DELETE) or (code ==KeyEvent.VK_BACK_SPACE)) {
                    isDigit = true;
                if ((code ==KeyEvent.VK_LEFT) or (code ==KeyEvent.VK_RIGHT)) {
                    isDigit = true;
               if (not isDigit) {
                    keyEvent.consume();
    function createSwingTextField() : SwingTextField{
        var field = SwingTextField {
            columns:12
        var listener =  DigitKeyEventHookListener{
            source: field.getJTextField()
        Toolkit.getDefaultToolkit().addAWTEventListener(listener, AWTEvent.KEY_EVENT_MASK);
        return field;
    Stage {
        title: "Digit Box"
        width: 200
        height: 80
        scene: Scene {
            content: createSwingTextField()
    }

  • No key event when compose keys are pressed

    I am supporting a legacy application for Sabre which maps some of the keys differently. For example, on a French keyboard the Compose key which is used to put a ^ on top of the vowel characters is to be remapped to produce a special character called a "Change Character" that has a special use for reservation agents that use Sabre
    The problem is, the first time you press the ^ compose key there is no key event apparently because the VM figures it doesn't yet know what key to report, it is expecting you to press a character such as 'o' and then you get an 'o' with a '^' on top of it.
    If you press the ^ compose key a second time, you get the following key events:
    keyPressed
    keyTyped
    keyTyped
    keyReleased
    On the screen you will see two ^ characters appear. Currently I remap the ^ character to the "Change Character", and I suppress the second keyTyped event so that I only get one character. The problem is that the user ends up having to press the key twice to get one "Change Character."
    I have no fix for this problem because there is no key event produced when they press the ^ compose key the first time.
    By the way, this behavior appears to have been introduced with jdk 1.3. The older jdk did produce a key event the first time you pressed the compose key. I would expect that this behavior was considered to be a bug and was fixed in jdk 1.3.
    Is there some other way to detect when the user presses a compose key? If not, is it possible for future jdk releases to report a keyPressed event when a compose key is pressed? This event would not cause a character to appear on the screen, but would allow programs to detect when the compose key is pressed.
    There is already a key on the French keyboard that behaves this way. It is the key to the left of the '1' key and it has the pipe symbol on it. If you press Shift plus this pipe key, no character is produces but a keyPressed event with a keycode of 222 is produced. I merely point this out to show that there is a way to report key events whithout producing output on the screen.
    Thanks, Brian Bruderer

    I don't know if this actually helps, but it seems that you can bind an Action to a dead key like the circumflex of the French keyboard
    Keymap keymap = textPane.addKeymap("MyEmacsBindings", textPane.getKeymap());
    Action action = getActionByName(DefaultEditorKit.beginAction );
    KeyStroke key = KeyStroke.getKeyStroke(KeyEvent.VK_DEAD_CIRCUMFLEX);
    keymap.addActionForKeyStroke(key, action);I saw this on a Swing tutorial and modified it slightly. Have a look at it :
    http://java.sun.com/docs/books/tutorial/uiswing/components/generaltext.html
    Chris

Maybe you are looking for

  • Windows 7 - Pci-to-Pci Bridge (Error: Code 10) - PCI Video Card

    Before I state my issues I will list what I'm running and what I'm trying to accomplish. I'm running Windows 7 Enterprise 64-bit edition, not the Beta or RC. I have 3 video cards in my possession (listed below). - (PCIe) Evga GTX260 - (PCI) Evga 9400

  • Developer 6.0 and oracle 8.1.5 personal for 98 connectivity problem

    I have see a couple postings on this. Most say to move the sqlnet.ora and tnsnames.ora files from the oracle 8i(home)/network/admin/ to developer(home)/network/admin or /net80/admin/ directories. My problem is that there isnt an sqlnet.ora file in th

  • Need help in Creating QPAC

    Hi there, I need some help regarding the creation of QPAC. I have created a QPAC for moving the file from one folder to another. I have successfully created the Jar file using Eclipse. But when i deploy the QPAC in Adobe Workflow and run it through t

  • Layer "Locked by Parent"

    I have a layer that I am trying to access and the message "Could not complete your request because the layer is locked by parent". The lock icon is grayed out. This is a CS3 file that I created, I have no idea how the layer was locked this way. Any i

  • Indesign CS4 colour issues with Onyx 7.3 RIP

    Hi all. I understand that Onyx Production house and postershop are having problems with colours dropping to white or changing to a completely different colour when sent from Indesign CS4 or a PDF created from the programme. I want to swap to indesign