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

📄 event.c

📁 BIOS emulator and interface to Realmode X86 Emulator Library Can emulate a PCI Graphic Controller V
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************					SciTech OS Portability Manager 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:  IBM PC (OS/2)** Description:	OS/2 implementation for the SciTech cross platform*				event library.*****************************************************************************//*---------------------------- Global Variables ---------------------------*//* Define generous keyboard monitor circular buffer size to minimize * the danger of losing keystrokes */#define KEYBUFSIZE  (EVENTQSIZE + 10)static int		oldMouseState;			/* Old mouse state				 */static ulong	oldKeyMessage;			/* Old keyboard state			 */static ushort	keyUpMsg[256] = {0};	/* Table of key up messages		 */static int		rangeX,rangeY;			/* Range of mouse coordinates	 */static ulong	frequency;				/* Timer frequency				 */HMOU			_EVT_hMouse;			/* Handle to the mouse driver	 */HMONITOR        _EVT_hKbdMon;       	/* Handle to the keyboard driver */TID             kbdMonTID = 0;      	/* Keyboard monitor thread ID    */HEV             hevStart;           	/* Start event semaphore handle  */BOOL            bMonRunning;        	/* Flag set if monitor thread OK */HMTX            hmtxKeyBuf;         	/* Mutex protecting key buffer   */KEYPACKET       keyMonPkts[KEYBUFSIZE]; /* Array of monitor key packets  */int             kpHead = 0;         	/* Key packet buffer head        */int             kpTail = 0;        		/* Key packet buffer tail        *//*---------------------------- Implementation -----------------------------*//* These are not used under OS/2 */#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){	QWORD count;	DosTmrQueryTime(&count);	return (count.ulLo * 1000.0 / frequency);}/****************************************************************************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;}/* Some useful defines any typedefs used in the keyboard handling */#define KEY_RELEASE             0x40/****************************************************************************REMARKS:Pumps all messages in the message queue from OS/2 into our event queue.****************************************************************************/static void _EVT_pumpMessages(void){	static KBDINFO		keyInfo;		/* Must not cross a 64K boundary */	static KBDKEYINFO	key;			/* Must not cross a 64K boundary */	static MOUQUEINFO	mqueue;			/* Must not cross a 64K boundary */	static MOUEVENTINFO	mouse;			/* Must not cross a 64K boundary */	static ushort		mWait;			/* Must not cross a 64K boundary */	static KEYPACKET    kp;				/* Must not cross a 64K boundary */	event_t				evt;	int                 scan;	/* Pump all keyboard messages from our circular buffer */	for (;;) {		/* Check that the monitor thread is still running */		if (!bMonRunning)			PM_fatalError("Keyboard monitor thread died!");		/* Protect keypacket buffer with mutex */		DosRequestMutexSem(hmtxKeyBuf, SEM_INDEFINITE_WAIT);		if (kpHead == kpTail) {			DosReleaseMutexSem(hmtxKeyBuf);			break;			}		/* Read packet from circular buffer and remove it */		memcpy(&kp, &keyMonPkts[kpTail], sizeof(KEYPACKET));		if (++kpTail == KEYBUFSIZE)			kpTail = 0;		DosReleaseMutexSem(hmtxKeyBuf);		/* Determine type of keyboard event */		memset(&evt,0,sizeof(evt));		if (kp.KbdDDFlagWord & KEY_RELEASE)			evt.what = EVT_KEYUP;		else			evt.what = EVT_KEYDOWN;		/* Convert keyboard codes */		scan = kp.MonFlagWord >> 8;		if (evt.what == EVT_KEYUP) {			/* Get message for keyup code from table of cached down values */			evt.message = keyUpMsg[scan];			keyUpMsg[scan] = 0;			oldKeyMessage = -1;			}		else {			evt.message = ((ulong)scan << 8) | kp.XlatedChar;			if (evt.message == keyUpMsg[scan]) {				evt.what = EVT_KEYREPEAT;				evt.message |= 0x10000;				}			oldKeyMessage = evt.message & 0x0FFFF;			keyUpMsg[scan] = (ushort)evt.message;			}		 /* Convert shift state modifiers */		 if (kp.ShiftState & 0x0001)			 evt.modifiers |= EVT_RIGHTSHIFT;		 if (kp.ShiftState & 0x0002)			 evt.modifiers |= EVT_LEFTSHIFT;		 if (kp.ShiftState & 0x0100)			 evt.modifiers |= EVT_LEFTCTRL;		 if (kp.ShiftState & 0x0200)			 evt.modifiers |= EVT_LEFTALT;		 if (kp.ShiftState & 0x0400)			 evt.modifiers |= EVT_RIGHTCTRL;		 if (kp.ShiftState & 0x0800)			 evt.modifiers |= EVT_RIGHTALT;		 oldMove = -1;		 /* Add time stamp and add the event to the queue */		 evt.when = key.time;		 if (count < EVENTQSIZE)			 addEvent(&evt);		 }	/* Don't just flush because that terminally confuses the monitor */	do {		KbdCharIn(&key, IO_NOWAIT, 0);		} while (key.fbStatus & KBDTRF_FINAL_CHAR_IN);	/* Pump all mouse messages */	KbdGetStatus(&keyInfo,0);	MouGetNumQueEl(&mqueue,_EVT_hMouse);	while (mqueue.cEvents) {		while (mqueue.cEvents--) {			memset(&evt,0,sizeof(evt));			mWait = MOU_NOWAIT;			MouReadEventQue(&mouse,&mWait,_EVT_hMouse);			/* Update the mouse position. We get the mouse coordinates			 * in mickeys so we have to translate these into pixels and			 * move our mouse position. If we don't do this, OS/2 gives			 * us the coordinates in character positions since it still			 * thinks we are in text mode!			 */			_EVT_mx += MickeyToPixel(mouse.col);			_EVT_my += MickeyToPixel(mouse.row);			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.where_x = _EVT_mx;			evt.where_y = _EVT_my;			evt.relative_x = mouse.col;			evt.relative_y = mouse.row;			evt.when = key.time;			if (mouse.fs & (MOUSE_BN1_DOWN | MOUSE_MOTION_WITH_BN1_DOWN))				evt.modifiers |= EVT_LEFTBUT;			if (mouse.fs & (MOUSE_BN2_DOWN | MOUSE_MOTION_WITH_BN2_DOWN))				evt.modifiers |= EVT_RIGHTBUT;			if (mouse.fs & (MOUSE_BN3_DOWN | MOUSE_MOTION_WITH_BN3_DOWN))				evt.modifiers |= EVT_MIDDLEBUT;			if (keyInfo.fsState & 0x0001)				evt.modifiers |= EVT_RIGHTSHIFT;			if (keyInfo.fsState & 0x0002)				evt.modifiers |= EVT_LEFTSHIFT;			if (keyInfo.fsState & 0x0100)				evt.modifiers |= EVT_LEFTCTRL;			if (keyInfo.fsState & 0x0200)				evt.modifiers |= EVT_LEFTALT;			if (keyInfo.fsState & 0x0400)				evt.modifiers |= EVT_RIGHTCTRL;			if (keyInfo.fsState & 0x0800)				evt.modifiers |= EVT_RIGHTALT;			/* Check for left mouse click events */			/* 0x06 == (MOUSE_BN1_DOWN | MOUSE_MOTION_WITH_BN1_DOWN) */			if (((mouse.fs & 0x0006) && !(oldMouseState & 0x0006))					|| (!(mouse.fs & 0x0006) && (oldMouseState & 0x0006))) {				if (mouse.fs & 0x0006)					evt.what = EVT_MOUSEDOWN;				else					evt.what = EVT_MOUSEUP;				evt.message = EVT_LEFTBMASK;				oldMove = -1;				if (count < EVENTQSIZE)					addEvent(&evt);				}			/* Check for right mouse click events */			/* 0x0018 == (MOUSE_BN2_DOWN | MOUSE_MOTION_WITH_BN2_DOWN) */			if (((mouse.fs & 0x0018) && !(oldMouseState & 0x0018))					|| (!(mouse.fs & 0x0018) && (oldMouseState & 0x0018))) {				if (mouse.fs & 0x0018)					evt.what = EVT_MOUSEDOWN;				else					evt.what = EVT_MOUSEUP;				evt.message = EVT_RIGHTBMASK;				oldMove = -1;				if (count < EVENTQSIZE)					addEvent(&evt);				}			/* Check for middle mouse click events */			/* 0x0060 == (MOUSE_BN3_DOWN | MOUSE_MOTION_WITH_BN3_DOWN) */			if (((mouse.fs & 0x0060) && !(oldMouseState & 0x0060))					|| (!(mouse.fs & 0x0060) && (oldMouseState & 0x0060))) {				if (mouse.fs & 0x0060)					evt.what = EVT_MOUSEDOWN;				else					evt.what = EVT_MOUSEUP;				evt.message = EVT_MIDDLEBMASK;				oldMove = -1;				if (count < EVENTQSIZE)					addEvent(&evt);				}			/* Check for mouse movement event */			if (mouse.fs & 0x002B) {				evt.what = EVT_MOUSEMOVE;				if (oldMove != -1) {					evtq[oldMove].where_x = evt.where_x;/* Modify existing one  */					evtq[oldMove].where_y = evt.where_y;					}

⌨️ 快捷键说明

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