• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Getting the current state of the modifier keys
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting the current state of the modifier keys


  • Subject: Re: Getting the current state of the modifier keys
  • From: Jeffrey Mattox <email@hidden>
  • Date: Sat, 22 Feb 2003 23:39:53 -0600

Matt:

By "my routine only gets the one event, not any others" I mean that my handler (menuClicked:) is triggered by a mouse click on a status menu item, and I get control because I've done this:

[theStatusBarItem setAction:@selector(menuClicked:)];

In fact, I don't even get an event. The only parameter I get is an NSStatusBarButton object, which is a private class.

If my application is frontmost, then I can test the current state of the modifier keys using GetCurrentEventKeyModifiers(), and I can use an event loop as you suggest to wait for the modifier keys to be released. That works.

However, if my application is in the background, my handler still gets control when the status menu item is clicked, but GetCurrentEventKeyModifiers() always returns 0, so I'm blind.

Please tell me more about polling the keyboard in Carbon. That might be what I need to do.

Jeff

At 8:59 PM -0800 2/22/03, matt neuburg wrote:
On Sat, 22 Feb 2003 15:07:50 -0600, Jeffrey Mattox <email@hidden> said:

I have a Cocoa routine that gets a single keystroke or mouse click
event. If a modifier key is down, I want to wait until the modifier
key is released before proceeding. My routine only gets the one
event, not any others. Is there a way to test the current state of
the modifiers without getting another event?

I know how to test the event to see if a modifier key was on, but I
need to wait for the key(s) to be released.

I'm not understanding the phrase "my routine only gets the one event, not any others". It sounds like you're fighting the AppKit. Let the AppKit do the work. If a modifier key is down, then when it goes up you'll get a flagsChanged event and you can do whatever you're supposed to do. Just maintain state in the meantime in an ivar.

If you really want to you can make a small event loop inside the current routine, as described in the docs (HandlingMouseEvents.html). Or you can poll the keyboard in a loop (yecch!) using Carbon. But it's hard for me to believe you need to resort to either of those. m.

matt neuburg, phd = email@hidden, http://www.tidbits.com/matt
pantes anthropoi tou eidenai oregontai phusei
Subscribe to TidBITS! It's free and smart. http://www.tidbits.com/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Getting the current state of the modifier keys
  • Next by Date: Re: Getting the current state of the modifier keys
  • Previous by thread: Re: Getting the current state of the modifier keys
  • Next by thread: Re: Trouble
  • Index(es):
    • Date
    • Thread