diff --git a/README.md b/README.md index 8c26440..afeb92e 100644 --- a/README.md +++ b/README.md @@ -37,8 +37,6 @@ res = { x = 1920, y = 1080 } windowed = false # vertical sync vsync = false -# auto change to english ime mode -auto_ime = false # unlock all songs unlock_songs = true @@ -82,10 +80,16 @@ image_path = "" song_no = [] [drum] -# input interval (if you are using taiko drum controller, it should be set to 0) +# input interval (if using taiko drum controller, should be set to 0) wait_period = 4 [controller] # use analog input analog_input = false + +[keyboard] +# auto change to english ime mode +auto_ime = false +# use jp layout scan code (if using jp layout keyboard, must be set to true) +jp_layout = false ``` diff --git a/dist/config.toml b/dist/config.toml index 761bc88..f67baf7 100644 --- a/dist/config.toml +++ b/dist/config.toml @@ -11,7 +11,6 @@ version = "auto" res = { x = 1920, y = 1080 } windowed = false vsync = false -auto_ime = false unlock_songs = true [patches.chn00] @@ -42,3 +41,7 @@ wait_period = 4 [controller] analog_input = false + +[keyboard] +auto_ime = false +jp_layout = false \ No newline at end of file diff --git a/dist/keyconfig.toml b/dist/keyconfig.toml index 410edfc..35ac3e0 100644 --- a/dist/keyconfig.toml +++ b/dist/keyconfig.toml @@ -22,9 +22,9 @@ P2_RIGHT_RED = [] P2_RIGHT_BLUE = [] # ESCAPE F1 through F12 -# ` 1 through 0 -= BACKSPACE -# TAB QWERTYUIOP [ ] BACKSLASH -# CAPS_LOCK ASDFGHJKL ;' ENTER +# ` 1 through 0 -= BACKSPACE ^ YEN +# TAB QWERTYUIOP [ ] BACKSLASH @ +# CAPS_LOCK ASDFGHJKL ;' ENTER : # SHIFT ZXCVBNM , . SLASH # CONTROL L_WIN ALT SPACE R_WIN MENU # SCROLL_LOCK PAUSE INSERT DELETE HOME END PAGE_UP PAGE_DOWN diff --git a/src/bnusio.cpp b/src/bnusio.cpp index 9e34e2d..c861bb5 100644 --- a/src/bnusio.cpp +++ b/src/bnusio.cpp @@ -314,6 +314,8 @@ HOOK (u64, bngrw_reqWaitTouch, PROC_ADDRESS ("bngrw.dll", "BngRwReqWaitTouch"), void Init () { + SetKeyboardButtons (); + auto configPath = std::filesystem::current_path () / "config.toml"; std::unique_ptr config_ptr (openConfig (configPath), toml_free); if (config_ptr) { diff --git a/src/dllmain.cpp b/src/dllmain.cpp index 8785489..0c80673 100644 --- a/src/dllmain.cpp +++ b/src/dllmain.cpp @@ -22,6 +22,7 @@ char accessCode2[21] = "00000000000000000002"; char chipId1[33] = "00000000000000000000000000000001"; char chipId2[33] = "00000000000000000000000000000002"; bool autoIME = false; +bool jpLayout = false; HOOK (i32, ShowMouse, PROC_ADDRESS ("user32.dll", "ShowCursor"), bool) { return originalShowMouse (true); } HOOK (i32, ExitWindows, PROC_ADDRESS ("user32.dll", "ExitWindowsEx")) { ExitProcess (0); } @@ -125,9 +126,11 @@ DllMain (HMODULE module, DWORD reason, LPVOID reserved) { std::strcat (placeId, "0FF0"); } auto patches = openConfigSection (config, "patches"); - if (patches) { - version = readConfigString (patches, "version", version); - autoIME = readConfigBool (patches, "auto_ime", autoIME); + if (patches) version = readConfigString (patches, "version", version); + auto keyboard = openConfigSection (config, "keyboard"); + if (keyboard) { + autoIME = readConfigBool (keyboard, "auto_ime", autoIME); + jpLayout = readConfigBool (keyboard, "jp_layout", jpLayout); } } diff --git a/src/poll.cpp b/src/poll.cpp index 80cd22f..90c011e 100644 --- a/src/poll.cpp +++ b/src/poll.cpp @@ -2,10 +2,15 @@ #include "helpers.h" #include -struct { +extern bool jpLayout; + +struct KeyCodePair { const char *string; uint8_t keycode; -} ConfigKeyboardButtons[] = { +}; +size_t ConfigKeyboardButtonsCount = 0; +KeyCodePair *ConfigKeyboardButtons = nullptr; +KeyCodePair ConfigKeyboardButtons_US[] = { // Reference:https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes // Wayback Machine:https://web.archive.org/web/20231223135232/https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes // Row 1 @@ -126,7 +131,129 @@ struct { {"NUM3", VK_NUMPAD3}, {"NUM0", VK_NUMPAD0}, {"DECIMAL", VK_DECIMAL}, +}; +KeyCodePair ConfigKeyboardButtons_JP[] = { + // Reference:https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes + // Wayback Machine:https://web.archive.org/web/20231223135232/https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes + // Row 1 + {"ESCAPE", VK_ESCAPE}, + {"F1", VK_F1}, + {"F2", VK_F2}, + {"F3", VK_F3}, + {"F4", VK_F4}, + {"F5", VK_F5}, + {"F6", VK_F6}, + {"F7", VK_F7}, + {"F8", VK_F8}, + {"F9", VK_F9}, + {"F10", VK_F10}, + {"F11", VK_F11}, + {"F12", VK_F12}, + // Row 2 + {"1", '1'}, + {"2", '2'}, + {"3", '3'}, + {"4", '4'}, + {"5", '5'}, + {"6", '6'}, + {"7", '7'}, + {"8", '8'}, + {"9", '9'}, + {"0", '0'}, + {"-", VK_OEM_MINUS}, + {"^", VK_OEM_7}, + {"YEN", VK_OEM_5}, + {"BACKSPACE", VK_BACK}, + + // Row 3 + {"TAB", VK_TAB}, + {"Q", 'Q'}, + {"W", 'W'}, + {"E", 'E'}, + {"R", 'R'}, + {"T", 'T'}, + {"Y", 'Y'}, + {"U", 'U'}, + {"I", 'I'}, + {"O", 'O'}, + {"P", 'P'}, + {"@", VK_OEM_3}, + {"[", VK_OEM_4}, + + // Row 4 + {"CAPS_LOCK", VK_CAPITAL}, + {"A", 'A'}, + {"S", 'S'}, + {"D", 'D'}, + {"F", 'F'}, + {"G", 'G'}, + {"H", 'H'}, + {"J", 'J'}, + {"K", 'K'}, + {"L", 'L'}, + {";", VK_OEM_PLUS}, + {":", VK_OEM_1}, + {"]", VK_OEM_6}, + {"ENTER", VK_RETURN}, + + // Row 5 + {"SHIFT", VK_SHIFT}, + {"Z", 'Z'}, + {"X", 'X'}, + {"C", 'C'}, + {"V", 'V'}, + {"B", 'B'}, + {"N", 'N'}, + {"M", 'M'}, + {",", VK_OEM_COMMA}, + {".", VK_OEM_PERIOD}, + {"SLASH", VK_OEM_2}, + {"BACKSLASH", VK_OEM_102}, + + // Row 6 + {"CONTROL", VK_CONTROL}, + {"L_WIN", VK_LWIN}, + {"ALT", VK_MENU}, + {"SPACE", VK_SPACE}, + {"R_WIN", VK_RWIN}, + {"MENU", VK_APPS}, + + // Other Keys + // PrtSc is more important when making snapshots, therefore comment it as reserved + //{"PRINT_SCREEN", VK_SNAPSHOT}, + {"SCROLL_LOCK", VK_SCROLL}, + {"PAUSE", VK_PAUSE}, + {"INSERT", VK_INSERT}, + {"DELETE", VK_DELETE}, + {"HOME", VK_HOME}, + {"END", VK_END}, + {"PAGE_UP", VK_PRIOR}, + {"PAGE_DOWN", VK_NEXT}, + + // Arrow Keys + {"UPARROW", VK_UP}, + {"LEFTARROW", VK_LEFT}, + {"DOWNARROW", VK_DOWN}, + {"RIGHTARROW", VK_RIGHT}, + + // NUMPAD Keys + {"NUM_LOCK", VK_NUMLOCK}, + {"DIVIDE", VK_DIVIDE}, + {"MULTIPLY", VK_MULTIPLY}, + {"SUBTRACT", VK_SUBTRACT}, + {"NUM7", VK_NUMPAD7}, + {"NUM8", VK_NUMPAD8}, + {"NUM9", VK_NUMPAD9}, + {"ADD", VK_ADD}, + {"NUM4", VK_NUMPAD4}, + {"NUM5", VK_NUMPAD5}, + {"NUM6", VK_NUMPAD6}, + {"NUM1", VK_NUMPAD1}, + {"NUM2", VK_NUMPAD2}, + {"NUM3", VK_NUMPAD3}, + {"NUM0", VK_NUMPAD0}, + {"DECIMAL", VK_DECIMAL}, }; struct { @@ -192,6 +319,13 @@ SDLAxisState lastControllerAxisState; SDL_Window *window; SDL_GameController *controllers[255]; +void +SetKeyboardButtons () { + ConfigKeyboardButtonsCount = jpLayout ? COUNTOFARR (ConfigKeyboardButtons_JP) : COUNTOFARR (ConfigKeyboardButtons_US); + ConfigKeyboardButtons = (KeyCodePair *)malloc (ConfigKeyboardButtonsCount * sizeof (KeyCodePair)); + memcpy (ConfigKeyboardButtons, jpLayout ? ConfigKeyboardButtons_JP : ConfigKeyboardButtons_US, ConfigKeyboardButtonsCount * sizeof (KeyCodePair)); +} + void SetConfigValue (toml_table_t *table, const char *key, Keybindings *keybind) { toml_array_t *array = toml_array_in (table, key); @@ -389,7 +523,7 @@ DisposePoll () { ConfigValue StringToConfigEnum (const char *value) { ConfigValue rval; - for (size_t i = 0; i < COUNTOFARR (ConfigKeyboardButtons); ++i) + for (size_t i = 0; i < ConfigKeyboardButtonsCount; ++i) if (!strcmp (value, ConfigKeyboardButtons[i].string)) { rval.type = keycode; rval.keycode = ConfigKeyboardButtons[i].keycode; @@ -422,7 +556,7 @@ InternalButtonState GetInternalButtonState (Keybindings bindings) { InternalButtonState buttons = {0}; - for (size_t i = 0; i < COUNTOFARR (ConfigKeyboardButtons); i++) { + for (size_t i = 0; i < ConfigKeyboardButtonsCount; i++) { if (bindings.keycodes[i] == 0) continue; if (KeyboardIsReleased (bindings.keycodes[i])) buttons.Released = 1; if (KeyboardIsDown (bindings.keycodes[i])) buttons.Down = 1; diff --git a/src/poll.h b/src/poll.h index b7d6826..0d3e0cc 100644 --- a/src/poll.h +++ b/src/poll.h @@ -63,6 +63,7 @@ struct InternalButtonState { bool InitializePoll (HWND windowHandle); void UpdatePoll (HWND windowHandle); void DisposePoll (); +void SetKeyboardButtons (); ConfigValue StringToConfigEnum (const char *value); void SetConfigValue (toml_table_t *table, const char *key, Keybindings *keybind); InternalButtonState GetInternalButtonState (Keybindings bindings);