Skip to main content

Overview

Minecraft Community Edition’s input system provides a platform-agnostic abstraction layer for handling input from keyboards, mice, and game controllers. The system supports multiple input sources and handles platform-specific implementations for PC, Xbox, PlayStation, and PS Vita.

Input Architecture

The input system is organized into three layers:
  1. Platform Layer - Platform-specific input capture (4J_Input)
  2. Abstraction Layer - Unified input interface (Input, ConsoleInput, KeyboardMouseInput)
  3. Game Layer - Input processing for player control and UI
┌─────────────────────────────────────┐
│     Game Layer (Player, Screen)      │
├─────────────────────────────────────┤
│   Abstraction (Input, ConsoleInput)  │
├─────────────────────────────────────┤
│   Platform (4J_Input, SDL, Windows)  │
└─────────────────────────────────────┘

Input Base Class

The Input class provides the core abstraction for player movement input:
class Input
{
public:
    float xa;           // X-axis movement (-1 to 1)
    float ya;           // Y-axis movement (forward/back, -1 to 1)
    
    bool wasJumping;    // Previous jump state
    bool jumping;       // Current jump state
    bool sneaking;      // Sneak/crouch state
    bool sprinting;     // Sprint state
    
    virtual void tick(LocalPlayer *player);
};
Source: Minecraft.Client/Input.h:4

Input Processing

The tick() method is called every game tick to update input state:
virtual void tick(LocalPlayer *player);
Implementations read from input devices and update movement/action states.

Keyboard and Mouse Input

The KeyboardMouseInput class handles PC keyboard and mouse input:

KeyboardMouseInput Class

class KeyboardMouseInput
{
public:
    static const int MAX_KEYS = 256;
    static const int MAX_MOUSE_BUTTONS = 3;
    
    // Mouse button constants
    static const int MOUSE_LEFT = 0;
    static const int MOUSE_RIGHT = 1;
    static const int MOUSE_MIDDLE = 2;
    
    void Init();
    void Tick();
    void ClearAllState();
};
Source: Minecraft.Client/KeyboardMouseInput.h:5

Keyboard State

Key State Query:
bool IsKeyDown(int vkCode) const;        // Currently held
bool IsKeyPressed(int vkCode) const;     // Just pressed this frame
bool IsKeyReleased(int vkCode) const;    // Just released this frame
Source: Minecraft.Client/KeyboardMouseInput.h:42 Key Events:
void OnKeyDown(int vkCode);   // Called when key is pressed
void OnKeyUp(int vkCode);     // Called when key is released
Source: Minecraft.Client/KeyboardMouseInput.h:34

Mouse State

Button State Query:
bool IsMouseButtonDown(int button) const;       // Currently held
bool IsMouseButtonPressed(int button) const;    // Just clicked
bool IsMouseButtonReleased(int button) const;   // Just released
Source: Minecraft.Client/KeyboardMouseInput.h:46 Mouse Position:
int GetMouseX() const;        // Screen X coordinate
int GetMouseY() const;        // Screen Y coordinate
int GetMouseDeltaX() const;   // Movement since last frame
int GetMouseDeltaY() const;   // Movement since last frame
Source: Minecraft.Client/KeyboardMouseInput.h:50 Mouse Events:
void OnMouseButtonDown(int button);
void OnMouseButtonUp(int button);
void OnMouseMove(int x, int y);
void OnMouseWheel(int delta);
void OnRawMouseDelta(int dx, int dy);  // For FPS camera control
Source: Minecraft.Client/KeyboardMouseInput.h:36

Mouse Capture

Grab/Release Mouse:
void SetMouseGrabbed(bool grabbed);    // Capture for FPS camera
bool IsMouseGrabbed() const;
When grabbed:
  • Mouse is hidden
  • Cursor is locked to window
  • Raw delta values used for camera
Source: Minecraft.Client/KeyboardMouseInput.h:58 Cursor Visibility:
void SetCursorHiddenForUI(bool hidden);
bool IsCursorHiddenForUI() const;

void SetScreenCursorHidden(bool hidden);
bool IsScreenCursorHidden() const;
Source: Minecraft.Client/KeyboardMouseInput.h:61

Window Focus

void SetWindowFocused(bool focused);
bool IsWindowFocused() const;
Input is typically ignored when window is not focused. Source: Minecraft.Client/KeyboardMouseInput.h:64

Keyboard/Mouse Activation

void SetKBMActive(bool active);    // Enable/disable KB/M input
bool IsKBMActive() const;

bool HasAnyInput() const;          // Any input received this frame
Source: Minecraft.Client/KeyboardMouseInput.h:67

Movement Input

