⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 event.c

📁 BIOS emulator and interface to Realmode X86 Emulator Library Can emulate a PCI Graphic Controller V
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************					SciTech Multi-platform Graphics Library**  ========================================================================**    The contents of this file are subject to the SciTech MGL Public*    License Version 1.0 (the "License"); you may not use this file*    except in compliance with the License. You may obtain a copy of*    the License at http://www.scitechsoft.com/mgl-license.txt**    Software distributed under the License is distributed on an*    "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or*    implied. See the License for the specific language governing*    rights and limitations under the License.**    The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc.**    The Initial Developer of the Original Code is SciTech Software, Inc.*    All Rights Reserved.**  ========================================================================** Language:		ANSI C* Environment:  QNX** Description:	QNX fullscreen console implementation for the SciTech*				cross platform event library.*****************************************************************************/#include <errno.h>#include "common/keyboard.c"/*--------------------------- Global variables ----------------------------*/#ifndef	__QNXNTO__static struct _mouse_ctrl	*_PM_mouse_ctl;static int			_PM_keyboard_fd = -1;static int			_PM_modifiers, _PM_leds;#elsestatic int			kbd_fd = -1, mouse_fd = -1;#endifstatic int			kill_pid = 0;static ushort		keyUpMsg[256] = {0};/* Table of key up messages		*/static int			rangeX,rangeY;		/* Range of mouse coordinates	*/#define TIME_TO_MSEC(__t)	((__t).tv_nsec / 1000000 + (__t).tv_sec * 1000)#define	LED_NUM			1#define	LED_CAP			2#define	LED_SCR			4/* Scancode mappings on QNX for special keys */typedef struct {	int scan;	int map;	} keymap;// TODO: Fix this and set it up so we can do a binary search!keymap keymaps[] = {	{96, KB_padEnter},	{74, KB_padMinus},	{78, KB_padPlus},	{55, KB_padTimes},	{98, KB_padDivide},	{71, KB_padHome},	{72, KB_padUp},	{73, KB_padPageUp},	{75, KB_padLeft},	{76, KB_padCenter},	{77, KB_padRight},	{79, KB_padEnd},	{80, KB_padDown},	{81, KB_padPageDown},	{82, KB_padInsert},	{83, KB_padDelete},	{105,KB_left},	{108,KB_down},	{106,KB_right},	{103,KB_up},	{110,KB_insert},	{102,KB_home},	{104,KB_pageUp},	{111,KB_delete},	{107,KB_end},	{109,KB_pageDown},	{125,KB_leftWindows},	{126,KB_rightWindows},	{127,KB_menu},	{100,KB_rightAlt},	{97,KB_rightCtrl},	};/* And the keypad with num lock turned on (changes the ASCII code only) */keymap keypad[] = {	{71, ASCII_7},	{72, ASCII_8},	{73, ASCII_9},	{75, ASCII_4},	{76, ASCII_5},	{77, ASCII_6},	{79, ASCII_1},	{80, ASCII_2},	{81, ASCII_3},	{82, ASCII_0},	{83, ASCII_period},	};#define NB_KEYMAPS (sizeof(keymaps)/sizeof(keymaps[0]))#define NB_KEYPAD (sizeof(keypad)/sizeof(keypad[0]))/*---------------------------- Implementation -----------------------------*//* These are not used under QNX */#define	_EVT_disableInt()		1#define	_EVT_restoreInt(flags)/****************************************************************************PARAMETERS:scanCode    - Scan code to testREMARKS:This macro determines if a specified key is currently down at thetime that the call is made.****************************************************************************/#define _EVT_isKeyDown(scanCode)	(keyUpMsg[scanCode] != 0)/****************************************************************************REMARKS:This function is used to return the number of ticks since systemstartup in milliseconds. This should be the same value that is placed intothe time stamp fields of events, and is used to implement auto mouse downevents.****************************************************************************/ulong _EVT_getTicks(void){	struct timespec t;	clock_gettime(CLOCK_REALTIME,&t);	return (t.tv_nsec / 1000000 + t.tv_sec * 1000);}/****************************************************************************REMARKS:Converts a mickey movement value to a pixel adjustment value.****************************************************************************/static int MickeyToPixel(	int mickey){	// TODO: We can add some code in here to handle 'acceleration' for	//		 the mouse cursor. For now just use the mickeys.	return mickey;}/****************************************************************************REMARKS:Map a keypress via the key mapping table****************************************************************************/static int getKeyMapping(	keymap *tab,	int nb,	int key){	int i;	for(i = 0; i < nb; i++) {		if (tab[i].scan == key)			return tab[i].map;		}	return key;}#ifdef __QNXNTO__/****************************************************************************REMARKS:Retrieves all events from the mouse/keyboard event queue and stuffs theminto the MGL event queue for further processing.****************************************************************************/static void _EVT_pumpMessages(void){	int		rc1, rc2;	struct kbd_pkt	key;	struct mse_pkt	ms;	static long	old_buttons = 0;	uint		message = 0, but_stat = 0, mods = 0;	event_t		evt;	while (count < EVENTQSIZE) {		rc1 = read(kbd_fd, (void *)&key, sizeof(struct kbd_pkt));		if (rc1 == -1) {			perror("getEvents");			PM_fatalError("Keyboard error");			}		if (rc1) {			memset(&evt, 0, sizeof(evt));			if (key.key.mods & KEYMOD_SHIFT)				mods |= EVT_LEFTSHIFT;			if (key.key.mods & KEYMOD_CTRL)				mods |= EVT_CTRLSTATE;			if (key.key.mods & KEYMOD_ALT)				mods |= EVT_ALTSTATE;			/* Now store the keyboard event data */			evt.when = TIME_TO_MSEC(key.timestamp);			if (key.key.flags & KEY_SCAN_VALID)				evt.message |= (key.key.scan & 0x7F) << 8;			if ((key.key.flags & KEY_SYM_VALID) &&			    (((key.key.sym & 0xff00) == 0xf000 &&			    (key.key.sym & 0xff) < 0x20) ||			    key.key.sym < 0x80))				evt.message |= (key.key.sym & 0xFF);			evt.modifiers = mods;			if (key.key.flags & KEY_DOWN) {				evt.what = EVT_KEYDOWN;				keyUpMsg[evt.message >> 8] = (ushort)evt.message;				}			else if (key.key.flags & KEY_REPEAT) {				evt.message |= 0x10000;				evt.what = EVT_KEYREPEAT;				}			else {				evt.what = EVT_KEYUP;				evt.message = keyUpMsg[evt.message >> 8];				if (evt.message == 0)					continue;				keyUpMsg[evt.message >> 8] = 0;				}			/* Now add the new event to the event queue */			addEvent(&evt);			}		rc2 = read(mouse_fd, (void *)&ms, sizeof(struct mse_pkt));		if (rc2 == -1) {			perror("getEvents");			PM_fatalError("Keyboard error");			}		if (rc2) {			memset(&evt, 0, sizeof(evt));			ms.buttons &= (_MOUSE_LEFT | _MOUSE_RIGHT);			if (ms.buttons & _MOUSE_LEFT)				but_stat = EVT_LEFTBUT;			if ((ms.buttons & _MOUSE_LEFT) != (old_buttons & _MOUSE_LEFT))				message = EVT_LEFTBMASK;			if (ms.buttons & _MOUSE_RIGHT)				but_stat |= EVT_RIGHTBUT;			if ((ms.buttons & _MOUSE_RIGHT) != (old_buttons & _MOUSE_RIGHT))				message |= EVT_RIGHTBMASK;			if (ms.dx || ms.dy) {				ms.dy = -ms.dy;				_EVT_mx += MickeyToPixel(ms.dx);				_EVT_my += MickeyToPixel(ms.dy);				if (_EVT_mx < 0) _EVT_mx = 0;				if (_EVT_my < 0) _EVT_my = 0;				if (_EVT_mx > rangeX)	_EVT_mx = rangeX;				if (_EVT_my > rangeY)	_EVT_my = rangeY;				evt.what = EVT_MOUSEMOVE;				evt.when = TIME_TO_MSEC(ms.timestamp);				evt.where_x = _EVT_mx;				evt.where_y = _EVT_my;				evt.relative_x = ms.dx;				evt.relative_y = ms.dy;				evt.modifiers = but_stat;				addEvent(&evt);				}			evt.what = ms.buttons < old_buttons ? EVT_MOUSEUP : EVT_MOUSEDOWN;			evt.when = TIME_TO_MSEC(ms.timestamp);			evt.where_x = _EVT_mx;			evt.where_y = _EVT_my;			evt.relative_x = ms.dx;			evt.relative_y = ms.dy;			evt.modifiers = but_stat;			evt.message = message;			if (ms.buttons != old_buttons) {				addEvent(&evt);				old_buttons = ms.buttons;				}			}		if (rc1 + rc2 == 0)			break;		}}#else/****************************************************************************REMARKS:Retrieves all events from the mouse/keyboard event queue and stuffs theminto the MGL event queue for further processing.****************************************************************************/static void _EVT_pumpMessages(void){	struct mouse_event		ev;	int				rc;	static long			old_buttons = 0;	uint				message = 0, but_stat = 0;	event_t				evt;	char				buf[32];	int				numkeys, i;	/* Poll keyboard events */	while ((numkeys = read(_PM_keyboard_fd, buf, sizeof buf)) > 0) {		for (i = 0; i < numkeys; i++) {			processRawScanCode(buf[i]);			}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -