[Cocoa] NSFlagsChanged and repeated keys

Hello,

I'm working on a GUI library and I'd like to know whether there is a way to get repeated NSFlagsChanged events like with the NSKeyDown events.

I noticed I don't get the NSFlagsChanged event when I keep the concerned key pressed, and I know it's normal.

I thought of doing this virtually, by creating the event myself if the modifier is still pressed after some time. But to do this, I need to know what's the time interval between the key press and the first repeat, and the time between each repeat. These times are set by the user in the keyboard preference panel. So... does anyone know how I could get these informations ?
Or does anyone have another better idea ?

Thanks !
Ceylo

MacBook, Mac OS X (10.5.5)

Posted on Oct 12, 2008 9:17 AM

Reply
7 replies

Oct 21, 2008 10:14 AM in response to etresoft

I want to detect a repeating key.

But here the keys I want to get are the Control, Option, Command and Shift ones (that are key modifiers). And the point is I can't get any event for these keys when I keep them pressed. I just get one when I press or release them, but not when I keep them pressed.

Whereas with other keys, when I keep them pressed I get a NSEvent.

That's why I can't just use -\[NSEvent isARepeat\].

Oct 21, 2008 12:22 PM in response to Ceylo

Have a look at this tech note. It is about caps lock, but hopefully other modifiers are handled the same way. It doesn't say if you can detect repeating keys. It seems that you do get an NSEvent for each event and, hopefully, that event will have the isARepeat set to true. Not all events cause the keyDown or keyUp to be fired. You have to look at the "flagsChanged" and look at the event then. Hopefully it will have the information and behavior you need.

Oct 21, 2008 12:33 PM in response to etresoft

Yeah, but -\[NSResponder flagsChanged:\] is called only when you press or release a modifier key. There is no event sent if you keep the key pressed.

I already succeeded in handling the key pressing and key releasing for all the key modifiers. My current problem is I would also like to get an event when my modifier key is kept down, like I do with every other key.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

[Cocoa] NSFlagsChanged and repeated keys

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.