float GetMoveX() const;                    // Strafe (-1 to 1)
float GetMoveY() const;                    // Forward/back (-1 to 1)
float GetLookX(float sensitivity) const;   // Camera X rotation
float GetLookY(float sensitivity) const;   // Camera Y rotation
Source: Minecraft.Client/KeyboardMouseInput.h:75

Default Key Bindings

static const int KEY_FORWARD = 'W';
static const int KEY_BACKWARD = 'S';
static const int KEY_LEFT = 'A';
static const int KEY_RIGHT = 'D';
static const int KEY_JUMP = VK_SPACE;
static const int KEY_SNEAK = VK_LSHIFT;
static const int KEY_SPRINT = VK_LCONTROL;
static const int KEY_INVENTORY = 'E';
static const int KEY_DROP = 'Q';
static const int KEY_CRAFTING = VK_TAB;
static const int KEY_CRAFTING_ALT = 'R';
static const int KEY_PAUSE = VK_ESCAPE;
static const int KEY_THIRD_PERSON = VK_F5;
static const int KEY_DEBUG_INFO = VK_F3;
Source: Minecraft.Client/KeyboardMouseInput.h:15

Global Instance

extern KeyboardMouseInput g_KBMInput;  // Global singleton
Source: Minecraft.Client/KeyboardMouseInput.h:121

Console Input (Gamepad)

The console editions use gamepad input through the ConsoleInput and C_4JInput classes:

ConsoleInput Class

class ConsoleInput
{
public:
    wstring msg;                // Text input result
    ConsoleInputSource *source; // Input source (player controller)
    
    ConsoleInput(const wstring& msg, ConsoleInputSource *source);
};
Source: Minecraft.Client/ConsoleInput.h:5 Used for text input results from virtual keyboards on consoles.

4J Input Manager

The C_4JInput class provides the low-level gamepad interface:
class C_4JInput
{
public:
    void Initialise(int iInputStateC, unsigned char ucMapC, 
                    unsigned char ucActionC, unsigned char ucMenuActionC);
    void Tick(void);
};
Source: Platform-specific 4J_Input.h files

Gamepad Button Mapping

Buttons are mapped to a unified button mask system:
// Xbox 360 style button mapping
#define _360_JOY_BUTTON_A          0x00000001
#define _360_JOY_BUTTON_B          0x00000002
#define _360_JOY_BUTTON_X          0x00000004
#define _360_JOY_BUTTON_Y          0x00000008
#define _360_JOY_BUTTON_START      0x00000010
#define _360_JOY_BUTTON_BACK       0x00000020
#define _360_JOY_BUTTON_RB         0x00000040
#define _360_JOY_BUTTON_LB         0x00000080
#define _360_JOY_BUTTON_RTHUMB     0x00000100
#define _360_JOY_BUTTON_LTHUMB     0x00000200
#define _360_JOY_BUTTON_DPAD_UP    0x00000400
#define _360_JOY_BUTTON_DPAD_DOWN  0x00000800
#define _360_JOY_BUTTON_DPAD_LEFT  0x00001000
#define _360_JOY_BUTTON_DPAD_RIGHT 0x00002000
#define _360_JOY_BUTTON_RT         0x00400000
#define _360_JOY_BUTTON_LT         0x00800000
Source: Minecraft.Client/PSVita/4JLibs/inc/4J_Input.h:10

PlayStation Button Mapping

PS Vita and PlayStation buttons are mapped to Xbox equivalents:
#define _PSV_JOY_BUTTON_X        _360_JOY_BUTTON_A
#define _PSV_JOY_BUTTON_O        _360_JOY_BUTTON_B
#define _PSV_JOY_BUTTON_SQUARE   _360_JOY_BUTTON_X
#define _PSV_JOY_BUTTON_TRIANGLE _360_JOY_BUTTON_Y
#define _PSV_JOY_BUTTON_START    _360_JOY_BUTTON_START
#define _PSV_JOY_BUTTON_SELECT   _360_JOY_BUTTON_BACK
#define _PSV_JOY_BUTTON_R1       _360_JOY_BUTTON_RB
#define _PSV_JOY_BUTTON_L1       _360_JOY_BUTTON_LB
#define _PSV_JOY_BUTTON_R2       _360_JOY_BUTTON_RT
#define _PSV_JOY_BUTTON_L2       _360_JOY_BUTTON_LT
Source: Minecraft.Client/PSVita/4JLibs/inc/4J_Input.h:43

Gamepad State Query

