Portals0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
Loading...
Searching...
No Matches
input_match.hpp
1// Copyright (c) 2026 ttldtor.
2// SPDX-License-Identifier: BSL-1.0
3#pragma once
4
5#include <portals/input.hpp>
6
7#include <algorithm>
8#include <initializer_list>
9
10namespace portals {
18constexpr bool keyPressed(const InputEvent &event, InputKey key) noexcept {
19 const auto *value = std::get_if<KeyEvent>(&event);
20
21 return value && value->key == key && value->action != KeyAction::RELEASE;
22}
23
31constexpr bool keyPressed(const InputEvent &event, InputKey key, InputModifiers modifiers) noexcept {
32 const auto *value = std::get_if<KeyEvent>(&event);
33
34 return keyPressed(event, key) && value->modifiers == modifiers;
35}
36
44constexpr bool keyPressed(const InputEvent &event, std::initializer_list<InputKey> keys) noexcept {
45 const auto *value = std::get_if<KeyEvent>(&event);
46
47 return value && value->action != KeyAction::RELEASE && std::ranges::contains(keys, value->key);
48}
49} // namespace portals
Public Portals API.
Definition action.hpp:8
@ RELEASE
Key release reported by a native adapter.
Definition input.hpp:209
std::variant< KeyEvent, TextInputEvent, MouseInputEvent, PasteInputEvent, InputProbeCandidate, InputIssue > InputEvent
Independent owning result, usable beyond decoder reset/destruction.
Definition input.hpp:378
constexpr bool keyPressed(const InputEvent &event, InputKey key) noexcept
Match a semantic key press or repeat without extracting the event variant.
Definition input_match.hpp:18
InputKey
Semantic key identities; character uses KeyEvent::scalar.
Definition input.hpp:64
Observed modifiers, also usable by a native input adapter.
Definition input.hpp:34