开发者

Detecting when the shift key is held down

开发者 https://www.devze.com 2022-12-20 21:23 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消