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. Advertisements

  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. Advertisements

  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. Advertisements

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. Dietrich
    Replies:
    1
    Views:
    831
    Joe Smith
    Jul 22, 2004
  2. Rob T

    Capturing Keystrokes

    Rob T, May 13, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    915
    Vidar Petursson
    May 14, 2004
  3. Leon
    Replies:
    2
    Views:
    725
  4. =?Utf-8?B?SmF2?=

    Is ViwState Page-Specific or UserControl-Specific

    =?Utf-8?B?SmF2?=, Aug 16, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    790
    =?Utf-8?B?SmF2?=
    Aug 16, 2006
  5. =?ISO-8859-1?Q?KLEIN_St=E9phane?=
    Replies:
    3
    Views:
    596
    hanumizzle
    Oct 6, 2006
  6. mazdotnet
    Replies:
    2
    Views:
    566
    Alexey Smirnov
    Oct 2, 2009
  7. John Machin
    Replies:
    0
    Views:
    269
    John Machin
    May 10, 2011
  8. William FERRERES
    Replies:
    7
    Views:
    505
    William FERRERES
    Jul 9, 2007
Loading...