Why was not the event sent when two keys were pressed?

advertisements

The following code works when you press single keys.

@Override public void handleEvent(Event evt) {
    switch(evt.type) {
    case SWT.KeyDown:
        System.out.println(evt.keyCode + " pressed");
        break;

    case SWT.KeyUp:
        System.out.println(evt.keyCode + " released");
        break;
    }
}

...

widget.addListener(SWT.KeyDown, this);
widget.addListener(SWT.KeyUp, this);

But when you press multiple keys like "A" first then "B", the listener will only receive key up event for "B" and no events for "A". So as a result, ...

switch(evt.type) {
case SWT.KeyDown:
    mKeyMap.get(evt.keyCode).isDown = true;
    break;

case SWT.KeyUp:
    mKeyMap.get(evt.keyCode).isDown = false;
    break;
}

The key "A" will always remain true, until you press it again and receive key down event and key up event. This problem doesn't happen with the arrow keys though. You can press multiple arrow keys and it sends key up events correctly.

So, why isn't key released event sent for key "A" when keys "A" and "B" are pressed?


This can be influenced by your keyboard to an extent. I'm not sure if that's what might be causing your problem, though, but take a look at this link:

http://www.tomshardware.com/forum/50383-28-pressing-multiple-keys-keyboard-problem