Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Cocoa, Carbon and HotKeys

Cocoa, Carbon and HotKeys
Thread Tools
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
Mar 20, 2003, 01:06 AM
 
I have a written a Cocoa app which registers Shift (as a modifier) and several keys with a Hotkey class that has some carbon in it. When the user uses shift and one of the other keys this carbon method gets called in the Hotkey class:

pascal OSErr keyEventHandler(EventHandlerCallRef inHandlerRef, EventRef inEvent, void* refCon )
{
return [[HotKeyCenter sharedCenter] handleHotKeyEvent: inEvent];
}

What I want to happen is to post a notification that a hotkey was pressed in the handleHotKeyEvent method, but then allow the capital letter (because it is shift and "a") to go to the correct app. In my handleHotKeyEvent method I have tried returning eventNotHandledErr, but my program crashes and it builds a stack trace *very* slowly. If I return noErr my app doesn't crash but I completely intercept the key stroke so that it doesn't go to the active app.

I am still learning Cocoa and I know hardly anything about Carbon. Anyone have any suggestions?:confused:
     
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status: Offline
Reply With Quote
Mar 20, 2003, 04:08 PM
 
I'm not sure the hot key API is designed for filtering key input -- you may want to look at writing an input method instead. (See here and here for info, depending on whether you're targeting all apps or just Cocoa apps.)
Rick Roe
icons.cx | weblog
     
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
Mar 20, 2003, 04:28 PM
 
Thanks Rick. Those links, especially the one to the Carbon docs, looks helpful. What I am really trying to do is implement a user-was-idle class. I have my app tracking the mouse, but not knowning when a user presses a key is a severe limitation.

Unfortunately, I hardly know anything Carbon so it is hard to make sense of the Carbon docs. Is there some method I can override, post a notification and then just call super's implimentation of the method?
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 08:55 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2