KeyTyped(KeyEvent) consumes CTRL key actions

hey there,
using a single CTRL key the method "keyTyped()" will never be called, why? Is there anything, that consumes the event before the method is called? I'd like to do without the tow methods keyPressed() and keyReleased(). Visiting the component sources didn't help.
thx in advance!
-hostmonsta

Hi,
You can override the processKeyEvent(KeyEvent e)
method of your control to get the CTRL keystroke.
protected void processKeyEvent(KeyEvent e)
super.processKeyEvent(e);
if(e.getID() == KeyEvent.KEY_PRESSED)
if(e.getKeyCode() == KeyEvent.VK_CONTROL)
// do your logic

Similar Messages

  • Problem in using KeyEvent.consume()

    Hi friends
    I am using KeyEvent.consume() for JTextField with KeyPressed and KeyTyped events, some times it cosumes and some time it don't. I would like to stop displaying some chars in text field by using consume(), ie basically validation part.
    Thanks
    Rammohan

    Are there specific keys that it won't consume?

  • Short cut for Radio buttons (using Ctrl+ key)

    How can I select deselect Radio buttons using Ctrl + keys. I know that setMnemonic can be used to access using Alt + key. But I want to use Ctrl also. Please suggest the solution. How can I select using only single key?

    Read the API for a meaning of each of the arguments. Here is a simple example showing how to assign an "Action" to the Ctrl+1 and Ctrl+2 keys:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class KeyboardAction extends JFrame
        public KeyboardAction()
            JPanel panel = new JPanel();
            setContentPane( panel );
            JTextField textField1 = new JTextField("Ctrl+1 or Ctrl+2", 10);
            panel.add( textField1 );
            JTextField textField2 = new JTextField("Ctrl+2", 10);
            panel.add( textField2 );
            //  Change the input map of the text field,
            //  therefore, Ctrl+1 only works for the first text field
            Action action1 = new SimpleAction("1");
            Object key1 = action1.getValue(Action.NAME);
            KeyStroke ks1 = KeyStroke.getKeyStroke(KeyEvent.VK_1, KeyEvent.CTRL_MASK);
            textField1.getInputMap().put(ks1, key1);
            textField1.getActionMap().put(key1, action1);
            //  Change the input map of the panel
            //  therefore, Ctrl+2 works for both text fields added to the panel
            Action action2 = new SimpleAction("2");
            Object key2 = action2.getValue(Action.NAME);
            KeyStroke ks2 = KeyStroke.getKeyStroke(KeyEvent.VK_2, KeyEvent.CTRL_MASK);
            panel.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(ks2, key2);
            panel.getActionMap().put(key2, action2);
        class SimpleAction extends AbstractAction
            public SimpleAction(String name)
                putValue( Action.NAME, "Action " + name );
            public void actionPerformed(ActionEvent e)
                System.out.println( getValue( Action.NAME ) );
        public static void main(String[] args)
            KeyboardAction frame = new KeyboardAction();
            frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
            frame.pack();
            frame.setVisible(true);
    }Also, if you search the forum using the keyword "getActionMap", I'm sure you'll find other example.

  • How to perform CTRL + ESC action on a JFrame

    I use following code for performing window closing when pressing ESC key, but i now want to perform a action when clicking CTRL + ESC
    , though i modifid following code i can't get soulution.
    KeyStroke escapeKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);
            Action escapeAction = new AbstractAction()
                 public void actionPerformed(ActionEvent e)
                     cancel.doClick() ;
            getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escapeKeyStroke, "ESCAPE");
            getRootPane().getActionMap().put("ESCAPE", escapeAction);

    try
    Robot r = new Robot();
    r.keyPress(KeyEvent.VK_CONTROL);
    r.keyPress(KeyEvent.VK_ESCAPE);
    r.keyRelease(KeyEvent.VK_CONTROL);
    r.keyRelease(KeyEvent.VK_ESCAPE);
    } catch (AWTException e)
    System.err.println("Error: " + e.getMessage());
    }

  • OpenScript : How to simulate ctrl key down?

    Hi,
    How do I simulate ctrl key down action in OpenScript?
    Couldnt get much info from oracle.oats.scripting.modules.functionalTest.api.FunctionalTestService.typeKeys() documentation about the keys value to be used.
    Or is there any better way?
    Thanks,
    Deepak

    I wanted to select multiple elements so I wrote the code like below,
    Robot robot = new Robot();
    robot.delay(1000);
    robot.keyPress(KeyEvent.VK_C);
    web.element(xpath).click();
    web.element(xpath1).click();
    web.element(xpath2).click();
    robot.keyRelease(KeyEvent.VK_C);
    Didnt work, so I tried keypress before each element click, but still that also didnt help.
    Same case with
    web.element("/web:window[@index='0']/web:document[@index='0']")
    .keyPress("<CTRL-SHIFT-F5>")
    My requirement is, I need to click multiple elements with Control key down.
    Please suggest me a solution.
    Thanks,

  • JComboBox consumes Escape Key

    Hi,
    I have a JDialog on which I am putting various components. I have used to the following code so that the cancel() method is called when the esacpe key is pressed.
    String CANCEL_ACTION_KEY = "CANCEL_ACTION_KEY";
    AbstractAction cancelAction = new AbstractAction(){
    public void actionPerformed(ActionEvent e){
    cancel();
    this.getRootPane().getActionMap().put(CANCEL_ACTION_KEY, cancelAction);
    KeyStroke escapeKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);
    InputMap dialogInputMap = this.getRootPane().getInputMap
    JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    dialogInputMap.put(escapeKeyStroke, CANCEL_ACTION_KEY);
    This works for all the components except for the JComboBox. Is there any way I can get the JComboBox not to consume the key event if it is not open? (i.e. of the combo box is open, i want to be able to cancel the second time escape is pressed.)
    The JComboBox is in a panel on another panel inside the JDialog. It's a type of wizard, and the componets are loaded dynamically by reflection, so the JComboBox doesn't have a reference to the action (or the cancel method).
    Maybe there's a way I could override one of the JComboBox's methods so it doesn't consume the key event if it is closed? (hence sending it up to the root pane?)
    Any help would be greatly appreciated!
    Thanks,
    Rob

    I've got it!
    Cheers for the reply vinny.... but the answer just came to me this morning. It's so simple! I override the processEvent method of the ComboBox like so: (super is the ComboBox)
    public void processKeyEvent(KeyEvent e)
    if((e.getKeyCode() == KeyEvent.VK_ESCAPE) && !super.isPopupVisible()){
    return; //don't process the event
    super.processKeyEvent(e);
    So, if the list is visible, escape will process the event and close the list .
    If escape is pressed again, list is not visible so the ComboBox will not process the event, sending it up to it's parent. Perfect operation.
    In my JDialog I have the following code to catch the escape key:
    private void addCancelByEscape()
    AbstractAction closeDialogAction = new AbstractAction(){
    public void actionPerformed(ActionEvent e){
    cancel();
    String actionName = "close-dialog";
    KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
    JLayeredPane layeredPane = this.getLayeredPane();
    layeredPane.getActionMap().put(actionName, closeDialogAction);
    layeredPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(stroke, actionName);
    This seems to work a treat. I also have a JTree on the dialog, and this seems to consume the escape key aswell. I've overridden the processKeyEvent for that (similar to above) and it works aswell! Thanks for the help.
    I might be including editable JComboBoxes soon.... if I come across any info or help i'll let you know....

  • How do I check if the ctrl key is pressed from within a mouseReleased actio

    How do I check if the ctrl key is pressed from within a mouseReleased action?
          addMouseListener( new MouseAdapter() {
             public void mouseReleased( final MouseEvent e ) {
               // If ctrl button is held down and mouse is clicked, do something
             }};

    Found it, I think
        e.isControlDown()

  • Use of the Ctrl key

    Hi all
    does anyone know of a method whereby I can use the Ctrl key (or Alt/Shift) as a trigger for an action?
    Spiersy

    Which version of Firefox do you use?
    You have a weird user agent:
    * Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.0; hi, Mom) Gecko/20020604
    Try to reset the preferences.
    * http://kb.mozillazine.org/Resetting_preferences
    * http://kb.mozillazine.org/Preferences_not_saved

  • Checking for Ctrl key after DropTargetDragEvent

    Hi,
    I need help with a program which contains a table and a tree. A DropTargetDragEvent is fired whenever selected line(s) from the table are dragged to the tree. Upon dragEnter() I do some action. How can I detect if the Ctrl key is pressed at that moment?
    Any suggestions are highly appreciated.

    It doesn't make a difference if I call dropTarget.setDefaultActions(DnDConstants.ACTION_COPY_OR_MOVE) or not.
    But I just noticed that event.getDropAction() returns DnDConstants.ACTION_MOVE when I press the SHIFT key and DnDConstants.ACTION_COPY otherwise. This is better than nothing but actually I wanted to detect the CTRL key.

  • Is there a way to change the Alt key to the Ctrl Key?

    Is there a to access the Alt key screen functions (the quick Eyedrop, (holding Alt and click the color) and the Zoom in and Zoom out (holding alt alt and scrolling with the mouse wheel) with other key instead of alt, for instance the Ctrl key?
    It is really annoying to me to deal with it, because in my shortcut configuration I use the keys "Q" and "W" to increace and decrease the size of the brush and the keys "A" and "S" to increase and decrease the hardness of the brush. What happens is that when I hold Alt to pick a color or to zoom, it calls the menu bar's shortcuts (it underlines the menu shortcuts) , so If I do so and press "S" it calls the Select menu, which is not what I'm trying to do.
    In Gimp, the pick a color and zoom in and zoom out actions are configured to work with the Ctrl key instead of Alt, so the shortcut menus are not an issue. Is there anyway to switch it to Ctrl? Is there anyway to make the Alt stop calling the menu bar?
    Thanks

    Hello, Other than a keyboard remapping software, you might be out of luck.

  • KeyEvent.consume() not consumed...

    Hi,
    If I attach a KeyEventListener to a TextField and that I consume the KeyEvents in the keyPressed() and keyReleased() methods, should the keys typed appear in the field or not?
    TextField f = new TextField();
    f.addKeyEventListener(this);
    public void keyPressed(KeyEvent e)
      e.consume();
    }I think they should not appear, as described in http://java.sun.com/j2se/1.3/docs/guide/awt/designspec/events.html:
    There are cases where programs need to prevent certain types of events from being processed normally by a component (i.e. a builder wants to use mouse events to enable a user to graphically move a button around and it wants to prevent the mouse press from 'pushing' the button).
    But testing it on Win2K with Sun JDK1.4.1 or IBM JDK1.3 shows the characters typed in the text field.
    On the other hand, testing the same code on a PDA width Personal Java does not show the keys types in the text field.
    Which one is correct?

    Hi,
    After been puzzled by this one for a few days, I found the answer. You have to consume all key events, even if KEY_TYPED is a high-level event and the javadoc for consume() says that it works only with low-level events!

  • Determine if Ctrl key is pressed.

    I want to perform some actions when handling Mouse Move event only when Ctrl key is pressed. Is there a way to determine pressed state of Ctrl key?

    Hi Jonni,
    I've attached a simple example VI that uses the Mouse Move event filter to check for mouse movement and calls user32.dll to check if CTRL key is pressed. I think that is what you are looking for.
    Sev K.
    Applications Engineering Specialist | CLA
    National Instruments
    Attachments:
    GetCtrlKey.vi ‏12 KB

  • KeyEvent.consume() doesn't work

    I have JFormattedTextField subclassed and implement a KeyListener to avoid typing invalid characters. so i implemented:
         * Implements KeyListener.
        public void keyPressed(KeyEvent event) {
            System.out.println("keyPressed: "+event);
            //verify:
            int keyCode = event.getKeyCode();
            switch (keyCode) {
            case KeyEvent.VK_T :
                System.out.println("valid: "+keyCode);
                break;
            default:
                System.out.println("invalid: "+keyCode);
                event.consume();
                break;
        }//keyPressed()The system out's are correct ("valid", "invalid"), but the invalid characters are still typed in the textfield - even though i call event.consume(). ?

    i had to introduce a class variable as a flag and also implement the other methods of KeyListener:
         * Implements KeyListener.
        public void keyPressed(KeyEvent event) {
            //verify:
            int keyCode = event.getKeyCode();
            switch (keyCode) {
            case KeyEvent.VK_T :
            case KeyEvent.VK_ESCAPE :
                isKeyConsumed = false;
                break;
            default:
                event.consume();
                isKeyConsumed = true;
                break;
        }//keyPressed()
         * Implements KeyListener.
        public void keyTyped(KeyEvent event) {
            if (isKeyConsumed) {
                event.consume();
        }//keyTyped()
         * Implements KeyListener.
        public void keyReleased(KeyEvent event) {
           if (isKeyConsumed) {
               event.consume();
        }//keyReleased()not pretty, but it works as expected.

  • I need to reprogram the delete and enter key to the left side of a external keyboard for the ipad mini. don't need the caps/lock or ctrl key and due to an injury my daughter can only use her left hand to type. She is using a text to speech app to verbaliz

    I need to reprogram the delete and enter key to the left side of a external keyboard for the ipad mini. I don't need the caps/lock or ctrl key. Due to a brain injury my daughter can only use her left hand to type. She also uses a text to speech app to verbalize all of her needs since her speech isn't intelligible any longer either. And her vision was significantly affected also, so the keyboard has to be mounted about 6 inches from her face. So to reach across the keyboard with her left hand to the right side delete and enter button is physically difficult and causes typing errors, which cause people to not understand what shes trying to say.
    The best keyboard so far is the Zagg folio mini. I just had to make stickers to enlarge the letters on the key buttons.
    Does anyone know how I can reprogram these two keys? Or where I can buy a wireless mini keyboard for Ipad made for lefthanders with these two functions on the left side. I have searched for days and days. It's sooooo important to me that she be able to contribute her voice again. Imagine if you got in a car accident and couldn't speak clearly any longer, but understood everything still. Thanks for any help and suggestions you all take the time to share with me. I really appreciate the kindness of strangers to help me help my daughter.
    Sami's mom

    Sami\'s mom wrote:
    I need to reprogram the delete and enter key to the left side of a external keyboard for the ipad mini.
    You cannot.

  • Tecra M10 - Stuck CTRL key issue -- perhaps to do with BIOS?

    Hello and thanks for reading.
    I recently switched my Tecra M10 to Windows 7 (from XP) and it soon developed the dreaded "stuck CTRL key" issue. This causes the keyboard to behave as if the CTRL key is permanently depressed. Sometimes hitting a combination of keys, or bringing up the onscreen keyboard, temporarily solves the issue, but then it returns.
    It seems to be an issue many people have, with no simple solution. I've looked at every thread about it I can find, and tried many things to do with drivers etc. without any success.
    So firstly, if anyone knows a remedy that works for this particular machine, I would be very grateful to learn it!
    Then, there are two things I've not yet done: update BIOS and disable pinch zoom.
    I was looking at the following BIOS update:
    http://www.toshiba-asia.com/sg/support/drivers/details/25244
    ... which is version 3.00 and seems to be most recent. My own version is 1.90.
    However version 3.00 is labelled "For PTMB0* ONLY". I don't know what this means or whether it applies to me. Can anyone help? Should I install this BIOS?
    For the pinch zoom, I've been told that disabling it does sometimes cure the CTRL problem -- but I can't find any pinch zoom facility on the M10. I suspect it simply doesn't have one. Is that right?
    Many thanks for any help you can give.

    Hi
    > I was looking at the following BIOS update. which is version 3.00 and seems to be most recent. My own version is 1.90.
    There are different Tecra M10 models on the market.
    Check the labels at the bottom of the unit. There you should find some numbers like for example PTMB0E-01K00LGR
    The first 6 characters are important: for example PTMB0E
    I assume your notebook belongs to European series.
    In such case you should check the Toshiba EU driver page for possible BIOS update.
    http://www.toshiba.eu/innovation/download_drivers_bios.jsp
    However, on Toshiba EU driver page you will find also the BIOS v3.0 for all European Tecra M10 units.
    Anyway, back to the CTRL button issue: guess what, you should connect an external USB keyboard and should check how the CTRL button acts.
    In case the USB keyboard would work properly, the CTRL button of internal keyboard is affected and you will need to replace the internal keyboard.
    PS: it could be possible that the option "sticky keys" has been enabled. To disable this function, you have to press SHIFT button 5 times in the row.

Maybe you are looking for

  • Can see my machine through vpn, but can't connect...

    Hello all, On 10.8.1 with ARD 3.6.1 at home-Mac MIni Server. Connected through a VPN (Cisco IPSec) to my office. I can see my work station at work (10.8.1, ARD 3.6), but I CAN'T connect. Message I get is: Make sure remote management is enabled in sha

  • Problem with serial number reinstalling Acrobat

    I purchased CS6 a few month ago, including Photoshop, Acrobat etc., which used to work fine. A few days ago, I had to reinstall Acrobat (starting with my CD Rom). Since then, Photoshop etc. work normally, but Acrobat keeps on asking me for my serial

  • How do I resize photos in Aperture to a specific size (645x369)?

    I belong to a social organization.  The web site web master said ""Make sure the images are the same size as the sizes under general setting on the left (645,x,369)"  Does anyone that steps to accomplish this?  Thanks.

  • How do I update my web browser on my Tungsten C

    How do I update my web browser on my tungsten C? (What update to I use and where do I get it?) Images are not displayed properly on web pages and no popups are allowed. I am using the Vista palm 6.2 OS because I use Docs to Go. Chat support is no lon

  • Java AVI Package

    Hi everyone I ve trying to find the java.AVI package but no luck so far. Is there any way I can find it on this site or on a different site? Cheers Pano