Button State:
unsigned int GetValue(int iPad, unsigned char ucAction, bool bRepeat=false);
bool ButtonPressed(int iPad, unsigned char ucAction=255);  // Toggled
bool ButtonReleased(int iPad, unsigned char ucAction);      // Toggled
bool ButtonDown(int iPad, unsigned char ucAction=255);      // Held
Source: Minecraft.Client/PSVita/4JLibs/inc/4J_Input.h:119 Analog Sticks:
// Returns -1.0 to 1.0
float GetJoypadStick_LX(int iPad, bool bCheckMenuDisplay=true);
float GetJoypadStick_LY(int iPad, bool bCheckMenuDisplay=true);
float GetJoypadStick_RX(int iPad, bool bCheckMenuDisplay=true);
float GetJoypadStick_RY(int iPad, bool bCheckMenuDisplay=true);
Source: Minecraft.Client/PSVita/4JLibs/inc/4J_Input.h:137 Triggers:
// Returns 0 to 255
unsigned char GetJoypadLTrigger(int iPad, bool bCheckMenuDisplay=true);
unsigned char GetJoypadRTrigger(int iPad, bool bCheckMenuDisplay=true);
Source: Minecraft.Client/PSVita/4JLibs/inc/4J_Input.h:141

Gamepad Configuration

Deadzone and Sensitivity:
void SetDeadzoneAndMovementRange(unsigned int uiDeadzone, 
                                  unsigned int uiMovementRangeMax);
void SetJoypadSensitivity(int iPad, float fSensitivity);
Source: Minecraft.Client/PSVita/4JLibs/inc/4J_Input.h:113 Control Schemes:
// Remap stick axes (for southpaw, legacy controls, etc.)
void SetJoypadStickAxisMap(int iPad, unsigned int uiFrom, unsigned int uiTo);
void SetJoypadStickTriggerMap(int iPad, unsigned int uiFrom, unsigned int uiTo);
Axis Maps:
#define AXIS_MAP_LX  0  // Left stick X
#define AXIS_MAP_LY  1  // Left stick Y
#define AXIS_MAP_RX  2  // Right stick X
#define AXIS_MAP_RY  3  // Right stick Y
Source: Minecraft.Client/PSVita/4JLibs/inc/4J_Input.h:70

Controller Detection

bool IsPadConnected(int iPad);
FLOAT GetIdleSeconds(int iPad);  // Time since last input
Source: Minecraft.Client/PSVita/4JLibs/inc/4J_Input.h:128

Key Repeat

For menu navigation:
void SetKeyRepeatRate(float fRepeatDelaySecs, float fRepeatRateSecs);
Source: Minecraft.Client/PSVita/4JLibs/inc/4J_Input.h:126
void SetMenuDisplayed(int iPad, bool bVal);
When a menu is displayed, some input behavior changes (e.g., stick input for cursor). Source: Minecraft.Client/PSVita/4JLibs/inc/4J_Input.h:146

Input Manager Singleton

extern C_4JInput InputManager;  // Global singleton
Source: Minecraft.Client/PSVita/4JLibs/inc/4J_Input.h:177

Touch Input (PS Vita)

The PS Vita version supports touchscreen input:

Touch Data

SceTouchData* GetTouchPadData(int iPad, bool bCheckMenuDisplay);
Source: Minecraft.Client/PSVita/4JLibs/inc/4J_Input.h:144

Touch Mapping

void MapTouchInput(int iPad, unsigned int uiActionVal);
Maps touch regions to button actions. Source: Minecraft.Client/PSVita/4JLibs/inc/4J_Input.h:134

Virtual Keyboard

Console platforms use virtual keyboards for text input:

Keyboard Modes

enum EKeyboardMode
{
    EKeyboardMode_Default,
    EKeyboardMode_Numeric,
    EKeyboardMode_Password,
    EKeyboardMode_Alphabet,
    EKeyboardMode_Full,
    EKeyboardMode_Alphabet_Extended,
    EKeyboardMode_IP_Address,
    EKeyboardMode_Phone
};
Source: Minecraft.Client/PSVita/4JLibs/inc/4J_Input.h:99

Requesting Keyboard

EKeyboardResult RequestKeyboard(LPCWSTR Title, LPCWSTR Text, DWORD dwPad, 
                                 UINT uiMaxChars, 
                                 int (*Func)(LPVOID, const bool), LPVOID lpParam,
                                 EKeyboardMode eMode);
Keyboard Results:
enum EKeyboardResult
{
    EKeyboard_Pending,
    EKeyboard_Cancelled,
    EKeyboard_ResultAccept,
    EKeyboard_ResultDecline
};
Source: Minecraft.Client/PSVita/4JLibs/inc/4J_Input.h:79

Retrieving Text

void GetText(uint16_t *UTF16String);
Retrieves the text entered via virtual keyboard. Source: Minecraft.Client/PSVita/4JLibs/inc/4J_Input.h:151

Key Mappings

