Detecting when the shift key is held down
I am trying to detect when the shift key (either side) is held down by the user (without pressing any other keys), but I can't figure out to do this. This is the only thing I found to detect pressing a shift key:
protected boolean keyStatus(int keycode, int time)
{
System.out.println("down");
boolean retVal = false;
int key = Keypad.key(keycode);
if( key == Keypad.KEY_SHIFT_LEFT )
{
// do something
retVal = true;
}
else if( key == Keypad.KEY_SHIFT_RIGHT )
{
// do something
retVal = true;
}
return retVal;
}
Shift doesn't trigger keyDown and key开发者_JAVA百科Up, which would have been ideal. What am I missing?
Does holding down the shift key trigger multiple keypresses? If so, you could write a function to detect a certain number of keypresses within a given amount of time.
精彩评论