{
memset (oldkeystate, 0, MGUI_NR_KEYS + 1); olddownkey = 0; status = 0; alt1 = 0; alt2 = 0; esc = 0; control1 = 0; control2 = 0; shift1 = 0; shift2 = 0; capslock = 0; caps_off = 1; numlock = 0; num_off = 1; slock = 0; slock_off = 1;
IAL_SetLeds (slock | (numlock << 1) | (capslock << 2));
__mg_event_timeout.tv_sec = 0;
__mg_event_timeout.tv_usec = timeoutusec; timeout_threshold = timeoutusec / 10000; repeat_threshold = repeatusec / 10000; timeout_count = timeout_threshold; }
(7)定义并初始化键盘相关的全局变量:长按、一直按和两个按键时间间隔
unsigned int __mg_key_longpress_time = 0;
unsigned int __mg_key_alwayspress_time = DEF_APRESS_TIME; unsigned int __mg_interval_time = DEF_INTERVAL_TIME;
(8)static void treat_longpress (PKEYEVENT ke, unsigned int interval)
函数作用:确定键盘的按键类型,包括: 0
KE_KEYDOWN KE_KEYLONGPRESS KE_KEYALWAYSPRESS
(9)BOOL GetLWEvent (int event, PLWEVENT lwe)
函数作用:根据事件event获取底层事件lwe的相关参数。将IAL_**类型的事件event转换为LWE_**类型的底层事件lwe。
(10)BOOL GUIAPI GetKeyStatus (UINT uKey)
函数作用:获取按键状态信息,包括鼠标按键和键盘按键
(11)DWORD GUIAPI GetShiftKeyStatus (void)
函数作用:获得是shift键的状态信息:return status;
(12)BOOL InitLWEvent (void)
函数作用:获得鼠标双击时间间隔,获得超时时间,初始化输入抽象层,充值鼠标和键盘 GetDblclickTime (); GetTimeout (); if (InitIAL ()) return FALSE; ResetMouseEvent(); ResetKeyEvent(); return TRUE;
(13)void TerminateLWEvent (void)
函数作用:结束底层事件
TerminateIAL ();
5、qvfb.h输入引擎的相关数据结构和宏定义
(1)定义鼠标和键盘的管道信息
#define QT_VFB_MOUSE_PIPE \ #define QT_VFB_KEYBOARD_PIPE \
(2)数据结构QVFbHeader
struct QVFbHeader {
int width; int height; int depth; int linestep; int dataoffset; RECT update; BYTE dirty; int numcols; unsigned int clut[256]; };
(3)定义qvfb的键盘事件数据结构
struct QVFbKeyData {
unsigned int unicode; unsigned int modifiers; BOOL press; BOOL repeat; };
(4)定义显示的数据结构
/* Private display data */ struct GAL_PrivateVideoData {
unsigned char* shmrgn; struct QVFbHeader* hdr; };
6、qvfb.c输入引擎相关的函数
(1)声明并定义以下函数:
static int QVFB_VideoInit(_THIS, GAL_PixelFormat *vformat);
static GAL_Rect **QVFB_ListModes(_THIS, GAL_PixelFormat *format, Uint32 flags);
static GAL_Surface *QVFB_SetVideoMode(_THIS, GAL_Surface *current, int width, int height, int bpp, Uint32 flags);
static int QVFB_SetColors(_THIS, int firstcolor, int ncolors, GAL_Color *colors); static void QVFB_VideoQuit(_THIS);
/* Hardware surface functions */
static int QVFB_AllocHWSurface(_THIS, GAL_Surface *surface); static void QVFB_FreeHWSurface(_THIS, GAL_Surface *surface);
(2)其他函数的定义:
static GAL_VideoDevice *QVFB_CreateDevice (int devindex) static void QVFB_UpdateRects (_THIS, int numrects, GAL_Rect *rects) static void QVFB_DeleteDevice (GAL_VideoDevice *device) static int QVFB_Available (void) 7、qvfbial.h
输入事件的相关数据结构和宏定义等
(1)定义鼠标和键盘的管道信息
#define QT_VFB_MOUSE_PIPE \ #define QT_VFB_KEYBOARD_PIPE \(2)定义qvfb的键盘事件数据结构
struct QVFbKeyData {
unsigned int unicode; unsigned int modifiers; BYTE press; BYTE repeat; };
(3)声明输入引擎初始化和终止函数
BOOL InitQVFBInput (INPUT* input, const char* mdev, const char* mtype);
void TermQVFBInput (void);
8、qvfbial.c输入事件的相关函数
(1)宏定义鼠标和键盘按键的数值
#define NOBUTTON 0x0000
#define LEFTBUTTON 0x0001 #define RIGHTBUTTON 0x0002 #define MIDBUTTON 0x0004 #define MOUSEBUTTONMASK 0x00FF
#define SHIFTBUTTON 0x0100 #define CONTROLBUTTON 0x0200 #define ALTBUTTON 0x0400 #define METABUTTON 0x0800 #define KEYBUTTONMASK 0x0FFF #define KEYPAD 0x4000
(2)定义并初始化与输入事件相关的参数
static int mouse_fd = -1; //鼠标文件描述符 static int kbd_fd = -1; //键盘文件描述符 static POINT mouse_pt; //鼠标位置 static int mouse_buttons; //鼠标按键
static struct QVFbKeyData kbd_data; //键盘数据 static unsigned char kbd_state [NR_KEYS]; //键盘状态 static unsigned char keycode_scancode [256];//键盘扫描码 static unsigned char nr_changed_keys = 0;
(3)static void init_code_map (void)
函数作用:初始化键盘扫描码
(4)static unsigned char keycode_to_scancode (unsigned char keycode, BOOL asscii)
函数作用:将键盘扫描码转化为ASCII码
(5)static int mouse_update (void)
函数作用:更新鼠标信息mouse_pt和mouse_buttons
(6)static void mouse_getxy (int *x, int* y)
函数作用:获得鼠标的位置信息 *x = mouse_pt.x;
*y = mouse_pt.y;
(7)static int mouse_getbutton (void)
函数作用:获取鼠标的button信息
(8)static int keyboard_update (void)
函数作用:更新鼠标信息,返回nr_changed_keys;
(9)static int read_key (void)
函数作用:读取键盘按键
(10)static const char* keyboard_getstate (void)
函数作用:获取键盘状态,return (char*)kbd_state;
(11)static int wait_event (int which, int maxfd, fd_set *in, fd_set *out, fd_set *except, struct timeval *timeout)
函数作用:从文件描述符获得输入事件,返回输入事件的类型
(12)BOOL InitQVFBInput (INPUT* input, const char* mdev, const char* mtype)
函数作用:初始化输入引擎,设置键盘和鼠标的文件描述符,为确定输入引擎的对输入事件的处理函数。
(13)void TermQVFBInput (void)
函数作用:关闭鼠标和键盘描述符。
if (mouse_fd >= 0) close (mouse_fd); if (kbd_fd >= 0) close (kbd_fd);
9、window.h与窗口和消息相关的宏定义和数据结构
(1)宏定义各种消息类型 (2)消息的数据结构MSG
typedef struct _MSG {
/** The handle to the window which receives this message. */ /** The message identifier. */ HWND hwnd; int message;
/** The first parameter of the message (32-bit integer). */ WPARAM wParam;
/** The second parameter of the message (32-bit integer). */ LPARAM lParam; /** Time*/
unsigned int time; #ifndef _LITE_VERSION /** Addtional data*/ void* pAdd; #endif } MSG;
typedef MSG* PMSG;
(3)宏定义消息队列的相关参数
#define QS_NOTIFYMSG 0x10000000 #ifndef _LITE_VERSION
#define QS_SYNCMSG 0x20000000 #else
#define QS_DESKTIMER 0x20000000 #endif
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库MINIGUI输入模块代码文件分析(2)在线全文阅读。
相关推荐: