Control/Option keys both set "control" modifier flag in NSEvent

  • I have a test mini-application with an application controller
    (subclass of NSApplication).  It works as expected, except that in my
    overridden "sendEvent"
    method, i log the following:
    a) the event (NSLog %@ format)
    b) the result of a getKeys call- which is supposed to return a
    bitmap of the depressed keys and can be called essentially at any time.
    I have  tried this with the left control, left option, right control,
    and right option keys. To my surprise, the "NSFlagsChanged" envent
    for the key press
    returns the following:
    a) left control down: keycode = 59 flags = 0004 (control key)
    keymask = <0,8,0,0>
    b)left option down keycode = 59 lfags = 0004    keymask = <0,8,0,0>
    right option down  keycode = 62  flags = 0004    keymask = <0,8,0,0>
    right control down keycode = 62 flags = 0004    keymask = <0,8,0,0>
    Any clues as to why this is happening?
    I don't have an installable keymap or input server in use. The
    HexInputServer sample code is installed,, but not selected.
    I don't to my knowledge have any unique changes to the default key
    bindings dictionnaries.

    I have a need to capture a key press of a modifier key and treat it
    as a normal key as long as no other key is pressed while it is down.
    (please don't flame me about Apple HIG, etc -an emulator has gotta do
    what it's gotta do).  The logic to do this using the 'flags changed"
    and "key down" events is not too difficult as long as I can determine
    which modifier was pressed, but ...
    I was hoping to avoid having to resort to installable keymaps or
    input servers beause I have not been able to ferret out a way to
    specify an application-specific keymap or input server
    programmatically. Forcing the user to manually specify a keymap or
    input server to make the application work seems
    rather user-unfriendly.

    Regards,

    Dale Miller
    <dalelmiller...>
  • On 07/10/2007, at 10:59 AM, Dale Miller wrote:
    > . To my surprise, the "NSFlagsChanged" envent for the key press
    > returns the following:
    > a) left control down:    keycode = 59    flags = 0004 (control key)
    > keymask = <0,8,0,0>
    > b)left option down    keycode = 59    lfags = 0004                    keymask = <0,8,0,0>
    > right option down        keycode = 62     flags = 0004                    keymask = <0,8,0,0>
    > right control down    keycode = 62    flags = 0004                    keymask =
    > <0,8,0,0>
    > Any clues as to why this is happening?

    Hi Dale,

    no I don't know why it's happening in your case, but the keyCodes for
    the modifier keys on either side are:

    // 55 = key code for left command key, 54 for right command key

    // 59 = key code for left control key, 62 for right control key

    // 58 = key code for left option key,  61 for right option key

    // 56 = key code for left shift key,  60 for right shift key

    I used NSLog(@"%p, %d", [event keyCode], [event keyCode]); inside -
    (void)flagsChanged:(NSEvent*)event to find out.

    I used a sublclass of NSWindow for this in a mini-test app.  Maybe
    your issue has something to do with using a subclass of
    NSApplication??  Dunno, just guessing.

    HTH,
    Ron
previous month october 2007 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today