Exemplo n.º 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;
}
Exemplo n.º 2
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 GsCheckKeyboardEvent(void)
{
	MWKEY		ch;		// latest character
	MWKEYMOD	modifiers;	// latest modifiers 
	MWSCANCODE	scancode;	// latest modifiers 
	int		keystatus;	// latest keyboard status 

	// Read the latest keyboard status: 
display_puts("key read\n");
	keystatus = GdReadKeyboard(&ch, &modifiers, &scancode);
	if(keystatus < 0) {
		if(keystatus == -2)	// special case for ESC pressed
			GsTerminate();
		display_puts("Kbd error\n");
		return FALSE;
	} else if(keystatus) { // Deliver events as appropriate: 
		byte2hex(modifiers,s);
		display_puts("kbd '");
		display_putc(ch);
		display_puts("',");
		display_puts(s);
		display_puts("\n");
		return TRUE;
	}
	return FALSE;
}
Exemplo n.º 3
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.
 */
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);
}
Exemplo n.º 4
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;
}
Exemplo n.º 5
0
/*
 * Handle all mouse events.  These are mouse enter, mouse exit, mouse
 * motion, mouse position, button down, and button up.  This also moves
 * the cursor to the new mouse position and changes it shape if needed.
 */
void GsHandleMouseStatus(GR_COORD newx, GR_COORD newy, BUTTON newbuttons)
{
	BUTTON	changebuttons;	/* buttons that have changed */
	unsigned char	ch;		/* latest character */
	MODIFIER	modifiers;	/* latest modifiers */

	GdReadKeyboard(&ch, &modifiers); /* Read the modifiers */

	/*
	 * First, if the mouse has moved, then position the cursor to the
	 * new location, which will send mouse enter, mouse exit, focus in,
	 * and focus out events if needed.  Check here for mouse motion and
	 * mouse position events.  Flush the device queue to make sure the
	 * new cursor location is quickly seen by the user.
	 */
	if ((newx != cursorx) || (newy != cursory)) {
		GsMoveCursor(newx, newy);
		GsFlush();
		GsDeliverMotionEvent(GR_EVENT_TYPE_MOUSE_MOTION,
			newbuttons, modifiers);
		GsDeliverMotionEvent(GR_EVENT_TYPE_MOUSE_POSITION,
			newbuttons, modifiers);
	}

	/*
	 * Next, generate a button up event if any buttons have been released.
	 */
	changebuttons = (curbuttons & ~newbuttons);
	if (changebuttons) {
		GsDeliverButtonEvent(GR_EVENT_TYPE_BUTTON_UP,
			newbuttons, changebuttons, modifiers);
	}

	/*
	 * Finally, generate a button down event if any buttons have been
	 * pressed.
	 */
	changebuttons = (~curbuttons & newbuttons);
	if (changebuttons) {
		GsDeliverButtonEvent(GR_EVENT_TYPE_BUTTON_DOWN,
			newbuttons, changebuttons, modifiers);
	}

	curbuttons = newbuttons;
}
Exemplo n.º 6
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 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();
		printf("Kbd error\n");
		return FALSE;
	} else if(keystatus) { /* Deliver events as appropriate: */	
		printf("kbd '%c',%d\n", ch, modifiers);
      return TRUE;
   }
   return FALSE;
}
Exemplo n.º 7
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.
 */
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;
}