dao::input
Key bindings of a plugin’s own, and pointing the game’s cursor pick at a pixel.
Declared in dao/Input.h.
Classes
| Class | |
|---|---|
| Action | An action for RegisterAction: its name, its label, its default key, and the game modes where the key works. |
| MouseMove | How far the mouse moved: the device’s own counts, x to the right and y down, unbounded by the window or the screen. |
Type aliases
Key
using Key = core::Key
a keyboard key, identified by its DirectInput scan code
Enumerations
ActionState
enum class ActionState
Whether the game has accepted an action given to RegisterAction.
| Value | |
|---|---|
Unknown |
no action of that name was given to RegisterAction |
Waiting |
the game has not registered its own actions yet |
Registered |
the game has added the action |
NameTaken |
the game already had an action of that name, so this one was not added |
MouseButton
enum class MouseButton : std::uint8_t
A mouse button as the device numbers it, whatever the game’s left-handed setting.
| Value | |
|---|---|
Left |
|
Right |
|
Middle |
|
Fourth |
|
Fifth |
Move
enum class Move : std::uint8_t
One of the four ways the game’s movement keys steer the controlled creature.
| Value | |
|---|---|
Forward |
|
Backward |
|
Left |
|
Right |
Reaction
enum Reaction : std::uint32_t
What of the game’s own reaction to the keys and mouse a plugin may withhold, or’d together.
| Value | |
|---|---|
kMovement = 1 |
moving the controlled creature: the movement keys, steering, run forward |
kCameraTurn = 2 |
turning and tilting the camera: the right mouse’s orbit, the camera keys |
kCameraZoom = 4 |
zooming: the wheel, Page Up and Page Down |
kCameraPan = 8 |
panning: the middle mouse’s drag and the camera’s pan keys |
Functions
Down()
bool Down(Key key)
Returns whether a key is down now, as the game’s input reads the keyboard, whatever the game does with it: withheld (Withhold), unbound or in a menu, and whatever else is held with it.
Returns false before the game reads its input, or with its window in the background
Down()
bool Down(MouseButton button)
Returns whether a mouse button is down now, as Down(Key) answers for a key.
Held()
bool Held(std::wstring_view name)
Returns whether a key the player bound to the named action is down now, in a game mode the action names: for an action held rather than pressed, such as moving a camera.
The modifiers the binding names must be down with the key; others may be down too. A binding to a mouse button does not count. Call it from a frame callback.
Returns false for an unknown name, an action the game has not accepted, or one bound to no key of the keyboard
Hold()
void Hold(Move direction, bool held)
Holds one of the game’s movement keys down, or lets it go, with no key pressed.
While a direction is held the game steers the controlled creature as it does by the keyboard: by the way the camera faces, running or walking as the player has it set, with the game’s own drive command, and only where the game takes movement keys at all (not in a conversation or a menu). It stops when nothing is held. A real key pressed at the same time counts as well. This works even when the game’s window is not in front. A direction stays held until it is let go, so let go of what was held. Call it from any thread.
| Parameter | |
|---|---|
direction |
the key |
held |
true to hold it down, false to let it go |
HoldCursor()
void HoldCursor(bool held)
Hides the cursor and holds it where it is, as the game’s right-drag orbit does, or shows it there again.
While it holds, the game’s own giving back (its orbit’s, its fly camera’s) waits for this, and MouseDelta still reads the mouse. Call it on the game thread.
| Parameter | |
|---|---|
held |
true to hide and hold it, false to give it back |
MouseDelta()
MouseMove MouseDelta()
Returns how far the mouse moved during the last frame, whatever the game does with it.
The frame is the one dao::OnFrame runs: read it from a frame callback.
PointCursor()
void PointCursor(std::int32_t x, std::int32_t y)
Makes the game treat a pixel as the one under the mouse, without moving the mouse.
In explore mode the game then picks the object or ground at that pixel, and anything that depends on what is under the cursor, such as a path preview, follows it. This works even when the game’s window is not in front. The Flash interface still follows the real mouse. The pixel stays in effect until ReleaseCursor. Call it from any thread.
| Parameter | |
|---|---|
x |
the pixel’s column, in the screen pixels that dao::world::ToScreen returns |
y |
the pixel’s row |
Presses()
std::uint64_t Presses(std::wstring_view name)
Returns how many times the action’s key has been pressed in a game mode where it works; 0 for an unknown name.
RegisterAction()
bool RegisterAction(Action action, std::function<void()> pressed)
Registers an action and the callback its key runs.
Call it from DAOLib_Load, because the game registers its actions only once, at start-up. Call StateOf later to find out whether the game accepted the action.
| Parameter | |
|---|---|
pressed |
runs once per key press, on the game thread (dao/Frame.h), so it may call script commands |
Returns false, with nothing registered, if the name is not valid or this plugin has already registered it, if pressed is empty, or if the game has already registered its own actions
ReleaseCursor()
void ReleaseCursor()
Hands the world pick back to the real mouse after PointCursor.
SetKeymap()
void SetKeymap(std::wstring_view keymap, bool on)
Turns one of the plugin’s key maps on or off, as a mode of its own: a free camera’s keys on W, A, S and D while it flies, the game’s walking on them otherwise.
While a map is on, its actions answer to their keys, in the game modes each names, and every other action with one of those keys does not answer to it, the game’s own among them; an action’s other key still works. Maps are off until turned on. Call it on the game thread.
| Parameter | |
|---|---|
keymap |
the name actions give as Action::keymap |
StateOf()
ActionState StateOf(std::wstring_view name)
Returns whether the game has accepted the named action.
WheelNotches()
std::int32_t WheelNotches()
Returns the wheel’s notches during the last frame, away from the player positive, whatever the game does with them.
Read it from a frame callback.
Withhold()
void Withhold(std::uint32_t reactions)
Withholds the game’s own reaction to the keys and mouse, until given back.
What is withheld is the game’s reading of its own inputs; a plugin’s actions (RegisterAction) still fire, and Down, MouseDelta and WheelNotches still answer. Clicks in the world are not withheld. A movement a plugin holds (Hold) is withheld with the keys’. Call it from any thread.
| Parameter | |
|---|---|
reactions |
those to withhold, or’d; 0 gives all back |
Variables
kAlt
constexpr std::uint32_t kAlt = core::kAlt
Alt, for Action::modifiers.
kControl
constexpr std::uint32_t kControl = core::kControl
Ctrl, for Action::modifiers.
kShift
constexpr std::uint32_t kShift = core::kShift
Shift, for Action::modifiers.