📄 event.c
字号:
evt.message = EVT.joyButState; evt.where_x = EVT.joyPrev[0]; evt.where_y = EVT.joyPrev[1]; evt.relative_x = EVT.joyPrev[2]; evt.relative_y = EVT.joyPrev[3]; addEvent(&evt); } _EVT_restoreInt(ps); } /* Read the joystick buttons, and post events to reflect the change * in state for the joystick buttons. */ if (newButState != EVT.joyButState) { if (EVT.count < EVENTQSIZE) { /* Add a new joystick movement event */ ps = _EVT_disableInt(); memset(&evt,0,sizeof(evt)); evt.what = EVT_JOYCLICK; evt.message = newButState; EVT.evtq[EVT.oldJoyMove].where_x = EVT.joyPrev[0]; EVT.evtq[EVT.oldJoyMove].where_y = EVT.joyPrev[1]; EVT.evtq[EVT.oldJoyMove].relative_x = EVT.joyPrev[2]; EVT.evtq[EVT.oldJoyMove].relative_y = EVT.joyPrev[3]; addEvent(&evt); _EVT_restoreInt(ps); } EVT.joyButState = newButState; } }}/****************************************************************************DESCRIPTION:Calibrates the joystick upper left positionHEADER:event.hREMARKS:This function can be used to zero in on better joystick calibration factors,which may work better than the default simplistic calibration (which assumesthe joystick is centered when the event library is initialised).To use this function, ask the user to hold the stick in the upper leftposition and then have them press a key or button. and then call thisfunction. This function will then read the joystick and update thecalibration factors.Usually, assuming that the stick was centered when the event library wasinitialized, you really only need to call EVT_joySetLowerRight since theupper left position is usually always 0,0 on most joysticks. However, thesafest procedure is to call all three calibration functions.SEE ALSO:EVT_joySetUpperLeft, EVT_joySetLowerRight, EVT_joyIsPresent****************************************************************************/void EVTAPI EVT_joySetUpperLeft(void){ _EVT_readJoyAxis(EVT_JOY_AXIS_ALL,EVT.joyMin);}/****************************************************************************DESCRIPTION:Calibrates the joystick lower right positionHEADER:event.hREMARKS:This function can be used to zero in on better joystick calibration factors,which may work better than the default simplistic calibration (which assumesthe joystick is centered when the event library is initialised).To use this function, ask the user to hold the stick in the lower rightposition and then have them press a key or button. and then call thisfunction. This function will then read the joystick and update thecalibration factors.Usually, assuming that the stick was centered when the event library wasinitialized, you really only need to call EVT_joySetLowerRight since theupper left position is usually always 0,0 on most joysticks. However, thesafest procedure is to call all three calibration functions.SEE ALSO:EVT_joySetUpperLeft, EVT_joySetCenter, EVT_joyIsPresent****************************************************************************/void EVTAPI EVT_joySetLowerRight(void){ _EVT_readJoyAxis(EVT_JOY_AXIS_ALL,EVT.joyMax);}/****************************************************************************DESCRIPTION:Calibrates the joystick center positionHEADER:event.hREMARKS:This function can be used to zero in on better joystick calibration factors,which may work better than the default simplistic calibration (which assumesthe joystick is centered when the event library is initialised).To use this function, ask the user to hold the stick in the centerposition and then have them press a key or button. and then call thisfunction. This function will then read the joystick and update thecalibration factors.Usually, assuming that the stick was centered when the event library wasinitialized, you really only need to call EVT_joySetLowerRight since theupper left position is usually always 0,0 on most joysticks. However, thesafest procedure is to call all three calibration functions.SEE ALSO:EVT_joySetUpperLeft, EVT_joySetLowerRight, EVT_joySetCenter****************************************************************************/void EVTAPI EVT_joySetCenter(void){ _EVT_readJoyAxis(EVT_JOY_AXIS_ALL,EVT.joyCenter);}#endif/****************************************************************************REMARKS:Pumps all messages in the message queue from Linux into our event queue.****************************************************************************/static void _EVT_pumpMessages(void){ event_t evt; int i,numkeys, c; ibool release; static struct kbentry ke; static char buf[KBDREADBUFFERSIZE]; static ushort repeatKey[128] = {0}; /* Poll keyboard events */ while (dataReady(_PM_console_fd) && (numkeys = read(_PM_console_fd, buf, KBDREADBUFFERSIZE)) > 0) { for (i = 0; i < numkeys; i++) { c = buf[i]; release = c & 0x80; c &= 0x7F; // TODO: This is wrong! We need this to be the time stamp at // ** interrupt ** time!! One solution would be to // put the keyboard and mouse polling loops into // a separate thread that can block on I/O to the // necessay file descriptor. evt.when = _EVT_getTicks(); if (release) { /* Key released */ evt.what = EVT_KEYUP; switch (c) { case KB_leftShift: _PM_modifiers &= ~EVT_LEFTSHIFT; break; case KB_rightShift: _PM_modifiers &= ~EVT_RIGHTSHIFT; break; case 29: _PM_modifiers &= ~(EVT_LEFTCTRL|EVT_CTRLSTATE); break; case 97: /* Control */ _PM_modifiers &= ~EVT_CTRLSTATE; break; case 56: _PM_modifiers &= ~(EVT_LEFTALT|EVT_ALTSTATE); break; case 100: _PM_modifiers &= ~EVT_ALTSTATE; break; default: } evt.modifiers = _PM_modifiers; evt.message = keyUpMsg[c]; if (EVT.count < EVENTQSIZE) addEvent(&evt); keyUpMsg[c] = 0; repeatKey[c] = 0; } else { /* Key pressed */ evt.what = EVT_KEYDOWN; switch (c) { case KB_leftShift: _PM_modifiers |= EVT_LEFTSHIFT; break; case KB_rightShift: _PM_modifiers |= EVT_RIGHTSHIFT; break; case 29: _PM_modifiers |= EVT_LEFTCTRL|EVT_CTRLSTATE; break; case 97: /* Control */ _PM_modifiers |= EVT_CTRLSTATE; break; case 56: _PM_modifiers |= EVT_LEFTALT|EVT_ALTSTATE; break; case 100: _PM_modifiers |= EVT_ALTSTATE; break; case KB_capsLock: /* Caps Lock */ _PM_leds ^= LED_CAP; ioctl(_PM_console_fd, KDSETLED, _PM_leds); break; case KB_numLock: /* Num Lock */ _PM_leds ^= LED_NUM; ioctl(_PM_console_fd, KDSETLED, _PM_leds); break; case KB_scrollLock: /* Scroll Lock */ _PM_leds ^= LED_SCR; ioctl(_PM_console_fd, KDSETLED, _PM_leds); break; default: } evt.modifiers = _PM_modifiers; if (keyUpMsg[c]) { evt.what = EVT_KEYREPEAT; evt.message = keyUpMsg[c] | (repeatKey[c]++ << 16); } else { int asc; evt.message = getKeyMapping(keymaps, NB_KEYMAPS, c) << 8; ke.kb_index = c; ke.kb_table = 0; if ((_PM_modifiers & EVT_SHIFTKEY) || (_PM_leds & LED_CAP)) ke.kb_table |= K_SHIFTTAB; if (_PM_modifiers & (EVT_LEFTALT | EVT_ALTSTATE)) ke.kb_table |= K_ALTTAB; if (ioctl(_PM_console_fd, KDGKBENT, (unsigned long)&ke)<0) perror("ioctl(KDGKBENT)"); if ((_PM_leds & LED_NUM) && (getKeyMapping(keypad, NB_KEYPAD, c)!=c)) { asc = getKeyMapping(keypad, NB_KEYPAD, c); } else { switch (c) { case 14: asc = ASCII_backspace; break; case 15: asc = ASCII_tab; break; case 28: case 96: asc = ASCII_enter; break; case 1: asc = ASCII_esc; default: asc = ke.kb_value & 0xFF; if (asc < 0x1B) asc = 0; break; } } if ((_PM_modifiers & (EVT_CTRLSTATE|EVT_LEFTCTRL)) && isalpha(asc)) evt.message |= toupper(asc) - 'A' + 1; else evt.message |= asc; keyUpMsg[c] = evt.message; repeatKey[c]++; } if (EVT.count < EVENTQSIZE) addEvent(&evt); } } } /* Poll mouse events */ if (_EVT_mouse_fd) { int dx, dy, buts; static int oldbuts; while (dataReady(_EVT_mouse_fd)) { if (readMouseData(&buts, &dx, &dy)) { EVT.mx += dx; EVT.my += dy; if (EVT.mx < 0) EVT.mx = 0; if (EVT.my < 0) EVT.my = 0; if (EVT.mx > range_x) EVT.mx = range_x; if (EVT.my > range_y) EVT.my = range_y; evt.where_x = EVT.mx; evt.where_y = EVT.my; evt.relative_x = dx; evt.relative_y = dy; // TODO: This is wrong! We need this to be the time stamp at // ** interrupt ** time!! One solution would be to // put the keyboard and mouse polling loops into // a separate thread that can block on I/O to the // necessay file descriptor. evt.when = _EVT_getTicks(); evt.modifiers = _PM_modifiers; if (buts & 4) evt.modifiers |= EVT_LEFTBUT; if (buts & 1) evt.modifiers |= EVT_RIGHTBUT; if (buts & 2) evt.modifiers |= EVT_MIDDLEBUT; /* Left click events */ if ((buts&4) != (oldbuts&4)) { if (buts&4) evt.what = EVT_MOUSEDOWN; else evt.what = EVT_MOUSEUP; evt.message = EVT_LEFTBMASK; EVT.oldMove = -1; if (EVT.count < EVENTQSIZE) addEvent(&evt); } /* Right click events */ if ((buts&1) != (oldbuts&1)) { if (buts&1) evt.what = EVT_MOUSEDOWN; else evt.what = EVT_MOUSEUP; evt.message = EVT_RIGHTBMASK; EVT.oldMove = -1; if (EVT.count < EVENTQSIZE) addEvent(&evt); } /* Middle click events */ if ((buts&2) != (oldbuts&2)) { if (buts&2) evt.what = EVT_MOUSEDOWN; else evt.what = EVT_MOUSEUP; evt.message = EVT_MIDDLEBMASK; EVT.oldMove = -1; if (EVT.count < EVENTQSIZE) addEvent(&evt); } /* Mouse movement event */ if (dx || dy) { evt.what = EVT_MOUSEMOVE; evt.message = 0; if (EVT.oldMove != -1) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -