static void msLinuxButton(DevicePtr pDev, ENQUEUEPROC enqueue, int buttons, BLOCK block) { GETPRIV; #define PRESS(b) \ do { \ enqueue(pDev, ButtonPress, 0, 0, NULL, block); \ } while (0) #define RELEASE(b) \ do { \ enqueue(pDev, ButtonRelease, 0, 0, NULL, block); \ } while (0) if ((buttons & button1) && !(priv->buttons & button1)) PRESS(1); if (!(buttons & button1) && (priv->buttons & button1)) RELEASE(1); if ((buttons & button2) && !(priv->buttons & button2)) PRESS(2); if (!(buttons & button2) && (priv->buttons & button2)) RELEASE(2); if ((buttons & button3) && !(priv->buttons & button3)) PRESS(3); if (!(buttons & button3) && (priv->buttons & button3)) RELEASE(3); if ((buttons & button4) && !(priv->buttons & button4)) PRESS(4); if (!(buttons & button4) && (priv->buttons & button4)) RELEASE(4); if ((buttons & button5) && !(priv->buttons & button5)) PRESS(5); if (!(buttons & button5) && (priv->buttons & button5)) RELEASE(5); priv->buttons = buttons; }
// test void main(void) { for (;;) { Sleep(6000); // wait for 6 seconds PRESS(VK_LEFT); Sleep(10); // hold it for 1/100'th of a second RELEASE(VK_LEFT); Sleep(1000); // wait for a second PRESS(VK_RIGHT); Sleep(10); // hold it for 1/100'th of a second RELEASE(VK_RIGHT); Sleep(1000); // wait for a second } }
static int ncurses_get_event(caca_display_t *dp, caca_privevent_t *ev) { int intkey; intkey = getch(); if(intkey == ERR) { ev->type = CACA_EVENT_NONE; return 0; } if(intkey < 0x7f) { ev->type = CACA_EVENT_KEY_PRESS; ev->data.key.ch = intkey; ev->data.key.utf32 = intkey; ev->data.key.utf8[0] = intkey; ev->data.key.utf8[1] = '\0'; return 1; } /* If the key was UTF-8, parse the whole sequence */ if(intkey >= 0x80 && intkey < 0x100) { int keys[7]; /* Necessary for ungetch(); */ char utf8[7]; uint32_t utf32; size_t i, bytes = 0; keys[0] = intkey; utf8[0] = intkey; for(i = 1; i < 6; i++) { keys[i] = getch(); utf8[i] = (unsigned char)keys[i]; } utf8[i] = '\0'; utf32 = caca_utf8_to_utf32(utf8, &bytes); while(i > bytes) ungetch(keys[--i]); if(bytes) { ev->type = CACA_EVENT_KEY_PRESS; ev->data.key.ch = 0; ev->data.key.utf32 = utf32; strcpy(ev->data.key.utf8, utf8); return 1; } } if(intkey == KEY_MOUSE) { MEVENT mevent; getmouse(&mevent); switch(mevent.bstate) { #define PRESS(x) ev->data.mouse.button = x; \ ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev) #define RELEASE(x) ev->data.mouse.button = x; \ ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev) #define CLICK(x) PRESS(x); RELEASE(x) case BUTTON1_PRESSED: PRESS(1); break; case BUTTON1_RELEASED: RELEASE(1); break; case BUTTON1_CLICKED: CLICK(1); break; case BUTTON1_DOUBLE_CLICKED: CLICK(1); CLICK(1); break; case BUTTON1_TRIPLE_CLICKED: CLICK(1); CLICK(1); CLICK(1); break; case BUTTON1_RESERVED_EVENT: break; case BUTTON2_PRESSED: PRESS(2); break; case BUTTON2_RELEASED: RELEASE(2); break; case BUTTON2_CLICKED: CLICK(2); break; case BUTTON2_DOUBLE_CLICKED: CLICK(2); CLICK(2); break; case BUTTON2_TRIPLE_CLICKED: CLICK(2); CLICK(2); CLICK(2); break; case BUTTON2_RESERVED_EVENT: break; case BUTTON3_PRESSED: PRESS(3); break; case BUTTON3_RELEASED: RELEASE(3); break; case BUTTON3_CLICKED: CLICK(3); break; case BUTTON3_DOUBLE_CLICKED: CLICK(3); CLICK(3); break; case BUTTON3_TRIPLE_CLICKED: CLICK(3); CLICK(3); CLICK(3); break; case BUTTON3_RESERVED_EVENT: break; case BUTTON4_PRESSED: PRESS(4); break; case BUTTON4_RELEASED: RELEASE(4); break; case BUTTON4_CLICKED: CLICK(4); break; case BUTTON4_DOUBLE_CLICKED: CLICK(4); CLICK(4); break; case BUTTON4_TRIPLE_CLICKED: CLICK(4); CLICK(4); CLICK(4); break; case BUTTON4_RESERVED_EVENT: break; default: break; #undef PRESS #undef RELEASE #undef CLICK } if(dp->mouse.x == mevent.x && dp->mouse.y == mevent.y) return _pop_event(dp, ev); dp->mouse.x = mevent.x; dp->mouse.y = mevent.y; ev->type = CACA_EVENT_MOUSE_MOTION; ev->data.mouse.x = dp->mouse.x; ev->data.mouse.y = dp->mouse.y; return 1; } switch(intkey) { case KEY_UP: ev->data.key.ch = CACA_KEY_UP; break; case KEY_DOWN: ev->data.key.ch = CACA_KEY_DOWN; break; case KEY_LEFT: ev->data.key.ch = CACA_KEY_LEFT; break; case KEY_RIGHT: ev->data.key.ch = CACA_KEY_RIGHT; break; case KEY_IC: ev->data.key.ch = CACA_KEY_INSERT; break; case KEY_DC: ev->data.key.ch = CACA_KEY_DELETE; break; case 0x7f: case KEY_BACKSPACE: ev->data.key.ch = CACA_KEY_BACKSPACE; break; case KEY_HOME: ev->data.key.ch = CACA_KEY_HOME; break; case KEY_END: ev->data.key.ch = CACA_KEY_END; break; case KEY_PPAGE: ev->data.key.ch = CACA_KEY_PAGEUP; break; case KEY_NPAGE: ev->data.key.ch = CACA_KEY_PAGEDOWN; break; case KEY_F(1): ev->data.key.ch = CACA_KEY_F1; break; case KEY_F(2): ev->data.key.ch = CACA_KEY_F2; break; case KEY_F(3): ev->data.key.ch = CACA_KEY_F3; break; case KEY_F(4): ev->data.key.ch = CACA_KEY_F4; break; case KEY_F(5): ev->data.key.ch = CACA_KEY_F5; break; case KEY_F(6): ev->data.key.ch = CACA_KEY_F6; break; case KEY_F(7): ev->data.key.ch = CACA_KEY_F7; break; case KEY_F(8): ev->data.key.ch = CACA_KEY_F8; break; case KEY_F(9): ev->data.key.ch = CACA_KEY_F9; break; case KEY_F(10): ev->data.key.ch = CACA_KEY_F10; break; case KEY_F(11): ev->data.key.ch = CACA_KEY_F11; break; case KEY_F(12): ev->data.key.ch = CACA_KEY_F12; break; default: /* Unknown key */ ev->type = CACA_EVENT_NONE; return 0; } ev->type = CACA_EVENT_KEY_PRESS; ev->data.key.utf32 = 0; ev->data.key.utf8[0] = '\0'; return 1; }