MayaFlux 1.0.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'
});
std::weak_ptr< Core::Window > window
Definition Picker.cpp:23
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 102 of file InputEvents.cpp.

105{
106 auto& promise = co_await GetEventPromise {};
107 auto& source = window->get_event_source();
108
110 filter.event_type = Core::WindowEventType::KEY_PRESSED;
111
112 while (true) {
113 if (promise.should_terminate) {
114 break;
115 }
116
117 auto event = co_await WindowEventAwaiter(source, filter);
118
119 if (auto* key_data = std::get_if<Core::WindowEvent::KeyData>(&event.data)) {
120 callback(static_cast<IO::Keys>(key_data->key));
121 }
122 }
123}
PickCallback callback
Definition Picker.cpp:22
Event-domain promise accessor with optional NetworkSource ownership transfer.
std::optional< Core::WindowEventType > event_type
Filter criteria for window input events.

References callback, MayaFlux::Vruta::WindowEventFilter::event_type, MayaFlux::Core::KEY_PRESSED, and window.

Referenced by MayaFlux::on_any_key().

+ Here is the caller graph for this function: