Пример #1
0
/*
 * 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.
 */
BOOL
MwCheckKeyboardEvent(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 for ESC pressed*/
			MwTerminate();
		/*MwError(GR_ERROR_KEYBOARD_ERROR, 0);*/
		return FALSE;
	} else if(keystatus) {		/* Deliver events as appropriate: */
		switch (mwkey) {
		case MWKEY_QUIT:
			MwTerminate();
			/* no return*/
		case MWKEY_REDRAW:
			MwRedrawScreen();
			break;
		case MWKEY_PRINT:
			if (keystatus == 1)
				GdCaptureScreen("screen.bmp");
			break;
		}
		MwDeliverKeyboardEvent(mwkey, modifiers, scancode,
			keystatus==1? TRUE: FALSE);
		return TRUE;
	}
	return FALSE;
}
Пример #2
0
/*
 * Update keyboard status and issue events on it if necessary.
 * This function doesn't block, but is only called when Poll() returns TRUE
 * or MwSelect shows some data waiting to be read on the keyboard file descriptor.
 */
BOOL
MwCheckKeyboardEvent(void)
{
	MWKEY	 	mwkey;		/* latest character */
	MWKEYMOD 	modifiers;	/* latest modifiers */
	MWSCANCODE	scancode;
	int	 	keystatus;	/* latest keyboard status */

	if (kbddev.Poll && (kbddev.Poll() == 0))
			return FALSE;

	/* Read the latest keyboard status*/
	keystatus = GdReadKeyboard(&mwkey, &modifiers, &scancode);
	if (keystatus <= 0)
	{
		if (keystatus == KBD_QUIT)	/* special case for quit message*/
			MwTerminate();
		return FALSE;				/* read failed or no new data*/
	}

	/* handle special keys*/
	switch (mwkey)
	{
	case MWKEY_QUIT:
#if DEBUG
		if (modifiers & MWKMOD_CTRL)
			GdCaptureScreen(NULL, "screen.bmp");
		else
#endif
		MwTerminate();
		break;
	case MWKEY_REDRAW:
		MwRedrawScreen();
		break;
#if DEBUG
	case MWKEY_PRINT:
		if (keystatus == KBD_KEYPRESS)
			GdCaptureScreen(NULL, "screen.bmp");
		break;
#endif
	}

	/* Deliver keyboard events as appropriate*/
	MwDeliverKeyboardEvent(mwkey, modifiers, scancode, keystatus == KBD_KEYPRESS? TRUE: FALSE);
	return TRUE;
}