From bdef1f9412d21757bc4a21ed905daff32fd0df27 Mon Sep 17 00:00:00 2001 From: daoge_cmd <3523206925@qq.com> Date: Sun, 1 Mar 2026 18:50:55 +0800 Subject: feat: add support for keyboard and mouse input --- Minecraft.Client/Minecraft.cpp | 76 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 71 insertions(+), 5 deletions(-) (limited to 'Minecraft.Client/Minecraft.cpp') diff --git a/Minecraft.Client/Minecraft.cpp b/Minecraft.Client/Minecraft.cpp index 1892fb36..7290d521 100644 --- a/Minecraft.Client/Minecraft.cpp +++ b/Minecraft.Client/Minecraft.cpp @@ -1452,6 +1452,21 @@ void Minecraft::run_middle() if(InputManager.ButtonPressed(i, MINECRAFT_ACTION_RENDER_THIRD_PERSON)) localplayers[i]->ullButtonsPressed|=1LL<ullButtonsPressed|=1LL<ullButtonsPressed |= 1LL<ullButtonsPressed |= 1LL<ullButtonsPressed |= 1LL<ullButtonsPressed |= 1LL<ullButtonsPressed |= 1LL<abilities.flying && KMInput.IsKeyDown(VK_SHIFT)) + localplayers[i]->ullButtonsPressed |= 1LL< 0 && gameMode->isInputAllowed(MINECRAFT_ACTION_LEFT_SCROLL)) wheel += 1; + else if (kbWheel < 0 && gameMode->isInputAllowed(MINECRAFT_ACTION_RIGHT_SCROLL)) wheel -= 1; + + // 1-9 keys for direct hotbar selection + if (gameMode->isInputAllowed(MINECRAFT_ACTION_LEFT_SCROLL)) + { + for (int k = '1'; k <= '9'; k++) + { + if (KMInput.IsKeyPressed(k)) + { + player->inventory->selected = k - '1'; + app.SetOpacityTimer(iPad); + break; + } + } + } + } +#endif if (wheel != 0) { player->inventory->swapPaint(wheel); @@ -3208,6 +3247,13 @@ void Minecraft::tick(bool bFirst, bool bUpdateTextures) player->handleMouseClick(0); player->lastClickTick[0] = ticks; } +#ifdef _WINDOWS64 + else if (iPad == 0 && KMInput.IsCaptured() && KMInput.IsMousePressed(0)) + { + player->handleMouseClick(0); + player->lastClickTick[0] = ticks; + } +#endif if (InputManager.ButtonDown(iPad, MINECRAFT_ACTION_ACTION) && ticks - player->lastClickTick[0] >= timer->ticksPerSecond / 4) { @@ -3215,8 +3261,19 @@ void Minecraft::tick(bool bFirst, bool bUpdateTextures) player->handleMouseClick(0); player->lastClickTick[0] = ticks; } +#ifdef _WINDOWS64 + else if (iPad == 0 && KMInput.IsCaptured() && KMInput.IsMouseDown(0) && ticks - player->lastClickTick[0] >= timer->ticksPerSecond / 4) + { + player->handleMouseClick(0); + player->lastClickTick[0] = ticks; + } +#endif - if(InputManager.ButtonDown(iPad, MINECRAFT_ACTION_ACTION) ) + if(InputManager.ButtonDown(iPad, MINECRAFT_ACTION_ACTION) +#ifdef _WINDOWS64 + || (iPad == 0 && KMInput.IsCaptured() && KMInput.IsMouseDown(0)) +#endif + ) { player->handleMouseDown(0, true ); } @@ -3237,14 +3294,23 @@ void Minecraft::tick(bool bFirst, bool bUpdateTextures) */ if( player->isUsingItem() ) { - if(!InputManager.ButtonDown(iPad, MINECRAFT_ACTION_USE)) gameMode->releaseUsingItem(player); + if(!InputManager.ButtonDown(iPad, MINECRAFT_ACTION_USE) +#ifdef _WINDOWS64 + && !(iPad == 0 && KMInput.IsCaptured() && KMInput.IsMouseDown(1)) +#endif + ) gameMode->releaseUsingItem(player); } else if( gameMode->isInputAllowed(MINECRAFT_ACTION_USE) ) { +#ifdef _WINDOWS64 + bool useButtonDown = InputManager.ButtonDown(iPad, MINECRAFT_ACTION_USE) || (iPad == 0 && KMInput.IsCaptured() && KMInput.IsMouseDown(1)); +#else + bool useButtonDown = InputManager.ButtonDown(iPad, MINECRAFT_ACTION_USE); +#endif if( player->abilities.instabuild ) { // 4J - attempt to handle click in special creative mode fashion if possible (used for placing blocks at regular intervals) - bool didClick = player->creativeModeHandleMouseClick(1, InputManager.ButtonDown(iPad, MINECRAFT_ACTION_USE) ); + bool didClick = player->creativeModeHandleMouseClick(1, useButtonDown ); // If this handler has put us in lastClick_oldRepeat mode then it is because we aren't placing blocks - behave largely as the code used to if( player->lastClickState == LocalPlayer::lastClick_oldRepeat ) { @@ -3256,7 +3322,7 @@ void Minecraft::tick(bool bFirst, bool bUpdateTextures) else { // Otherwise just the original game code for handling autorepeat - if (InputManager.ButtonDown(iPad, MINECRAFT_ACTION_USE) && ticks - player->lastClickTick[1] >= timer->ticksPerSecond / 4) + if (useButtonDown && ticks - player->lastClickTick[1] >= timer->ticksPerSecond / 4) { player->handleMouseClick(1); player->lastClickTick[1] = ticks; @@ -3272,7 +3338,7 @@ void Minecraft::tick(bool bFirst, bool bUpdateTextures) bool firstClick = ( player->lastClickTick[1] == 0 ); bool autoRepeat = ticks - player->lastClickTick[1] >= timer->ticksPerSecond / 4; if ( player->isRiding() || player->isSprinting() || player->isSleeping() ) autoRepeat = false; - if (InputManager.ButtonDown(iPad, MINECRAFT_ACTION_USE) ) + if (useButtonDown ) { // If the player has just exited a bed, then delay the time before a repeat key is allowed without releasing if(player->isSleeping() ) player->lastClickTick[1] = ticks + (timer->ticksPerSecond * 2); -- cgit v1.2.3