Carbon framework

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

  1. damned macrumors newbie

    Joined:
    Apr 9, 2010
    #1
    Hi

    I was write a code :
    Code:
    #include <Carbon/Carbon.h>
     
     OSStatus KeyboardHandler (EventHandlerCallRef nextHandler,EventRef theEvent, void* userData){
    	printf("event!\n");
    	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");
    	 exit(0);
     }else{
    	 printf("Installed handler, listening for events...\n");
     }
     
     printf("Entering Loop...\n");
     RunApplicationEventLoop();
     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

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

    Joined:
    Aug 9, 2009
    #3
    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

    Joined:
    Apr 9, 2010
    #4
    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

    Joined:
    Aug 9, 2009
    #5
    Works fine for me, on 10.6.2 or 10.6.3.

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

    kainjow

    Joined:
    Jun 15, 2000
    #6
    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

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

Share This Page