weird key behavior
From: Jan Biel (jan.biel_at_tu-clausthal.de)
Date: 06/29/04
- Next message: A deaf heart, a loose liver: "How to test an updated .jar?"
- Previous message: Oliver Hirschi: "RTFEditorKit - BUG"
- Next in thread: Niels Dybdahl: "Re: weird key behavior"
- Reply: Niels Dybdahl: "Re: weird key behavior"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 29 Jun 2004 16:29:21 +0200
I have a problem and it's really driving me insane!
I gave the code below, but first the problem description:
It's quite simple:
I have a JFrame with a KeyListener.
Everytime someone hits the CTRL or ALT key the program is supposed to type
either "CONTROL" or "ALT".
But somehow the KeyListener does not always fire and I have no idea why.
When the program starts I can hit CTRL as much as I want and get the desired
result
When I hit ALT once I cannot get any CTRL registered.
When I hit ALT a second time, nothing happens
But after that, CTRL hits register every time
When I hit ALT again, no CTRL hits register
and so on.
It seems as if hitting alt would lock up the KeyEventListener until I hit
ALT again.
If I keep hitting ALT, the following happens:
ALT -> returns "ALT"
ALT -> nothing happens
ALT -> returns "ALT"
ALT -> nothing happens
and so on. Seems to me like some "on-off" switch. I'm really confused :(
=============================
Here's the code:
public class MyFrame extends JFrame implements KeyListener
{
public MyFrame()
{
this.setVisible(true);
this.setSize(100, 100);
this.addKeyListener(this);
}
public void keyPressed(KeyEvent arg0)
{
if (arg0.isControlDown())
System.out.println("CONTROL");
if (arg0.isAltDown())
System.out.println("ALT");
}
public void keyReleased(KeyEvent arg0)
{}
public void keyTyped(KeyEvent arg0)
{}
- Next message: A deaf heart, a loose liver: "How to test an updated .jar?"
- Previous message: Oliver Hirschi: "RTFEditorKit - BUG"
- Next in thread: Niels Dybdahl: "Re: weird key behavior"
- Reply: Niels Dybdahl: "Re: weird key behavior"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|