Checks if keyboard key currently pressed (held down).
Takes vKeyCode (virtual key code constant, integer, e.g., VK_W, VK_SPACE).
Returns 1 if key pressed, 0 if released.
Input
Parameters & Returns
Parameters
vKeyCodeInt
Returns
Int
Quick Summary
Checks if keyboard key currently pressed (held down).
Takes vKeyCode (virtual key code constant, integer, e.g., VK_W, VK_SPACE).
Returns 1 if key pressed, 0 if released.
Technical Exegesis...
Checks if keyboard key currently pressed (held down). Takes vKeyCode (virtual key code constant, integer, e.g., VK_W, VK_SPACE). Returns 1 if key pressed, 0 if released. Queries current key state, returns true every frame while key held.
Key state: 1=key pressed this frame (held down), 0=key not pressed (released or never pressed), continuous detection (returns 1 every frame while held), different from inpIsKeyHit (which returns 1 only on first press frame).
Checks if keyboard key currently pressed (held down). Takes vKeyCode (virtual key code constant, integer, e.g., VK_W, VK_SPACE). Returns 1 if key pressed, 0 if released. Queries current key state, returns true every frame while key held.
Key state: 1=key pressed this frame (held down), 0=key not pressed (released or never pressed), continuous detection (returns 1 every frame while held), different from inpIsKeyHit (which returns 1 only on first press frame).
Virtual key codes: use predefined VK_ constants (VK_A through VK_Z for letters, VK_0 through VK_9 for numbers, VK_SPACE, VK_SHIFT, VK_CTRL, VK_ENTER, VK_ESCAPE, arrow keys VK_LEFT/RIGHT/UP/DOWN, etc.), codes map to Windows virtual key constants (standard across Windows applications), consult input constants documentation for available key codes.
Use cases: (1) Continuous movement (hold W to move forward, WASD controls), (2) Hold-to-sprint mechanics (hold Shift while moving to sprint), (3) Charging attacks (hold key to charge, release to fire), (4) Multi-key combinations (If inpIsKeyDown(VK_CTRL) AND inpIsKeyDown(VK_S) Then save), (5) Analog keyboard behavior (accumulate hold duration for variable effects).
Common patterns: movement = If inpIsKeyDown(VK_W) Then moveForward(); sprint = If inpIsKeyDown(VK_SHIFT) AND inpIsKeyDown(VK_W) Then sprint forward; charge = If inpIsKeyDown(VK_SPACE) Then chargeTime#=chargeTime#+deltaTime#; combo = If inpIsKeyDown(VK_CTRL) AND inpIsKeyHit(VK_C) Then copy.
KeyDown vs KeyHit: inpIsKeyDown returns 1 every frame while held (continuous detection, use for movement/running/charging), inpIsKeyHit returns 1 only on first press frame (single-shot detection, use for jumps/actions/menu navigation), use KeyDown for sustained actions (auto-fire, continuous movement), use KeyHit for discrete actions (jump once, toggle setting, menu select).
WASD controls: typical FPS/game controls (W=forward, S=backward, A=left, D=right), pattern: If inpIsKeyDown(VK_W) Then z#=z#-speed#: If inpIsKeyDown(VK_S) Then z#=z#+speed#: If inpIsKeyDown(VK_A) Then x#=x#-speed#: If inpIsKeyDown(VK_D) Then x#=x#+speed#.
Modifier keys: check Shift/Ctrl/Alt with inpIsKeyDown(VK_SHIFT/CTRL/ALT) for combinations, pattern: If inpIsKeyDown(VK_SHIFT) Then sprintSpeed Else walkSpeed, allows context-sensitive controls (Shift+Click for different action than Click alone).
Performance: very fast query (~0.0001ms, simple state lookup), safe for per-frame calls (negligible overhead), no polling required (system tracks key states automatically).
Key codes: case-insensitive for letters (VK_A checks 'A' key regardless of Shift/CapsLock state), separate codes for left/right modifiers (VK_LSHIFT vs VK_RSHIFT if needed), function keys (VK_F1 through VK_F12), numpad keys separate from number row.
Return values: 1 if key pressed (held down this frame), 0 if key released (not pressed), 0 on error (invalid key code, though typically just returns 0).