How get key down on launch?

  • How can I test for a key down at launch time with Cocoa? The old event
    manager has functions like GetKeys() etc that lets you check if a key
    is down at any given time. I need something that can do this so I can
    check for a key down when my app launch. What I want to do is show a
    prefs dialog if a key is held down during launch before any other
    windows and stuff are set up.

    I have not found anything that can do it. Is there a way to do this?

    Thanks,
    Ken
  • assistive devices... some coregraphics api IIRC
    but that's quite an overhead for the simple task of checking a key.

    Therefore for me it was GetKeys() [no not ideal but the only way
    guaranteed to work :)]

    With best regards,
    Dominik Pich

    On Nov 8, 2007, at 11:40 PM, Ken Drycksback wrote:

    > How can I test for a key down at launch time with Cocoa? The old
    > event manager has functions like GetKeys() etc that lets you check
    > if a key is down at any given time. I need something that can do
    > this so I can check for a key down when my app launch. What I want
    > to do is show a prefs dialog if a key is held down during launch
    > before any other windows and stuff are set up.
    >
    > I have not found anything that can do it. Is there a way to do this?
    >
    > Thanks,
    > Ken
  • On Nov 8, 2007, at 4:40 PM, Ken Drycksback wrote:

    > How can I test for a key down at launch time with Cocoa? The old
    > event manager has functions like GetKeys() etc that lets you check
    > if a key is down at any given time. I need something that can do
    > this so I can check for a key down when my app launch. What I want
    > to do is show a prefs dialog if a key is held down during launch
    > before any other windows and stuff are set up.
    >
    > I have not found anything that can do it. Is there a way to do this?

    I the key in question is one of the modifier keys, you may be able to
    do something like this:

    if (([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask) != 0)
        {
        // option-key down
        }

    ___________________________________________________________
    Ricky A. Sharp        mailto:<rsharp...>
    Instant Interactive(tm)  http://www.instantinteractive.com
  • >
    >
    >> How can I test for a key down at launch time with Cocoa? The old
    >> event manager has functions like GetKeys() etc that lets you check
    >> if a key is down at any given time. I need something that can do
    >> this so I can check for a key down when my app launch. What I want
    >> to do is show a prefs dialog if a key is held down during launch
    >> before any other windows and stuff are set up.
    >>
    >> I have not found anything that can do it. Is there a way to do this?
    >
    >
    > I the key in question is one of the modifier keys, you may be able
    > to do something like this:
    >
    > if (([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask) != 0)
    > {
    > // option-key down
    > }

    Unfortunately it's not working. And I'd prefer not to use the old
    event manager functions since I assume they are not supported under 64
    bit.

    Ken
  • On Nov 8, 2007, at 9:29 PM, Ken Drycksback wrote:

    >> If the key in question is one of the modifier keys, you may be able
    >> to do something like this:
    >>
    >> if (([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask) != 0)
    >> {
    >> // option-key down
    >> }
    >
    > Unfortunately it's not working. And I'd prefer not to use the old
    > event manager functions since I assume they are not supported under
    > 64 bit.

    Using [NSApp currentEvent] at launch won't work because there is no
    current event at that point - you haven't started running the event
    loop yet.

    GetKeys actually is available in 64-bit HIToolbox, specifically
    because there didn't appear to be any other way to do this, so I think
    it's your best option for now.

    -eric
  • >>
    >> Unfortunately it's not working. And I'd prefer not to use the old
    >> event manager functions since I assume they are not supported under
    >> 64 bit.
    >
    > Using [NSApp currentEvent] at launch won't work because there is no
    > current event at that point - you haven't started running the event
    > loop yet.
    >
    > GetKeys actually is available in 64-bit HIToolbox, specifically
    > because there didn't appear to be any other way to do this, so I
    > think it's your best option for now.

    Ok, that's fine. If GetKeys is 64 bit then I can use that, no problem.

    Ken
  • I entered a bug on this a year ago - 5037322 - which was dupped to
    Bug 2671273 [so this has been a long standing request!].

    Anyone who would like the same feature in the next big cat release
    should enter a new bug and reference 2671273.

    David

    PS: A possible way to do this would be to have NSApplication return a
    NSFlagsChanged event up through -applicationWillFinishLaunching, then
    deleted it.
  • On 11/8/07 2:40 PM, Ken Drycksback said:

    > How can I test for a key down at launch time with Cocoa? The old event
    > manager has functions like GetKeys() etc that lets you check if a key
    > is down at any given time. I need something that can do this so I can
    > check for a key down when my app launch.

    If it's for a modifier, instead of the old GetKeys() I use:

    - (void)applicationWillFinishLaunching:
      (NSNotification*)aNotification
    {
    // If the option key is down at launch...
    if (GetCurrentEventKeyModifiers() && optionKeyBit) {
      ...;
    }
    }

    --
    ____________________________________________________________
    Sean McBride, B. Eng                <sean...>
    Rogue Research                        www.rogue-research.com
    Mac Software Developer              Montréal, Québec, Canada
previous month november 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    
Go to today