The Options class stores configurable key bindings:
class Options
{
public:
    KeyMapping *keyUp;
    KeyMapping *keyLeft;
    KeyMapping *keyDown;
    KeyMapping *keyRight;
    KeyMapping *keyJump;
    KeyMapping *keyBuild;
    KeyMapping *keyDrop;
    KeyMapping *keyChat;
    KeyMapping *keySneak;
    KeyMapping *keyAttack;
    KeyMapping *keyUse;
    KeyMapping *keyPlayerList;
    KeyMapping *keyPickItem;
    KeyMapping *keyToggleFog;
    
    static const int keyMappings_length = 14;
    KeyMapping *keyMappings[keyMappings_length];
};
Source: Minecraft.Client/Options.h:74

Key Mapping Access

wstring getKeyDescription(int i);    // Get key name
wstring getKeyMessage(int i);        // Get action name
void setKey(int i, int key);         // Rebind key
Source: Minecraft.Client/Options.h:117

Input Settings

Input-related settings in the Options class:
float sensitivity;       // Mouse/stick sensitivity (0.0-1.0)
bool invertYMouse;       // Invert Y-axis
Source: Minecraft.Client/Options.h:62

Multi-Player Input

The input system supports up to 4 simultaneous players:
#define XUSER_MAX_COUNT 4  // Maximum players

int iPad = minecraft->player->GetXboxPad();  // Get player's controller index
Each player has:
  • Independent controller
  • Separate input state
  • Own viewport (in split-screen)
  • Individual settings

Input Processing Flow

Game Input (In-World)

  1. Platform Layer captures hardware input
  2. Input Manager processes and filters input
  3. Input::tick() updates movement state
  4. LocalPlayer applies movement to player entity
  5. Game updates physics and world state

UI Input (Screens)

  1. Platform Layer captures hardware input
  2. Screen::updateEvents() polls for input events
  3. Screen::mouseEvent() / keyboardEvent() process events
  4. Screen::mouseClicked() / keyPressed() handle specific actions
  5. Screen::buttonClicked() receives button callbacks
Source: Minecraft.Client/Screen.cpp:104

Platform-Specific Input

Windows PC

  • Uses Windows message loop for keyboard/mouse
  • Raw input for camera control
  • DirectInput for gamepad support
  • XInput for Xbox controllers

Xbox (Durango)

  • Native XInput for controllers
  • Kinect support (voice/gesture)
  • Smart Glass integration

PlayStation 3

  • Cell SPU optimized input processing
  • SIXAXIS motion support
  • PlayStation Network integration

PlayStation Vita

  • Front and rear touchscreen
  • Motion sensors (gyroscope/accelerometer)
  • Hardware buttons and analog sticks
  • Vita TV mode (controller-only)

Checking Platform

bool IsVitaTV();  // Check if running on Vita TV
Source: Minecraft.Client/PSVita/4JLibs/inc/4J_Input.h:171

Text Input Validation

For online play, user text is validated:
bool VerifyStrings(WCHAR **pwStringA, int iStringC,
                   int (*Func)(LPVOID, STRING_VERIFY_RESPONSE *), 
                   LPVOID lpParam);

void CancelQueuedVerifyStrings(int (*Func)(LPVOID, STRING_VERIFY_RESPONSE *),
                                LPVOID lpParam);

void CancelAllVerifyInProgress(void);
Source: Minecraft.Client/PSVita/4JLibs/inc/4J_Input.h:167 Used to filter offensive language in:
  • Chat messages
  • World names
  • Player usernames
  • Signs and books

Circle/Cross Swap (PlayStation)

PlayStation regions have different button conventions:
void SetCircleCrossSwapped(bool swapped);
bool IsCircleCrossSwapped();
Japan typically uses Circle for confirm, while Western regions use Cross. Source: Minecraft.Client/PSVita/4JLibs/inc/4J_Input.h:130

Best Practices

Input Handling

  1. Check for input availability before processing
  2. Respect menu state - disable game input when UI is open
  3. Handle controller disconnect gracefully
  4. Support all control schemes (default, southpaw, legacy)
  5. Apply deadzone to analog sticks
  6. Smooth camera input using delta values
  7. Validate text input for online features

Multi-Player Support

  1. Index by player (iPad/controller index)
  2. Check connection state before reading input
  3. Handle hot-plugging (controllers connecting/disconnecting)
  4. Show appropriate prompts per platform (“Press A” vs “Press X”)
  5. Respect per-player settings (sensitivity, inversion)

Platform Compatibility

  1. Use abstraction layer - avoid platform-specific code in game logic
  2. Test all platforms - button mappings may differ
  3. Support keyboard and gamepad simultaneously on PC
  4. Handle touch input on Vita
  5. Provide fallbacks for missing input devices

Build docs developers (and LLMs) love