}
goto mouseret; }
if ( (oldbutton & IAL_MOUSE_LEFTBUTTON) && //如果前一个鼠标事件为单击 !(button & IAL_MOUSE_LEFTBUTTON) )//且当前事件不为左键单击事件 {
me->event = ME_LEFTUP; //鼠标事件类型为左键释放 goto mouseret; }
//如果前一个鼠标事件不是右击事件且当前事件为右击事件 if ( !(oldbutton & IAL_MOUSE_RIGHTBUTTON) && (button & IAL_MOUSE_RIGHTBUTTON) ) {
if (time2) { //如果time2不为0
interval = __mg_timer_counter - time2; //两次击键的时间间隔
if (interval <= dblclicktime)//如果两次击键的时间间隔小于双击的时间间隔 me->event = ME_RIGHTDBLCLICK; //鼠标事件为右键双击事件 else //两次击键的时间间隔大于双击的时间间隔 me->event = ME_RIGHTDOWN; //鼠标事件为右键单击事件 time2 = 0;//将time2置为0 } else {
time2 = __mg_timer_counter; //如果time2为0,将time2设置为当前的时间 me->event = ME_RIGHTDOWN; //鼠标事件为右键单击事件 }
goto mouseret; }
//如果前一个事件为鼠标右键单击事件且当前事件不为鼠标右键单击事件 if ( (oldbutton & IAL_MOUSE_RIGHTBUTTON) && !(button & IAL_MOUSE_RIGHTBUTTON) ) {
me->event = ME_RIGHTUP;//则鼠标事件为鼠标右键释放事件 goto mouseret; } }
//如果事件类型包含键盘事件 if (event & IAL_KEYEVENT) {//
int nr_keys = IAL_UpdateKeyboard ();//更新键盘信息
if (nr_keys == 0)//如果nr_keys为0,表示获取事件信息失败返,回0 return 0;
lwe->type = LWETYPE_KEY; //设置底层事件类型为LWETYPE_KEY
keystate = IAL_GetKeyboardState (); //获取键盘状态信息
//该循环的作用是判断哪个键按下或者弹起,记录相应事件的发生事件和扫描码等信息 for (i = 1; i < nr_keys; i++) {
if (!oldkeystate[i] && keystate[i]) { ke->event = KE_KEYDOWN; ke_time =__mg_timer_counter; ke->scancode = i; olddownkey = i; break; }
if (oldkeystate[i] && !keystate[i]) { ke->event = KE_KEYUP; ke->scancode = i; break; } }
if (i == nr_keys) { //如果将所有的键都扫描完
if (olddownkey == 0) //且没有键按下时,返回0,表示获取事件失败 return 0;
ke->scancode = olddownkey; //若有键按下,则键盘事件的扫描码就为olddownkey interval = __mg_timer_counter - ke_time; //计算时间间隔 treat_longpress (ke, interval);//判断按键类型 if (ke->event == 0) //表示获取事件失败 return 0; //返回0 }
make = (ke->event == KE_KEYDOWN)?1:0;
if (i != nr_keys) {//没有将所有的键都扫描完 unsigned leds; //用于点亮见哦按的三个LED灯
switch (ke->scancode) {
case SCANCODE_CAPSLOCK: //如果按键扫描码为大小写锁定键 if (make && caps_off) { //如果是按键消息且caps_off为1 capslock = 1 - capslock; //转换锁定状态
leds = slock | (numlock << 1) | (capslock << 2);//设置leds的值 IAL_SetLeds (leds);//用leds的值点亮对应的LED等 status = (DWORD)leds << 16;将leds加入状态信息 }
//如果是键释放消息,caps_off,如果是键按下消息,caps_off置0 caps_off = 1 - make;//设置caps_off的值 break;
case SCANCODE_NUMLOCK:
if (make && num_off) { numlock = 1 - numlock;
leds = slock | (numlock << 1) | (capslock << 2); IAL_SetLeds (leds);
status = (DWORD)leds << 16; }
num_off = 1 - make; break;
case SCANCODE_SCROLLLOCK: if (make & slock_off) { slock = 1 - slock;
leds = slock | (numlock << 1) | (capslock << 2); IAL_SetLeds (leds);
status = (DWORD)leds << 16; }
slock_off = 1 - make; break; //设置系统按键状态
case SCANCODE_LEFTCONTROL: control1 = make; break;
case SCANCODE_RIGHTCONTROL: control2 = make; break;
case SCANCODE_LEFTSHIFT: shift1 = make; break;
case SCANCODE_RIGHTSHIFT: shift2 = make; break;
case SCANCODE_LEFTALT: alt1 = make; break;
case SCANCODE_RIGHTALT: alt2 = make; break; }
//根据按键信息设置状态信息
status &= ~(MASK_KS_SHIFTKEYS);
status |= (DWORD)((capslock << 8) | (numlock << 7) | (slock << 6) | (control1 << 5) | (control2 << 4) | (alt1 << 3) | (alt2 << 2) | (shift1 << 1) | (shift2)); // Mouse button status
if (oldbutton & IAL_MOUSE_LEFTBUTTON) status |= KS_LEFTBUTTON;
else if (oldbutton & IAL_MOUSE_RIGHTBUTTON) status |= KS_RIGHTBUTTON; }
ke->status = status;
memcpy (oldkeystate, keystate, nr_keys); memcpy (&old_lwe, lwe, sizeof (LWEVENT)); return 1; }
old_lwe.type = 0; return 0; mouseret:
status &= ~(MASK_KS_BUTTONS); //鼠标按钮状态的掩码 oldbutton = button;
if (oldbutton & IAL_MOUSE_LEFTBUTTON) status |= KS_LEFTBUTTON;
if (oldbutton & IAL_MOUSE_RIGHTBUTTON) status |= KS_RIGHTBUTTON; me->status = status;
memcpy (&old_lwe, lwe, sizeof (LWEVENT)); return 1; }
8、将消息加入到消息队列中
/* post a message to a message queue */
BOOL QueueMessage (PMSGQUEUE msg_que, PMSG msg) {
LOCK_MSGQ(msg_que);
/* check whether the last message is MSG_MOUSEMOVE */
if (msg->message == MSG_MOUSEMOVE && msg->hwnd == HWND_DESKTOP && msg_que->readpos != msg_que->writepos) { PMSG last_msg;
if (msg_que->writepos == 0)
last_msg = msg_que->msg + msg_que->len - 1; else
last_msg = msg_que->msg + msg_que->writepos - 1;
if (last_msg->message == MSG_MOUSEMOVE
&& last_msg->wParam == msg->wParam && last_msg->hwnd == msg->hwnd) { last_msg->lParam = msg->lParam; last_msg->time = msg->time; goto ret; } }
if ((msg_que->writepos + 1) % msg_que->len == msg_que->readpos) { UNLOCK_MSGQ(msg_que); return FALSE; }
/* Write the data and advance write pointer */
msg_que->msg [msg_que->writepos] = *msg; //将消息加入消息队列
msg_que->writepos++;
if (msg_que->writepos >= msg_que->len) msg_que->writepos = 0; ret:
msg_que->dwState |= QS_POSTMSG; UNLOCK_MSGQ (msg_que); return TRUE; }