Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/adi3120/Fazen2d/llms.txt

Use this file to discover all available pages before exploring further.

KeyboardHandler wraps GetAsyncKeyState to let you poll keyboard state each frame without blocking. Rather than waiting on input events, it samples key state asynchronously on every call, making it well-suited for real-time game loops. Access it via game.keyboardHandler.
#include "include/headers/KeyboardHandler.h"  // included automatically via Fazen.h

Methods

SignatureReturnsDescription
IsKeyPressed(int keyCode)booltrue while the key is currently held down
IsKeyReleased(int keyCode)booltrue when the key is not held down
CheckForUserExit()booltrue when the Escape key is pressed

bool IsKeyPressed(int keyCode)

Returns true while the specified key is currently held down. Internally calls GetAsyncKeyState(keyCode) & 0x8000 to test the high-order bit, which is set when the key is pressed at the moment of the call.

bool IsKeyReleased(int keyCode)

Returns true when the specified key is not held down. This is the logical inverse of IsKeyPressed — it returns true when GetAsyncKeyState(keyCode) & 0x8000 is zero.

bool CheckForUserExit()

Returns true when the Escape key (VK_ESCAPE) is pressed. This is a convenience wrapper equivalent to calling IsKeyPressed(VK_ESCAPE), intended for use as the condition of your main game loop.

Key Code Reference

Virtual Key ConstantHex ValueCommon Use
VK_ESCAPE0x1BExit / quit
VK_LEFT0x25Left arrow
VK_RIGHT0x27Right arrow
VK_UP0x26Up arrow
VK_DOWN0x28Down arrow
VK_SPACE0x20Space bar
'A''Z'0x410x5ALetter keys (uppercase ASCII)
VK_RETURN0x0DEnter
All standard Windows Virtual Key codes defined in <windows.h> are valid. For a complete reference see the Microsoft Virtual-Key Codes documentation.

Example — Movement Using Arrow Keys

Box player(40.0f, 20.0f, 3.0f, 3.0f, greenF);

while (!game.keyboardHandler.CheckForUserExit()) {
    game.graphics.background(whiteB);

    if (game.keyboardHandler.IsKeyPressed(VK_LEFT))  player.translate(-0.5f, 0.0f);
    if (game.keyboardHandler.IsKeyPressed(VK_RIGHT)) player.translate( 0.5f, 0.0f);
    if (game.keyboardHandler.IsKeyPressed(VK_UP))    player.translate( 0.0f,-0.5f);
    if (game.keyboardHandler.IsKeyPressed(VK_DOWN))  player.translate( 0.0f, 0.5f);

    game.graphics.draw(player);
    game.graphics.display();
}
GetAsyncKeyState reports asynchronous key state — it works even when the console does not have focus. This is useful during testing but may cause unexpected input if you switch windows while your game loop is running.

Build docs developers (and LLMs) love