Input¶
The keyboard, mouse and controller, read only while the game window has focus. While the player is typing in a
plugin's text box, every key reads as up except Input::Escape, so Escape can still close a menu (for the game's own
text boxes, check Editor::Typing()). Keys are Input::Key values: named keys such as Input::F5, Input::PageUp,
Input::Backspace, Input::MouseBack, Input::Win and Input::RightWin (the Windows keys), Input::A to
Input::Z, Input::N0 to Input::N9 for the number row, Input::Numpad0 to Input::Numpad9, and controller
buttons: Input::PadA, PadB, PadX, PadY, PadLB, PadRB,
PadLT, PadRT, PadL3, PadR3, PadView, PadMenu, the D-pad (PadUp, PadDown, PadLeft, PadRight) and
the left stick pushed a direction (PadStickUp, ...). Controllers are read with XInput (Xbox pads, and most others
through Steam Input). The Down arrow is Input::Key::Down, since Input::Down is also the function below.
Pressed¶
bool Input::Pressed(Key)
True in the frame the key goes down.
Example
// F6 toggles the window
if (Input::Pressed(Input::F6))
window.visible = !window.visible;
Down¶
bool Input::Down(Key)
True for as long as the key is held.
Example
// Only snap once the drag has finished
if (!Input::Down(Input::MouseLeft))
SnapSelection();
MousePosition¶
bool Input::MousePosition(float &out, float &out)
Where the mouse is on the game's screen, from the top left, in the units windows are placed in (Window.SetOffset,
Window.SetRect). Returns false when it isn't over the game. Requires host 0.13.0.
Example
float x, y;
if (Input::MousePosition(x, y))
Log::Info("mouse at " + x + ", " + y);
Wheel¶
float Input::Wheel()
How far the mouse wheel turned this frame (0 when it didn't turn), as the game's own controls read it. Requires host 0.14.0.
Example
speed *= Math::pow(1.2, Input::Wheel());
AnyPressed¶
Key Input::AnyPressed()
A key that went down this frame, or Input::None: for letting the player choose a key.
Example
Input::Key k = Input::AnyPressed();
if (k != Input::None)
Log::Info("pressed " + Input::Name(k));
Name¶
string Input::Name(Key)
A key's name, as its Input::Key value is written without Input:: ("F5", "PageUp", "PadA").
Example
hint.text = "save: " + Input::Name(saveKey);
Input::Key¶
Input::None, plus Input::A to Input::Z and Input::N0 to Input::N9.