Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

damned

macrumors newbie
Original poster
Apr 9, 2010
6
0
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!
 
EDIT: Never mind. I didn't read the code closely enough and thought it was using event taps.
 
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.
 
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.

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 !
 
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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.