KeyListener - how to handle series of key pressed

Hi,
Is there a way to handle a series of key pressed in the keyPressed(KeyEvent e) method. for instance, I want to popup a dialogbox when the user pressed: F9, 31, F9 ?
thanks,
chau

Is there a way to handle a series of key pressed in
the keyPressed(KeyEvent e) method. for instance, I
want to popup a dialogbox when the user pressed: F9,
31, F9 ?Look at the following.
import java.awt.event.*;
import javax.swing.*;
/* http://forum.java.sun.com/thread.jspa?messageID=2900727 */
/* http://forums.devshed.com/t218618/s.html */
class KeyListenerDemo {
    public static void main(String[] args) {
        new KeyListenerDemo().go();
    void go() {
        JTextField field = new JTextField("Press a key, and watch the console.");
        field.setEditable(false);
        field.addKeyListener(new MyKeyListener());
        JFrame frame = new JFrame("KeyListener Demo");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(field);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
class MyKeyListener extends KeyAdapter {
    public void keyTyped(KeyEvent e) {
        if (e.getKeyChar() == KeyEvent.VK_ESCAPE) System.exit(0);
        System.out.println("Typed: " + e.getKeyChar());
}It shouldn't take too much imagination to figure out how to make the listener listen for that combination....

Similar Messages

  • How can we trape the Keys Pressed on the Keyboard and do action depending on the keys

    I want to know how we can capture the keys pressed on the keyboard by the user and do necessary action depending on the key pressed by the user....
    For example.... If user press Alt+q the form should go in the Enter Query Mode.
    Can anyone tell me how i can do this in Form 6i....
    Please Help me out from this problem...
    Thanks in Advance
    Shan

    Can somebody point me to what I need to use to
    intercept all the 'keys' for an application.
    At the moment I have set Focus to parts of the
    application when the Mouse is over it, and then get
    the Keys with a KeyListener.
    Is there a way to get the keys, as long as the Java
    app is active.
    - Its an image display program, and I want to use keys
    for - next image , zooom etc etc.
    If soemone could just point me to the right part of
    the API to look in?java.awt.Toolkit.addAWTEventListener()
    then use the mask defined in AWTEvent.KEY_EVENT_MASK to listen to all the events.
    Steve

  • How to get the actual key pressed in a UITextField

    Hi all , now i develop a program on iphone SDK 3.0 GM.
    I have an UITextField (created programmatically) and I have implemented the delegate as well as the UITextFieldTextDidChangeNotification so that I can react to changes in the text values.
    However, I specifically want to know when the user presses the backspace key in the UITextField when there is currently no text in the field. I can't find where I can get a specific notification of the actual key pressed, as opposed to the resulting state of the text. I'm sure there is a way to do this...help?

    I can imagine why you want to do it. I had the same problem myself and managed to circumvent it in a slightly painful way. What I did was to subclass UITextField to create a text field that always had text in it, even when it "seemed" empty. In fact the first character of the text is a space character, and then what follows is the actual text. In this way, your delegate will always get called about a backspace (when it's an attempt to delete the leading space character, obviously you should return NO in the textField: shouldChangeCharactersInRange: replacementString: method). I won't get into the details of exactly how to set everything up, like I said it is kind of elaborate and I wouldn't really recommend it unless you are desperate to have that kind of functionality.

  • How to handle Shift+Tab key event

    HI,
    This is Ramesh.I have added KeyListener to JTable. I am handling key events through key codes. But I am
    unable to handling multiple key strokes like Shift+Tab
    Can any one please give me suggestion how can I do it
    Thanks & Regards
    Ramesh K

    i dont know about Key BindingsWhich is why you where given a link to the tutorial in the first response.
    can you please give me suggestion.You've been given the suggestion 3 times. You can decide to learn to write code the way other Swing components are written. Or, you can do it the old way. The choice is up to you.

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

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

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

  • How to determine the exact key pressed when numlock disabled?

    Hi there,
    I am trying track the keyboardevent that triggered by pressing numpad keys as hotkey, but when the numlock is disabled, the same keycode, same keylocation was gotten as pressing in the standard keyboard. how can I determine if the numpad was pressed or the other control keys were pressed?
    Thank you!
    Andy

    Hi there,
    I am trying track the keyboardevent that triggered by pressing numpad keys as hotkey, but when the numlock is disabled, the same keycode, same keylocation was gotten as pressing in the standard keyboard. how can I determine if the numpad was pressed or the other control keys were pressed?
    Thank you!
    Andy

  • How to detect mouse movement/key press on Mac?

    Need to write a VI that will detect/report mouse movement (ie. returns it's location) and any key (or key combinations) pressed. And, to send the mouse pointer to any location on screen. Using Labview 6i on Mac.

    The event structure is new to LabVIEW 6.1. I could post 6.1 code but I cannot save the structure for previous and LabVIEW will not open a VI from a newer version. The best place to learn about the event structure is on the What's new in LabVIEW 6.1 page.
    http://amp.ni.com/niwc/labview/lv.jsp?node=1381

  • How do I capture two key press?

    How do I captyure Ctrl+Shift+A or Ctrl+A in KeyListener?

    Use the getModifiersEx() method of your KeyEvent. That contains a bitfield of the different modifiers (including CTRL and SHIFT) that were in effect when the event was generated. So you can do things like:
    KeyEvent evt = ...
    int keyCode = evt.getKeyCode();  // Let's say this is KeyEvent.VK_A
    int modifiers = evt.getModifiersEx();
    if( (modifiers & CTRL_DOWN_MASK) != 0 ) {
        // CTRL was down --> We have a CTRL-A event
    }Read the KeyEvent (or rather InputEvent, KeyEvent's baseclass) API for more info.

  • How to handle duplicate Primary Key entries in the Source data

    This is my first experience with ODI.
    I receive Source data from the customer that includes a one letter designation, ACTION_CODE, in each record of data as to the disposition of the record:
    ‘R’ represents Re-issue in which case I’m to modify the corresponding Target record based on the Primary Key.
    ‘N’ represents an Insert in which case I’m to insert a new record into the Target.
    ‘D’ represents a delete in which case I’m to delete the record with the corresponding Primary Key from the Target.
    The Source data comes in an XML file and the Target is an Oracle DB.
    I have chosen the IKM Oracle Incremental Update (MERGE) Knowledge Module.
    I filter ACTION_CODE to just collect records that are ‘N’ or ‘R’ and I exclude the ACTION_CODE from the mapping but since within the same Source
    set there may be an ‘N’ and ‘R’ with the same primary key I receive Primary Key errors.
    Should I alter CKM to not check for duplicates in the Source?
    Is there a better way?

    Ganesh,
    Identifying Duplicates is a logical activity.  More or less it need Manual intervention to judge both the records means common.  if few unique paramenters like Telephone, Pincode, SSN, passport no etc can be used on filters for searching the records.  Currently there are no automatic method to identify the duplicates.  In MDM 5.5 SP04 which is next release there will be auto de-duplicate facility based on tresholeds and matching criteria that you will setup.
    I hope i have answered your query transparently. if you have any queries futher you can reply here.
    Regards
    Veera

  • How to handle the unique primary key validation when is a multipart key !

    I dont know how to handle the primary key validation when the primary key is a multipart key.
    Besides would like to know how to catch the TooManyObjectsException in order to custom the default exception message.
    thank u.
    regards,
    Orlando Acosta

    Are you using EJB's, Toplink, or BC4J?
    Thanks,
    Rob
    Team JDev

  • Get control after key press in listview?

    how to get control after key press in listview ????
    example
    after keyboard key PAGE_DOWN  from listview
    execute my routine ?????
    Thank' s

    PavelSafrata, your solution is right, but in my case it does not work properly, because it has to be "setOnKeyPressed", then he picks up the current line and not after the jump PAGE_DOWN.
    used the routine below, but in this case when pressed SHIFT + PAGE_DOWN, does not bring the line "new" correct.
    this.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() {
                @Override
                public void changed(ObservableValue<? extends Number> observableValue, Number old, Number n ) {
                    if( my_last_keyborard_registered == KeyCode.PAGE_DOWN  ) {
                        System.out.println( n.intValue() );    // when pressed SHIFT + PAGE_DOWN
                                       // get -1  << error
    Thank's

  • Raise Key pressed event

    Hello, any know how can I raise a key press event throw code. For example I want to simulate that the user has press the A Key. How can I do that throw code?
    Thanks a lot !!

    Hi there,
    Your question has been discussed previously in the forums. Sounds like you want to programmatically click a button in WPF.
    Please check out this post
    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1329603&SiteID=1
    Thanks,
    Jennifer

  • How to handle form close event or escape key press event for user defined f

    Experts,
    Please let me know how to handle form close event or escape key press event for user defined form...
    Thanks & Regards,
    Pravin.

    Hi
    You can catch the form close event like this
    If ((pVal.FormType = 139 And (pVal.EventType = SAPbouiCOM.BoEventTypes.et_FORM_CLOSE)) And (pVal.Before_Action = True)) Then
          Try
                   SBO_Application.SetStatusBarMessage(pVal.EventType.ToString())
          Catch ex As Exception
                    SBO_Application.SetStatusBarMessage(ex.Message)
            End Try
          End If
    Hope this helps
    Regards
    Arun

  • How to pass the key pressed in javascript

    I'm asking this question here as I could not find the needed help elsewhere .
    I don't know how to pass the key pressed in the function on OnKeyPress event .
    I'm trying the following :
    <input type="text" name="a" onKeyPress="check();">
    I want to pass the key presses in the check function .
    How to collect the key pressed in the function check ?
    Thanks.

    As I said above, that won't work in Mozilla.
    In fact IMO Netscape/Mozilla javascript event handling has been behind IE since version 4.
    Be that as it may: here is a workaround (for Mozilla): It seems you have to assign the onkeypress event for it rather than declaring it as part of the textfield.
    Of the two textfields on this form, both work in IE, and only the first one will work properly in Mozilla. I left it in just to demonstrate the difference.
    And a couple of links for ya
    javascript forum: http://forums.webdeveloper.com/forumdisplay.php?s=&forumid=3
    Keypress events: http://www.din.or.jp/~hagi3/JavaScript/JSTips/Mozilla/Samples/KeyEvent.htm
    <html>
    <head>
    <script language="javascript" >
    <!--
    function check(evnt){
      alert("A key was pressed!");
      // IE handling
      if (window.event){
        evnt = window.event;
        alert(evnt.keyCode);
      // netscape/mozilla handling 
      else{
        alert(evnt.which);
    //-->
    </script>
    </head>
    <body >
    <form name="myform" method="post">
    Test <input type="text" name="myTest"><BR>
    Test <input type="text" name="myTest2" onKeyPress="check();"><BR>
    <script> document.myform.myTest.onkeypress = check; </script>
    </form>
    </body>
    </html>

  • Where can i learn to handle key presses?

    Right now if I try to hold two keys at once the computer only listens to one of the key presses, and if I am trying to hold a key and release another key at the same time, it only responds to the release. Does anyone know how I can fix these problems or at least point me in the direction of a place I can learn? Right now I have been trying for days and am completely stumped.

    Not sure if this will help or confuse you more but try this:
    1) Run the program as is. Try the left/right arrow keys
    both keyPressed and keyReleased events are generated
    2) Uncomment the line // panel.add(tf). Run again and try the left/right arrow keys
    only the keyReleased event is generated (so the text field is doing something)
    3) Uncomment the remaining lines to override the processKeyEvent of the text field
    Run again and try the left/right arrow keys
    both keyPressed and keyReleased events are generated
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    class TestKeyListener extends JFrame implements KeyListener
         public TestKeyListener()
              setSize(200, 200);
              addKeyListener(this);
              JPanel panel = new JPanel();
              getContentPane().add(panel);
              JTextField tf = new JTextField(10)
    //               public void processKeyEvent(KeyEvent e)
    //                    super.processKeyEvent(e);
    //                    System.out.println(e);
    //          panel.add(tf);
         public void keyTyped(KeyEvent e)
              System.out.println(e);
         public void keyPressed(KeyEvent e)
              System.out.println(e);
         public void keyReleased(KeyEvent e)
              System.out.println(e);
         public static void main(String[] args)
              JFrame frame = new TestKeyListener();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.setVisible(true);
    Here is another program that gets all events from the AWT event queue. There is a way to set a mask to retrieve only the events you want (ie. key events), but I'm not sure how to do it. If you search the forum you should be able to find an answer.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    class TestEventQueue extends JFrame
         public TestEventQueue()
              Toolkit.getDefaultToolkit().getSystemEventQueue().push(new MyEventQueue());
              setSize(200, 200);
    //          JTextField tf = new JTextField(10);
    //          getContentPane().add(tf);
         public static void main(String[] args)
              JFrame frame = new TestEventQueue();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.setVisible(true);
         public class MyEventQueue extends EventQueue
              protected void dispatchEvent(AWTEvent event)
                   super.dispatchEvent(event);
                   System.out.println(event);

Maybe you are looking for

  • 64 bit installation in Lightroom 2 for MAC

    The readme file that came with Lightroom 2 for MAC states: "Mac: Lightroom 2 is a 32-bit application by default. For customers using OS X 10.5 on an Intel-based computer, Lightroom 2.0 can be used as a 64-bit application by selecting Adobe Lightroom

  • Can anyone send me the SSL Plug-ins?

    I have a new 5525-X and of course it doesn't ship with the plug-ins installed in Flash (pretty stupid).  Anyway I need to setup my SSL VPN and I'm looking for the plug-ins.  Unfortunately my account isn't linked to a contract so I can't download them

  • List/DSC issue

    Hi all, I'm currently building a DSC which takes in a list (java.util.List) of ints and returns the modified list. In workbench I am mapping the input and output lists to the same variable. Basically the idea behind the DSC is to modify a list and re

  • Adobe keeps asking me to register

    I keep getting messages from Adobe to tell me to register my products or complete registration, which I have done twice now. I would like to stop getting these nags. Is there a way to communicate to the Adobe Master Computer to kindly knock it off? T

  • Replaced Hard Drive, Now Password is Incorrect

    I upgraded my hard drive from a 500 GB hard drive to a 1TB hard drive in my MacBook Pro, I reinstalled Lion and restored the data from the other hard drive. Now when I try to login to my account, it's as though my password is incorrect. I'm certain i