Skip to content

Instantly share code, notes, and snippets.

@nommiin
Last active March 1, 2026 06:01
Show Gist options
  • Select an option

  • Save nommiin/364d1c1b8a80f9e74fa373502a0fe242 to your computer and use it in GitHub Desktop.

Select an option

Save nommiin/364d1c1b8a80f9e74fa373502a0fe242 to your computer and use it in GitHub Desktop.
A basic shim for adding keyboard support to Minecraft Console Edition
#include "stdafx.h"
#include <Windows64\4JLibs\inc\4J_Input.h>
#include <Common\App_enums.h>
#include <Windows.h>
C_4JInput InputManager;
void C_4JInput::Initialise(int iInputStateC, unsigned char ucMapC, unsigned char ucActionC, unsigned char ucMenuActionC)
{
}
bool m_CurrentKeys[256] = {};
bool m_PreviousKeys[256] = {};
void C_4JInput::Tick(void)
{
for (int i = 0; i < 256; ++i)
{
m_PreviousKeys[i] = m_CurrentKeys[i];
m_CurrentKeys[i] = (GetAsyncKeyState(i) & 0x8000) != 0;
}
}
void C_4JInput::SetDeadzoneAndMovementRange(unsigned int uiDeadzone, unsigned int uiMovementRangeMax)
{
}
void C_4JInput::SetGameJoypadMaps(unsigned char ucMap, unsigned char ucAction, unsigned int uiActionVal)
{
}
unsigned int C_4JInput::GetGameJoypadMaps(unsigned char ucMap, unsigned char ucAction)
{
return 0;
}
void C_4JInput::SetJoypadMapVal(int iPad, unsigned char ucMap)
{
}
unsigned char C_4JInput::GetJoypadMapVal(int iPad)
{
return 0;
}
void C_4JInput::SetJoypadSensitivity(int iPad, float fSensitivity)
{
}
bool KeyDown(int key) {
return (GetAsyncKeyState(key) & 0x8000) != 0;
}
bool KeyPressed(int key) {
return m_CurrentKeys[key] && !m_PreviousKeys[key];
}
bool KeyReleased(int key) {
return !m_CurrentKeys[key] && m_PreviousKeys[key];
}
bool C_4JInput::ButtonPressed(int iPad, unsigned char ucAction)
{
switch (ucAction) {
case ACTION_MENU_UP: return KeyPressed(VK_UP);
case ACTION_MENU_DOWN: return KeyPressed(VK_DOWN);
case ACTION_MENU_LEFT: return KeyPressed(VK_LEFT);
case ACTION_MENU_RIGHT: return KeyPressed(VK_RIGHT);
case ACTION_MENU_OK:
case ACTION_MENU_A: return KeyPressed(VK_RETURN);
case ACTION_MENU_CANCEL:
case ACTION_MENU_B: return KeyPressed(VK_ESCAPE);
case MINECRAFT_ACTION_FORWARD: return KeyPressed('W');
case MINECRAFT_ACTION_BACKWARD: return KeyPressed('S');
case MINECRAFT_ACTION_LEFT: return KeyPressed('A');
case MINECRAFT_ACTION_RIGHT: return KeyPressed('D');
case MINECRAFT_ACTION_JUMP: return KeyPressed(VK_SPACE);
case MINECRAFT_ACTION_INVENTORY: return KeyPressed('E');
case MINECRAFT_ACTION_DROP: return KeyPressed('Q');
case MINECRAFT_ACTION_ACTION: return KeyPressed(VK_LBUTTON);
case MINECRAFT_ACTION_USE: return KeyPressed(VK_RBUTTON);
case MINECRAFT_ACTION_RENDER_THIRD_PERSON: return KeyPressed(VK_F5);
}
return false;
}
bool C_4JInput::ButtonReleased(int iPad, unsigned char ucAction)
{
switch (ucAction) {
case ACTION_MENU_UP: return KeyReleased(VK_UP);
case ACTION_MENU_DOWN: return KeyReleased(VK_DOWN);
case ACTION_MENU_LEFT: return KeyReleased(VK_LEFT);
case ACTION_MENU_RIGHT: return KeyReleased(VK_RIGHT);
case ACTION_MENU_OK:
case ACTION_MENU_A: return KeyReleased(VK_RETURN);
case ACTION_MENU_CANCEL:
case ACTION_MENU_B: return KeyReleased(VK_ESCAPE);
case MINECRAFT_ACTION_FORWARD: return KeyReleased('W');
case MINECRAFT_ACTION_BACKWARD: return KeyReleased('S');
case MINECRAFT_ACTION_LEFT: return KeyReleased('A');
case MINECRAFT_ACTION_RIGHT: return KeyReleased('D');
case MINECRAFT_ACTION_JUMP: return KeyReleased(VK_SPACE);
case MINECRAFT_ACTION_INVENTORY: return KeyReleased('E');
case MINECRAFT_ACTION_DROP: return KeyReleased('Q');
case MINECRAFT_ACTION_ACTION: return KeyReleased(VK_LBUTTON);
case MINECRAFT_ACTION_USE: return KeyReleased(VK_RBUTTON);
case MINECRAFT_ACTION_RENDER_THIRD_PERSON: return KeyReleased(VK_F5);
}
return false;
}
bool C_4JInput::ButtonDown(int iPad, unsigned char ucAction)
{
switch (ucAction) {
case ACTION_MENU_UP: return KeyDown(VK_UP);
case ACTION_MENU_DOWN: return KeyDown(VK_DOWN);
case ACTION_MENU_LEFT: return KeyDown(VK_LEFT);
case ACTION_MENU_RIGHT: return KeyDown(VK_RIGHT);
case ACTION_MENU_OK:
case ACTION_MENU_A: return KeyDown(VK_RETURN);
case ACTION_MENU_CANCEL:
case ACTION_MENU_B: return KeyDown(VK_ESCAPE);
case MINECRAFT_ACTION_FORWARD: return KeyDown('W');
case MINECRAFT_ACTION_BACKWARD: return KeyDown('S');
case MINECRAFT_ACTION_LEFT: return KeyDown('A');
case MINECRAFT_ACTION_RIGHT: return KeyDown('D');
case MINECRAFT_ACTION_JUMP: return KeyDown(VK_SPACE);
case MINECRAFT_ACTION_INVENTORY: return KeyDown('E');
case MINECRAFT_ACTION_DROP: return KeyDown('Q');
case MINECRAFT_ACTION_ACTION: return KeyDown(VK_LBUTTON);
case MINECRAFT_ACTION_USE: return KeyDown(VK_RBUTTON);
case MINECRAFT_ACTION_RENDER_THIRD_PERSON: return KeyDown(VK_F5);
}
return false;
}
bool C_4JInput::ButtonPressedDirect(int key) {
return KeyPressed(key);
}
unsigned int C_4JInput::GetValue(int iPad, unsigned char ucAction, bool bRepeat)
{
return ButtonDown(iPad, ucAction);
}
void C_4JInput::SetJoypadStickAxisMap(int iPad, unsigned int uiFrom, unsigned int uiTo)
{
}
void C_4JInput::SetJoypadStickTriggerMap(int iPad, unsigned int uiFrom, unsigned int uiTo)
{
}
void C_4JInput::SetKeyRepeatRate(float fRepeatDelaySecs, float fRepeatRateSecs)
{
}
void C_4JInput::SetDebugSequence(const char* chSequenceA, int(*Func)(LPVOID), LPVOID lpParam)
{
}
FLOAT C_4JInput::GetIdleSeconds(int iPad)
{
return 0.0f;
}
bool C_4JInput::IsPadConnected(int iPad)
{
if (iPad == 0) return true;
return false;
}
float C_4JInput::GetJoypadStick_LX(int iPad, bool bCheckMenuDisplay)
{
if (KeyDown('A')) {
return -1.0f;
} else if (KeyDown('D')) {
return 1.0f;
}
return 0.0f;
}
float C_4JInput::GetJoypadStick_LY(int iPad, bool bCheckMenuDisplay)
{
if (KeyDown('W')) {
return 1.0f;
} else if (KeyDown('S')) {
return -1.0f;
}
return 0.0f;
}
float C_4JInput::GetJoypadStick_RX(int iPad, bool bCheckMenuDisplay)
{
if (KeyDown(VK_LEFT)) {
return -1.0f;
} else if (KeyDown(VK_RIGHT)) {
return 1.0f;
}
return 0.0f;
}
float C_4JInput::GetJoypadStick_RY(int iPad, bool bCheckMenuDisplay)
{
if (KeyDown(VK_UP)) {
return 1.0f;
} else if (KeyDown(VK_DOWN)) {
return -1.0f;
}
return 0.0f;
}
unsigned char C_4JInput::GetJoypadLTrigger(int iPad, bool bCheckMenuDisplay)
{
if (KeyDown(VK_RBUTTON)) {
return 1;
}
return 0;
}
unsigned char C_4JInput::GetJoypadRTrigger(int iPad, bool bCheckMenuDisplay)
{
if (KeyDown(VK_LBUTTON)) {
return 1;
}
return 0;
}
void C_4JInput::SetMenuDisplayed(int iPad, bool bVal)
{
}
EKeyboardResult C_4JInput::RequestKeyboard(LPCWSTR Title, LPCWSTR Text, DWORD dwPad, UINT uiMaxChars, int( *Func)(LPVOID,const bool),LPVOID lpParam,C_4JInput::EKeyboardMode eMode)
{
return EKeyboard_Pending;
}
void C_4JInput::GetText(uint16_t* UTF16String)
{
}
bool C_4JInput::VerifyStrings(
WCHAR** pwStringA,
int iStringC,
int(*Func)(LPVOID, STRING_VERIFY_RESPONSE*),
LPVOID lpParam)
{
return false;
}
void C_4JInput::CancelQueuedVerifyStrings(
int(*Func)(LPVOID, STRING_VERIFY_RESPONSE*),
LPVOID lpParam)
{
}
void C_4JInput::CancelAllVerifyInProgress(void)
{
}
@BlackAnt1968601851
Copy link

BlackAnt1968601851 commented Mar 1, 2026

im getting compilation errors such as C_4JInput::ButtonPressedDirect(int key) not existing and etc.

and also this too
2>Minecraft.obj : error LNK2019: unresolved external symbol "public: __cdecl Input::Input(void)" (??0Input@@qeaa@XZ) referenced in function "public: class std::shared_ptr __cdecl Minecraft::createExtraLocalPlayer(int,class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > const &,int,int,class ClientConnection *,class MultiPlayerLevel *)" (?createExtraLocalPlayer@Minecraft@@qeaa?AV?$shared_ptr@VMultiplayerLocalPlayer@@@std@@HAEBV?$basic_string@_WU?$char_traits@_W@std@@v?$allocator@_W@2@@3@HHPEAVClientConnection@@PEAVMultiPlayerLevel@@@z)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment