|
| | KeyCapture (Key cancel_key=Key::Escape) noexcept |
| | Creates a capture that waits for nothing yet.
|
| |
| void | start (ActionId action, const Keyboard &keyboard) noexcept |
| | Waits for a key for an action, replacing a capture in progress.
|
| |
| void | cancel () noexcept |
| | Stops waiting, without changing any binding.
|
| |
| std::optional< ActionId > | waiting () const noexcept |
| | Action waiting for a key.
|
| |
| std::optional< CapturedKey > | update (ActionMap &actions, const Keyboard &keyboard) |
| | Binds the first key pressed during the frame, if any.
|
| |
Key binding step of a settings menu: "press a key for Fire".
The menu calls start() when the player picks an action, then update() once per frame after Window::poll_events(). The next key pressed becomes the only key of the action (ActionMap::rebind()); the cancel key (Escape by default) gives up and leaves the action unchanged, so it cannot be bound this way. Keys pressed in the frame start() was called in are ignored: the key that chose the action is not taken as its new key.
if (fire_chosen_in_menu) {
capture.start(fire, window.keyboard());
}
if (capture.update(actions, window.keyboard())) {
actions.save(settings, "input");
settings.save(file);
}