int KeyToPspButton(int deviceId, int key) { int search_start_layer = 0; int psp_button; if (FindKeyMapping(deviceId, key, &psp_button)) return psp_button; return KEYMAP_ERROR_UNKNOWN_KEY; }
void Main_OnKeyJoyEvent(SDL_Event evt) { int pressed = (evt.type == SDL_KEYDOWN || evt.type == SDL_JOYBUTTONDOWN); //int sourcetype = (evt.type == SDL_KEYDOWN || evt.type == SDL_KEYUP) ? EVKEY : EVJOY; //DEBUG if (pressed) printf("KeyDown %d\n", evt.key.keysym.sym); BYTE ukncscan = FindKeyMapping(evt.key.keysym.sym); if (ukncscan != 0) // UKNC event mapping found { Emulator_KeyboardEvent(ukncscan, pressed); } else if (pressed) // Commands works only on key/button press, not release { int command = FindCommandMapping(evt.key.keysym.sym); if (command != 0) // Command mapping found { Main_ExecuteCommand(command); } } }
// Handles SDL keyboard press/release and joystick button press/release events. void Main_OnKeyJoyEvent(SDL_Event evt) { KeyMappingStruct* mapping; int pressed = (evt.type == SDL_KEYDOWN || evt.type == SDL_JOYBUTTONDOWN); int sourcetype = (evt.type == SDL_KEYDOWN || evt.type == SDL_KEYUP) ? EVKEY : EVJOY; if (g_okKeyboard) // Onscreen keyboard mode { mapping = FindKeyMapping(sourcetype, evt.key.keysym.sym, TRUE); if (mapping == NULL) return; int command = mapping->resultcd; if (pressed) { switch (command) { case ID_MENU_ESCAPE: case ID_MENU: case ID_KEYBOARD: Main_ExecuteCommand(ID_KEYBOARD); return; case ID_MENU_UP: case ID_MENU_DOWN: case ID_MENU_LEFT: case ID_MENU_RIGHT: g_KeyboardCurrent = Main_KeyboardFindNearestKey(command); return; case ID_MENU_SELECT: Emulator_KeyboardEvent(m_arrKeyboardKeys[g_KeyboardCurrent].code, TRUE); break; default: break; } } else { if (command == ID_MENU_SELECT) { Emulator_KeyboardEvent(m_arrKeyboardKeys[g_KeyboardCurrent].code, FALSE); } } return; } mapping = FindKeyMapping(sourcetype, evt.key.keysym.sym, FALSE); if (mapping != NULL) // BK event mapping found { BYTE result = mapping->resultcd; if (mapping->resulttype == EVJOY) Emulator_JoystickEvent(result, pressed); else Emulator_KeyboardEvent(result, pressed); } else if (pressed) // Commands works only on key/button press, not release { mapping = FindKeyMapping(sourcetype, evt.key.keysym.sym, TRUE); if (mapping != NULL) // Command mapping found { Main_ExecuteCommand(mapping->resultcd); } } }
void Main_Menu() { int exitMenu = FALSE; int currentItem = 0; int redrawScreen = TRUE; const int menuItemCount = sizeof(m_MainMenuItems) / sizeof(MenuItemStruct); const int menuLeft = 12; const int menuWidth = 8 * 16; char progname[50]; char buffer[32]; sprintf(progname, "BKBTL SDL version %d.%d " __DATE__ " ", VERSION_MAJOR, VERSION_MINOR); while (!exitMenu) { if (redrawScreen) { Main_DrawScreen(); // Draw menu background SDL_Rect rc; rc.x = menuLeft - 8; rc.y = 8 - 4; rc.w = 16 + menuWidth; rc.h = 8 + 12 * menuItemCount; SDL_FillRect(g_Screen, &rc, SDL_MapRGB(g_Screen->format, 32, 32, 192)); // Draw selected item background rc.x = menuLeft - 4; rc.y = 8 - 1 + currentItem * 12; rc.w = 8 + menuWidth; rc.h = 11 + 2; SDL_FillRect(g_Screen, &rc, SDL_MapRGB(g_Screen->format, 192, 32, 32)); // Draw menu items int y = 8; for (int i = 0; i < menuItemCount; i++) { Font_DrawText(menuLeft, y + 12 * i, m_MainMenuItems[i].text); } // Emulator name and version number Font_DrawText(menuLeft, SCREEN_HEIGHT - 12, progname); // Last FPS sprintf(buffer, "FPS: %d, Delay: %d", g_LastFps, g_LastDelay); Font_DrawText(menuLeft, SCREEN_HEIGHT - 24, buffer); SDL_Flip(g_Screen); redrawScreen = FALSE; } SDL_Event evt; while (SDL_PollEvent(&evt)) { redrawScreen = TRUE; if (evt.type == SDL_QUIT) { g_okQuit = exitMenu = TRUE; break; } if (evt.type == SDL_KEYDOWN || evt.type == SDL_JOYBUTTONDOWN) { KeyMappingStruct* mapping = FindKeyMapping(1, evt.key.keysym.sym, TRUE); if (mapping != NULL) { switch (mapping->resultcd) { case ID_EXIT: g_okQuit = exitMenu = TRUE; break; case ID_MENU: case ID_MENU_ESCAPE: exitMenu = TRUE; break; case ID_MENU_UP: if (currentItem > 0) currentItem--; else currentItem = menuItemCount - 1; break; case ID_MENU_DOWN: if (currentItem < menuItemCount - 1) currentItem++; else currentItem = 0; break; case ID_MENU_RIGHT: case ID_MENU_SELECT: if (Main_ExecuteMenuCommand(m_MainMenuItems[currentItem].command, TRUE)) exitMenu = TRUE; break; case ID_MENU_LEFT: if (Main_ExecuteMenuCommand(m_MainMenuItems[currentItem].command, FALSE)) exitMenu = TRUE; break; default: break; } } } } SDL_Delay(50); } }
bool KeyToPspButton(int deviceId, int key, std::vector<int> *pspKeys) { return FindKeyMapping(deviceId, key, pspKeys); }