void CheckJoy() { uint8_t i, j, n; SDL_JoystickUpdate(); for (i = 0; i < 2; i++) { for (j = 0; j < DKEY_TOTAL; j++) { switch (g.cfg.PadDef[i].KeyDef[j].JoyEvType) { case AXIS: n = abs(g.cfg.PadDef[i].KeyDef[j].J.Axis) - 1; if (g.cfg.PadDef[i].KeyDef[j].J.Axis > 0) { if (SDL_JoystickGetAxis(g.PadState[i].JoyDev, n) > 16383) { bdown(i, j); } else { bup(i, j); } } else if (g.cfg.PadDef[i].KeyDef[j].J.Axis < 0) { if (SDL_JoystickGetAxis(g.PadState[i].JoyDev, n) < -16383) { bdown(i, j); } else { bup(i, j); } } break; case BUTTON: if (SDL_JoystickGetButton(g.PadState[i].JoyDev, g.cfg.PadDef[i].KeyDef[j].J.Button)) { bdown(i, j); } else { bup(i, j); } break; default: break; } } } CheckAnalog(); }
void CheckKeyboard() { uint8_t i, j, found; XEvent evt; XClientMessageEvent *xce; uint16_t Key; while (XPending(g.Disp)) { XNextEvent(g.Disp, &evt); switch (evt.type) { case ButtonPress: for(i = 0; i < 2; ++i) { if(g.cfg.PadDef[i].Type == PSE_PAD_TYPE_MOUSE) { switch(evt.xbutton.button) { case 1: bdown(i, 11); break; case 3: bdown(i, 10); break; } } } break; case ButtonRelease: for(i = 0; i < 2; ++i) { if(g.cfg.PadDef[i].Type == PSE_PAD_TYPE_MOUSE) { switch(evt.xbutton.button) { case 1: bup(i, 11); break; case 3: bup(i, 10); break; } } } break; case MotionNotify: g_currentMouse_X = evt.xmotion.x - 160; g_currentMouse_Y = evt.xmotion.y - 120; if( g_currentMouse_X < -128) g_currentMouse_X = -128; if( g_currentMouse_X > 127) g_currentMouse_X = 127; if( g_currentMouse_Y < -128) g_currentMouse_Y = -128; if( g_currentMouse_Y > 127) g_currentMouse_Y = 127; break; case KeyPress: Key = XLookupKeysym((XKeyEvent *)&evt, 0); found = 0; for (i = 0; i < 2; i++) { for (j = 0; j < DKEY_TOTAL; j++) { if (g.cfg.PadDef[i].KeyDef[j].Key == Key) { found = 1; bdown(i, j); } } } if (!found && !AnalogKeyPressed(Key)) { for (i=0 ; i < EMU_TOTAL ; i++) { if (Key == g.cfg.E.EmuDef[i].Mapping.Key /*&& g.cfg.E.EmuDef[i].Mapping.ReleaseEventPending == 0*/) { //printf("press %x %x and %x\n", Key, g.cfg.E.EmuDef[i].Mapping.Key, g.cfg.E.EmuDef[i].EmuKeyEvent); Key = g.cfg.E.EmuDef[i].EmuKeyEvent; //g.cfg.E.EmuDef[i].Mapping.ReleaseEventPending = 1; // joypad sends immediately release if enabled here i=EMU_TOTAL; } } g.KeyLeftOver = Key; } break; case KeyRelease: Key = XLookupKeysym((XKeyEvent *)&evt, 0); found = 0; for (i = 0; i < 2; i++) { for (j = 0; j < DKEY_TOTAL; j++) { if (g.cfg.PadDef[i].KeyDef[j].Key == Key) { found = 1; bup(i, j); } } } if (!found && !AnalogKeyReleased(Key)) { for (i=0 ; i < EMU_TOTAL ; i++) { if (Key == g.cfg.E.EmuDef[i].Mapping.Key) { //printf("release %x and %x\n", Key, g.cfg.E.EmuDef[i].EmuKeyEvent); Key = g.cfg.E.EmuDef[i].EmuKeyEvent; //g.cfg.E.EmuDef[i].Mapping.ReleaseEventPending = 0; i=EMU_TOTAL; } } g.KeyLeftOver = (long) ( Key | 0x40000000l ); } break; case ClientMessage: xce = (XClientMessageEvent *)&evt; if (xce->message_type == wmprotocols && (Atom)xce->data.l[0] == wmdelwindow) { // Fake an ESC key if user clicked the close button on window g.KeyLeftOver = XK_Escape; return; } break; } } g.PadState[0].MouseAxis[0][0] = g_currentMouse_X; g.PadState[0].MouseAxis[0][1] = g_currentMouse_Y; g_currentMouse_X *= 0.7; g_currentMouse_Y *= 0.7; if (g.cfg.PadDef[0].Type == PSE_PAD_TYPE_MOUSE || g.cfg.PadDef[1].Type == PSE_PAD_TYPE_MOUSE) { XWarpPointer(g.Disp, None, window, 0, 0, 0, 0, 160, 120); } }