/* * Update keyboard status and issue events on it if necessary. * This function doesn't block, but is normally only called when * there is known to be some data waiting to be read from the keyboard. */ void GsCheckKeyboardEvent(void) { unsigned char ch; /* latest character */ MODIFIER modifiers; /* latest modifiers */ int keystatus; /* latest keyboard status */ /* Read the latest keyboard status: */ keystatus = GdReadKeyboard(&ch, &modifiers); if(keystatus < 0) { if(keystatus == -2) /* special case for ESC pressed*/ GsTerminate(); GsError(GR_ERROR_KEYBOARD_ERROR, 0); return; } else if(keystatus) /* Deliver events as appropriate: */ GsDeliverKeyboardEvent(GR_EVENT_TYPE_KEY_DOWN, ch, modifiers); }
/* * Update keyboard status and issue events on it if necessary. * This function doesn't block, but is normally only called when * there is known to be some data waiting to be read from the keyboard. */ GR_BOOL GsCheckKeyboardEvent(void) { MWKEY mwkey; /* latest character */ MWKEYMOD modifiers; /* latest modifiers */ MWSCANCODE scancode; int keystatus; /* latest keyboard status */ /* Read the latest keyboard status: */ keystatus = GdReadKeyboard(&mwkey, &modifiers, &scancode); if(keystatus < 0) { if(keystatus == -2) /* special case return code*/ GsTerminate(); GsError(GR_ERROR_KEYBOARD_ERROR, 0); return FALSE; } else if(keystatus) { /* Deliver events as appropriate: */ switch (mwkey) { case MWKEY_QUIT: GsTerminate(); /* no return*/ case MWKEY_REDRAW: GsRedrawScreen(); break; case MWKEY_PRINT: if (keystatus == 1) GdCaptureScreen("screen.bmp"); break; } GsDeliverKeyboardEvent(0, (keystatus==1? GR_EVENT_TYPE_KEY_DOWN: GR_EVENT_TYPE_KEY_UP), mwkey, modifiers, scancode); return TRUE; } return FALSE; }