From 802b0ebfdfac0dbf56efca3be043d9165bfa398c Mon Sep 17 00:00:00 2001 From: UniversePM Date: Wed, 26 Aug 2026 19:03:52 -0500 Subject: [PATCH] modernize input --- Minecraft.Client/Input.cpp | 103 ++++++++++++++++++++++++------------- Minecraft.Client/Input.h | 2 +- 2 files changed, 67 insertions(+), 38 deletions(-) diff --git a/Minecraft.Client/Input.cpp b/Minecraft.Client/Input.cpp index 402d98ba..85864316 100644 --- a/Minecraft.Client/Input.cpp +++ b/Minecraft.Client/Input.cpp @@ -7,6 +7,9 @@ #include "Input.h" #include "..\Minecraft.Client\LocalPlayer.h" #include "Options.h" +#ifdef _WINDOWS64 +#include "Windows64/KBMInput.h" +#endif Input::Input() { @@ -15,10 +18,10 @@ Input::Input() wasJumping = false; jumping = false; sneaking = false; + sprinting = false; lReset = false; rReset = false; - m_gamepadSneaking = false; } void Input::tick(LocalPlayer *player) @@ -43,20 +46,12 @@ void Input::tick(LocalPlayer *player) #ifdef _WINDOWS64 - // WASD movement (combine with gamepad) - if (iPad == 0) + if (iPad == 0 && g_KBMInput.IsMouseGrabbed() && g_KBMInput.IsKBMActive()) { - float kbX = 0.0f, kbY = 0.0f; - if (g_KBMInput.IsKeyDown('W')) kbY += 1.0f; - if (g_KBMInput.IsKeyDown('S')) kbY -= 1.0f; - if (g_KBMInput.IsKeyDown('A')) kbX += 1.0f; // inverted like gamepad - if (g_KBMInput.IsKeyDown('D')) kbX -= 1.0f; - // Normalize diagonal - if (kbX != 0.0f && kbY != 0.0f) { kbX *= 0.707f; kbY *= 0.707f; } - if (pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_LEFT) || pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_RIGHT)) - xa = max(min(xa + kbX, 1.0f), -1.0f); - if (pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_FORWARD) || pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_BACKWARD)) - ya = max(min(ya + kbY, 1.0f), -1.0f); + if( pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_LEFT) || pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_RIGHT) ) + kbXA = g_KBMInput.GetMoveX(); + if( pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_FORWARD) || pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_BACKWARD) ) + kbYA = g_KBMInput.GetMoveY(); } #endif #ifndef _CONTENT_PACKAGE @@ -81,16 +76,42 @@ void Input::tick(LocalPlayer *player) { if((player->ullButtonsPressed&(1LL<localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_SNEAK_TOGGLE)) { - m_gamepadSneaking=!m_gamepadSneaking; + sneaking=!sneaking; } } - sneaking = m_gamepadSneaking; #ifdef _WINDOWS64 - // Keyboard hold-to-sneak (overrides gamepad toggle) - if (iPad == 0 && g_KBMInput.IsKeyDown(VK_SHIFT) && !player->abilities.flying) - sneaking = true; -#endif + if (iPad == 0 && g_KBMInput.IsMouseGrabbed() && g_KBMInput.IsKBMActive()) + { + // Left Shift = sneak (hold to crouch) + if (pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_SNEAK_TOGGLE)) + { + if (!player->abilities.flying) + { + sneaking = g_KBMInput.IsKeyDown(KeyboardMouseInput::KEY_SNEAK); + } + } + + // Ctrl + forward = sprint (hold to sprint, including while flying) + { + bool ctrlHeld = g_KBMInput.IsKeyDown(KeyboardMouseInput::KEY_SPRINT); + bool movingForward = (kbYA > 0.0f); + + if (ctrlHeld && movingForward) + { + sprinting = true; + } + else + { + sprinting = false; + } + } + } + else if (iPad == 0) + { + sprinting = false; + } + #endif if(sneaking) { @@ -125,39 +146,47 @@ void Input::tick(LocalPlayer *player) } tx = ty = 0.0f; } - player->interpolateTurn(tx * abs(tx) * turnSpeed, ty * abs(ty) * turnSpeed); #ifdef _WINDOWS64 - // Mouse look (added after stick-based turn) - if (iPad == 0 && g_KBMInput.IsCaptured()) + if (iPad == 0 && g_KBMInput.IsMouseGrabbed() && g_KBMInput.IsKBMActive()) { - float mouseSensitivity = 1.25f; - float mdx = g_KBMInput.GetMouseDeltaX() * mouseSensitivity; - float mdy = -g_KBMInput.GetMouseDeltaY() * mouseSensitivity; - if (app.GetGameSettings(iPad, eGameSetting_ControlInvertLook)) - mdy = -mdy; - player->interpolateTurn(mdx, mdy); + float mouseSensitivity = static_cast(app.GetGameSettings(iPad, eGameSetting_Sensitivity_InGame)) / 100.0f; + float mouseLookScale = 5.0f; + float mx = g_KBMInput.GetLookX(mouseSensitivity * mouseLookScale); + float my = g_KBMInput.GetLookY(mouseSensitivity * mouseLookScale); + + if ( app.GetGameSettings(iPad,eGameSetting_ControlInvertLook) ) + { + my = -my; + } + + turnX += mx; + turnY += my; } #endif + player->interpolateTurn(tx * abs(tx) * turnSpeed, ty * abs(ty) * turnSpeed); + //jumping = controller.isButtonPressed(0); unsigned int jump = InputManager.GetValue(iPad, MINECRAFT_ACTION_JUMP); - if( jump > 0 && pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_JUMP) ) - jumping = true; - else - jumping = false; - + bool kbJump = false; #ifdef _WINDOWS64 - // Keyboard jump (Space) - if (iPad == 0 && g_KBMInput.IsKeyDown(VK_SPACE) && pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_JUMP)) - jumping = true; + kbJump = (iPad == 0) && g_KBMInput.IsMouseGrabbed() && g_KBMInput.IsKBMActive() && g_KBMInput.IsKeyDown(KeyboardMouseInput::KEY_JUMP); #endif + if( (jump > 0 || kbJump) && pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_JUMP) ) #ifndef _CONTENT_PACKAGE if (app.GetFreezePlayers()) jumping = false; #endif +#ifdef _WINDOWS64 + if (iPad == 0 && g_KBMInput.IsKeyPressed(VK_ESCAPE) && g_KBMInput.IsMouseGrabbed()) + { + g_KBMInput.SetMouseGrabbed(false); + } +#endif + //OutputDebugString("INPUT: End input tick\n"); } \ No newline at end of file diff --git a/Minecraft.Client/Input.h b/Minecraft.Client/Input.h index 84cd76de..3ca56024 100644 --- a/Minecraft.Client/Input.h +++ b/Minecraft.Client/Input.h @@ -10,6 +10,7 @@ public: bool wasJumping; bool jumping; bool sneaking; + bool sprinting; Input(); // 4J - added @@ -19,5 +20,4 @@ private: bool lReset; bool rReset; - bool m_gamepadSneaking; }; \ No newline at end of file