MayaFlux 0.2.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ any_key()

MAYAFLUX_API Vruta::Event MayaFlux::Kriya::any_key ( std::shared_ptr< Core::Window window,
std::function< void(IO::Keys)>  callback 
)

Creates an Event coroutine that triggers on any key press.

Parameters
windowWindow to listen to
callbackFunction to call with key code when any key is pressed
Returns
Event coroutine that can be added to EventManager

Example:

auto task = any_key(window,
[](IO::Keys key) {
// Handle any key press, key code in 'key'
});
Vruta::Event any_key(std::shared_ptr< Core::Window > window, std::function< void(IO::Keys)> callback)
Creates an Event coroutine that triggers on any key press.

Definition at line 54 of file InputEvents.cpp.

57{
58 auto& promise = co_await GetEventPromise {};
59 auto& source = window->get_event_source();
60
61 Vruta::EventFilter filter;
62 filter.event_type = Core::WindowEventType::KEY_PRESSED;
63
64 while (true) {
65 if (promise.should_terminate) {
66 break;
67 }
68
69 auto event = co_await EventAwaiter(source, filter);
70
71 if (auto* key_data = std::get_if<Core::WindowEvent::KeyData>(&event.data)) {
72 callback(static_cast<IO::Keys>(key_data->key));
73 }
74 }
75}
Templated awaitable for accessing a coroutine's promise object.
std::optional< Core::WindowEventType > event_type
Filter criteria for window events.

References MayaFlux::Vruta::EventFilter::event_type, and MayaFlux::Core::KEY_PRESSED.

Referenced by MayaFlux::on_any_key().

+ Here is the caller graph for this function: