Keylistener problem

Hi,

I have added a keylistener to my glcanvas. The keylistener does pick up basic key presses, but the keyevent.isControlDown() method does not work (isAltDown does work, however). I’m not sure if this problem is specific to the operating system (I’m using Red Hat Linux).

I want the user to use ctrl key combinations to draw specific results on the glcanvas.

So, does anybody know if there is a way of trapping for ctrl key combinations (ie ctrl-m means user has pressed m key whilst holding ctrl key down) without using keyevent.isControlDown() method ?

Regards,

Sally

How about making a flag for CTRL in keyPressed() and keyReleased() methods?

public void keyPressed(KeyEvent e)
{
   if (e.getKeyCode() == KeyEvent.VK_CTRL)
     ctrlDown = true;
}

public void keyReleased(KeyEvent e)
{
  if (e.getKeyCode() == KeyEvent.VK_CTRL)
    ctrlDown = false;
}

The window manager occasionally traps certain modifier keys. I recall that Sawfish tends to grab Alt+Click events to cause the window to move, which can be problematic. If this is what’s happening, you can probably change the bindings in your window manager’s preferences. Aside from that, I haven’t personally seen issues related to the Control key specifically, though there are definitely platform-dependent issues related to reporting of modifier keys in the Java platform. See for example the ExaminerViewer source code in the gleem package in the jogl-demos workspace.

That’s interesting. Oddly enough the isControlDown has now, miraculously started to work for me. You may think I’m crazy because I have made absolutely no changes since it started to work and have no idea why it was not working last week but it is working now.

Weird ???