how to handle specific keystrokes

Discussion in 'Java' started by user@domain.invalid, Jun 27, 2004.

  1. Guest

    Hi,

    I want to change the output to a JTtextbox based on user input.
    For example:
    user types in Ctrl + Alt + Shoft + B, i want to detect this and send to
    the textbox a N or user types in Ctrl + Alt + D, i want to detect this
    and send to the textbox a A for example.

    Pleas who can help me.

    Thanks,

    Anand
    , Jun 27, 2004
    #1
    1. Advertising

  2. > I want to change the output to a JTtextbox based on user input.
    > For example:
    > user types in Ctrl + Alt + Shoft + B, i want to detect this and send to
    > the textbox a N or user types in Ctrl + Alt + D, i want to detect this
    > and send to the textbox a A for example.


    If you only want the functionality when the textbox has focus, then use
    Component.addKeyListener
    If you want it to work no matter where the focus is, then use
    KeyboardFocusManager.addKeyEventDispatcher (from Java 1.4)

    Niels Dybdahl
    Niels Dybdahl, Jun 28, 2004
    #2
    1. Advertising

  3. Guest

    HI Niels,

    I use addKeyListener.
    I can intercept the keyPressed event but i dont't succeed in changing
    the character send to the JTextField.
    This is my coding i tried:

    public void processKeyEvent (KeyEvent e)
    {
    if ( (e.getID () == KeyEvent.KEY_TYPED) &&
    Character.isLowerCase (e.getKeyChar ()))
    {
    System.out.println ("keycode=" + e.getKeyCode() );

    // test purpose: change lowercase to uppercase. THIS WORKS!
    e.setKeyChar (Character.toUpperCase (e.getKeyChar ()));
    }
    else
    {
    if ( (e.getID () == KeyEvent.KEY_PRESSED))
    {
    if (e.isAltDown() && e.isControlDown() && e.isShiftDown())
    {
    char kar=65;
    e.setKeyChar (kar); //does not work
    }

    if (e.isShiftDown())
    // create new KeyEvent, consume old one and proces new one.
    // THIS IS NOT SUCCESFULL. WHAT IS WRONG IN MY CODING?
    {
    char kar=67; // does not work either

    KeyEvent nke = new KeyEvent(
    e.getComponent() ,
    e.getID(),
    e.getWhen(),
    e.getModifiers()
    ,67
    ,kar
    ,e.getKeyLocation());

    // consume old event
    e.consume ();
    super.processKeyEvent(nke);
    }
    }
    else
    {
    super.processKeyEvent (e);
    }
    }
    }

    Niels Dybdahl wrote:

    >>I want to change the output to a JTtextbox based on user input.
    >>For example:
    >>user types in Ctrl + Alt + Shoft + B, i want to detect this and send to
    >>the textbox a N or user types in Ctrl + Alt + D, i want to detect this
    >>and send to the textbox a A for example.

    >
    >
    > If you only want the functionality when the textbox has focus, then use
    > Component.addKeyListener
    > If you want it to work no matter where the focus is, then use
    > KeyboardFocusManager.addKeyEventDispatcher (from Java 1.4)
    >
    > Niels Dybdahl
    >
    >
    , Jun 28, 2004
    #3
  4. VisionSet Guest

    <> wrote in message
    news:40dfe4a1$0$1739$...

    Do not Multipost!

    Read this:
    http://www.safalra.com/internet/crosspost.html

    Don't even bother to crosspost, until you know this group well.
    A simple problem such as yours will be answered quickly on c.l.j.help

    --
    Mike W
    VisionSet, Jun 28, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rob T

    Capturing Keystrokes

    Rob T, May 13, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    813
    Vidar Petursson
    May 14, 2004
  2. Lucas Tam
    Replies:
    5
    Views:
    6,234
    WizyDig
    Dec 2, 2004
  3. Martijn Mulder

    where do the keystrokes go?

    Martijn Mulder, Dec 18, 2005, in forum: Java
    Replies:
    2
    Views:
    401
    Martijn Mulder
    Dec 18, 2005
  4. Simon
    Replies:
    2
    Views:
    393
    Simon
    Mar 2, 2006
  5. Steven Raasch

    Sending keystrokes to QT applications

    Steven Raasch, Jul 17, 2003, in forum: C++
    Replies:
    2
    Views:
    500
    Rolf Magnus
    Jul 17, 2003
Loading...

Share This Page