Carbon framework

Discussion in 'Mac Programming' started by damned, Apr 9, 2010.

  1. damned macrumors newbie

    Apr 9, 2010

    I was write a code :
    #include <Carbon/Carbon.h>
     OSStatus KeyboardHandler (EventHandlerCallRef nextHandler,EventRef theEvent, void* userData){
    	return noErr;
     int main(int argc, char *argv[]){
     EventTypeSpec   kEvents[] =
    	 // use an event that isn't monitored just so we have a valid EventTypeSpec to install
    	 { kEventClassMouse, kEventMouseDown  },
    	 {kEventClassKeyboard,	kEventRawKeyDown},
    	 {kEventClassKeyboard,	kEventRawKeyRepeat},
    	 {kEventClassKeyboard,	kEventRawKeyUp},
    	 {kEventClassKeyboard,	kEventRawKeyModifiersChanged}
     OSStatus err = noErr;
     err = InstallEventHandler( GetEventMonitorTarget(), &KeyboardHandler, GetEventTypeCount(kEvents), kEvents, NULL, NULL);
     if(err != noErr){
    	 printf("Error: Could not install carbon event hook for input!\n");
    	 printf("Installed handler, listening for events...\n");
     printf("Entering Loop...\n");
     printf("Exiting Loop...\n");
     return 0;
    Mouse events work Ok !!! But keyboard events don't catch ! Please tell me why ? And, if not hard, please help me fix this problem!
  2. kpua macrumors 6502

    Jul 25, 2006
    EDIT: Never mind. I didn't read the code closely enough and thought it was using event taps.
  3. chown33 macrumors 604

    Aug 9, 2009
    Which OS version?

    How are you compiling and running your program?

    If it's in Xcode, which version? Debug or Release build? With or without debugger?

    When I compile and run it on 10.5.8 in Terminal, it says "event!" for every mouse and keyboard event.
  4. damned thread starter macrumors newbie

    Apr 9, 2010
    I use Mac OS X 10.6.2
    Build with command : gcc -x c -arch i386 -m32 -framework Carbon exampleEvent.cpp -o exampleEvent

    When I compile and run in Terminal, it says "event!" ONLY for mouse events !
  5. chown33 macrumors 604

    Aug 9, 2009
    Works fine for me, on 10.6.2 or 10.6.3.

    gcc -framework Carbon carbo.c && ./a.out
    gcc -arch i386 -framework Carbon carbo.c && ./a.out
  6. kainjow Moderator emeritus


    Jun 15, 2000
    Only the mouse down event worked for me on 10.6.3. I couldn't get Apple's EventMonitorTest to work either for the keyboard.
  7. damned thread starter macrumors newbie

    Apr 9, 2010
    I tried your method, but nothing changed. :(

Share This Page