NSResponder not receiving keyUp event when Cmd ⌘ key held down
Asked Answered
S

1

16

I'm using a custom subclass of NSView and receiving keyboard events through the keyDown/keyUp methods, everything works fine except when the "Cmd ⌘" key is pressed, keyDown events are fired as normal but the keyUp event never comes.

In our case we use the arrow keys on their own to move an image left/right/up/down and if the user holds down "Cmd ⌘" while pressing left/right it will rotate the image instead. Since we get the keyDown event the image starts rotating but it never stops as keyUp never comes. Other modifiers don't have this issue (e.g. if shift, ctrl or alt are held down while another key is pressed we get the keyUp as expected). One option is to use a different modifier but it would be nice to keep it consistent with the PC version (Cmd is used as a substitute for when Ctrl is used on Windows, keeps it consistent with standard copy/paste commands etc).

Does anyone know why it does this? It feels like a bug but is probably just strange "correct behaviour", any ideas how to get around it (other than using an alternative modifier or using the likes of direct HID access).

Thanks.

Selfrenunciation answered 17/5, 2013 at 7:49 Comment(1)
This might be a possible solution: #4002065 I am having the same issue.Gwen
T
1

You can use flagsChanged to be notified when modifier keys are down/up, see: Technical Q&A QA1519 Detecting the Caps Lock Key which is applicable to other modifier keys. See Carbon/Frameworks/HIToolbox/Events.h for more modifier key codes.

- (void)flagsChanged:(NSEvent *)event
{
    if (event.keyCode == 0x37) { // kVK_Command
        if (event.modifierFlags & NSCommandKeyMask) {
            NSLog(@"Command key is down");            
        } else {
            NSLog(@"Command key is up");
        }
    }
}
Taro answered 12/4, 2014 at 19:57 Comment(1)
The OP was asking about the keyUp event for the key pressed in conjunction with the command key. This keyUp event never arrives.Conwell

© 2022 - 2024 — McMap. All rights reserved.