Do you want to program key handler for the program when it's window is active, or at anytime?
For the first case, you just need to add IDCMP port for RAWKEY or VANILLAKEY when you open the window, for example
my_window = (struct Window *) OpenWindowTags(NULL, WA_Left,0,WA_Top,0,WA_Width,180,WA_Height,160,WA_IDCMP,RAWKEY,WA_NewLookMenus,TRUE,WA_Flags,SMART_REFRESH|ACTIVATE,WA_Title, "drHirudo",WA_WBenchWindow,TRUE,TAG_END,NULL);
Later in you program you need to take the events from the userport of the window - there are 2 ways - passive (prefered) and active (takes more cpu resources). Here is the passive way:
Wait ( 1 << my_window->UserPort->mp_SigBit );
If an event comes to your program, you have to handle it, but first you need to know what's the event.
while (my_message = (struct IntuiMessage *) GetMsg (my_window->UserPort))
{ class=my_message->Class;
code=my_message->Code;
ReplyMsg(my_message);
}
/* We got it. Actually we have the last event, and ignore the previous. */
/* For a keypress: */
if (class == RAWKEY) {
switch (code) {
/* Do stuff according the pressed key/keys. */
case 1: printf("The key 1 was pressed.");break;
case 2: printf("The key 2 was pressed.");break;
default: printf("Some other key was pressed.");break
}
}
That's it - a simple key handler.
For this stuff you simply need the Intuition library.
IntuitionBase = (struct IntuitionBase *) OpenLibrary ("intuition.library",0 );
if ( !IntuitionBase )
{printf("Something terrible had happened!");return(-1);}
At the end don't forget to close the window and the library:
CloseWindow ( my_window );
CloseLibrary ( IntuitionBase );
:-D
Regards