PDA

View Full Version : raw-key events


sealfin
2002.06.14, 03:26 PM
ok, perhaps someone out there can point out why this crashes on any key-press :


EventHandlerRef gMoveEventHandlerRef;
EventTypeSpec gMoveEventTypeSpec[] = {kEventClassKeyboard, kEventRawKeyDown};
char keyCode;

[...]

InstallEventHandler(GetApplicationEventTarget(), NewEventHandlerUPP((EventHandlerProcPtr)MoveEventH andler), 1, gMoveEventTypeSpec, NULL, &gMoveEventHandlerRef);

[...]

void MoveEventHandler(void)
{
GetEventParameter((EventRef)gMoveEventHandlerRef, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(keyCode), NULL, &keyCode);
// ignore this.
#ifdef kPutKeyCodeToFile
if(gKeyCodeFile != NULL)
fprintf(gKeyCodeFile, "... %d ...\n", (int)keyCode);
#endif
return;
}


I've worked that much out so far from a few way too complex examples, but now I'm stuck...

OneSadCookie
2002.06.14, 11:02 PM
MoveEventHandler should have a particular type -- pascal OSStatus MoveEventHandler(EventRef event, EventHandlerCallRef thingy, void* userinfo) or something, but look at the documentation -- that's from memory.

You can't just cast things to the type you need and hope things work! There are two invalid casts in your code: (EventHandlerProcPtr)MoveEventHandler and (EventRef)gMoveEventHandlerRef.