// Keyboard and mouse input polling. // // Call joeyInputPoll() once per frame (typically right before // drawing) to refresh both keyboard and mouse state. After polling, // the joeyKey* predicates return the current state of every key: // // joeyKeyDown(k) -- is key k held down right now // joeyKeyPressed(k) -- rising edge since the previous poll // joeyKeyReleased(k) -- falling edge since the previous poll // // And the mouse predicates return the pointer state: // // joeyMouseX/Y() -- pointer position in surface // coords (0..SURFACE_WIDTH-1, // 0..SURFACE_HEIGHT-1) // joeyMouseDown(b) -- is button b held right now // joeyMousePressed(b) -- rising edge since last poll // joeyMouseReleased(b) -- falling edge since last poll // // Edge predicates are one-shot: they return true only in the // frame the transition occurred and false thereafter. #ifndef JOEYLIB_INPUT_H #define JOEYLIB_INPUT_H #include "platform.h" #include "types.h" typedef enum { KEY_NONE = 0, KEY_A, KEY_B, KEY_C, KEY_D, KEY_E, KEY_F, KEY_G, KEY_H, KEY_I, KEY_J, KEY_K, KEY_L, KEY_M, KEY_N, KEY_O, KEY_P, KEY_Q, KEY_R, KEY_S, KEY_T, KEY_U, KEY_V, KEY_W, KEY_X, KEY_Y, KEY_Z, KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, KEY_8, KEY_9, KEY_SPACE, KEY_ESCAPE, KEY_RETURN, KEY_TAB, KEY_BACKSPACE, KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT, KEY_LSHIFT, KEY_RSHIFT, KEY_LCTRL, KEY_LALT, KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5, KEY_F6, KEY_F7, KEY_F8, KEY_F9, KEY_F10, KEY_COUNT } JoeyKeyE; typedef enum { MOUSE_BUTTON_NONE = 0, MOUSE_BUTTON_LEFT, MOUSE_BUTTON_RIGHT, MOUSE_BUTTON_MIDDLE, MOUSE_BUTTON_COUNT } JoeyMouseButtonE; void joeyInputPoll(void); bool joeyKeyDown(JoeyKeyE key); bool joeyKeyPressed(JoeyKeyE key); bool joeyKeyReleased(JoeyKeyE key); int16_t joeyMouseX(void); int16_t joeyMouseY(void); bool joeyMouseDown(JoeyMouseButtonE button); bool joeyMousePressed(JoeyMouseButtonE button); bool joeyMouseReleased(JoeyMouseButtonE button); #endif