static void key(struct XWindow *xw, struct zr_input *in, XEvent *evt, zr_bool down) { int ret; KeySym *code = XGetKeyboardMapping(xw->dpy, (KeyCode)evt->xkey.keycode, 1, &ret); if (*code == XK_Shift_L || *code == XK_Shift_R) zr_input_key(in, ZR_KEY_SHIFT, down); else if (*code == XK_Delete) zr_input_key(in, ZR_KEY_DEL, down); else if (*code == XK_Return) zr_input_key(in, ZR_KEY_ENTER, down); else if (*code == XK_space) zr_input_key(in, ZR_KEY_SPACE, down); else if (*code == XK_Left) zr_input_key(in, ZR_KEY_LEFT, down); else if (*code == XK_Right) zr_input_key(in, ZR_KEY_RIGHT, down); else if (*code == XK_BackSpace) zr_input_key(in, ZR_KEY_BACKSPACE, down); else if (*code > 32 && *code < 128) { if (*code == 'c') zr_input_key(in, ZR_KEY_COPY, down && (evt->xkey.state & ControlMask)); else if (*code == 'v') zr_input_key(in, ZR_KEY_PASTE, down && (evt->xkey.state & ControlMask)); else if (*code == 'x') zr_input_key(in, ZR_KEY_CUT, down && (evt->xkey.state & ControlMask)); if (!down) zr_input_char(in, (char)*code); } XFree(code); }
static void zrmenu_input_gamepad(zrmenu_handle_t *zr) { switch (zr->action) { case MENU_ACTION_LEFT: zr_input_key(&zr->ctx, ZR_KEY_LEFT, 1); break; case MENU_ACTION_RIGHT: zr_input_key(&zr->ctx, ZR_KEY_RIGHT, 1); break; case MENU_ACTION_DOWN: zr_input_key(&zr->ctx, ZR_KEY_DOWN, 1); break; case MENU_ACTION_UP: zr_input_key(&zr->ctx, ZR_KEY_UP, 1); break; default: zr_input_key(&zr->ctx, ZR_KEY_UP, 0); zr_input_key(&zr->ctx, ZR_KEY_DOWN, 0); zr_input_key(&zr->ctx, ZR_KEY_LEFT, 0); zr_input_key(&zr->ctx, ZR_KEY_RIGHT, 0); break; } }
static void key(struct zr_input *in, MSG *msg, zr_bool down) { if (msg->lParam == VK_SHIFT) zr_input_key(in, ZR_KEY_SHIFT, down); else if (msg->lParam == VK_DELETE) zr_input_key(in, ZR_KEY_DEL, down); else if (msg->lParam == VK_RETURN) zr_input_key(in, ZR_KEY_ENTER, down); else if (msg->lParam == VK_SPACE) zr_input_key(in, ZR_KEY_SPACE, down); else if (msg->lParam == VK_BACK) zr_input_key(in, ZR_KEY_BACKSPACE, down); }
static void key(struct zr_input *in, SDL_Event *evt, zr_bool down) { const Uint8* state = SDL_GetKeyboardState(NULL); SDL_Keycode sym = evt->key.keysym.sym; if (sym == SDLK_RSHIFT || sym == SDLK_LSHIFT) zr_input_key(in, ZR_KEY_SHIFT, down); else if (sym == SDLK_DELETE) zr_input_key(in, ZR_KEY_DEL, down); else if (sym == SDLK_RETURN) zr_input_key(in, ZR_KEY_ENTER, down); else if (sym == SDLK_BACKSPACE) zr_input_key(in, ZR_KEY_BACKSPACE, down); else if (sym == SDLK_LEFT) zr_input_key(in, ZR_KEY_LEFT, down); else if (sym == SDLK_RIGHT) zr_input_key(in, ZR_KEY_RIGHT, down); else if (sym == SDLK_c) zr_input_key(in, ZR_KEY_COPY, down && state[SDL_SCANCODE_LCTRL]); else if (sym == SDLK_v) zr_input_key(in, ZR_KEY_PASTE, down && state[SDL_SCANCODE_LCTRL]); else if (sym == SDLK_x) zr_input_key(in, ZR_KEY_CUT, down && state[SDL_SCANCODE_LCTRL]); }