What I ended up doing is to override OnKeyDown
and OnKeyUp
methods on the main windows of the Avalonia app, and then I am mapping Avalonia.Input.Key
enum to SDL.SDL_Keycode
enum. After that I am creating a new SDL2 event with a given key down/up like so:
public void OnKeyUp(SDL.SDL_Keycode key)
{
SDL.SDL_Event _event = new SDL.SDL_Event();
_event.key.keysym.sym = key;
_event.type = SDL.SDL_EventType.SDL_KEYUP;
SDL.SDL_PushEvent(ref _event);
}
public void OnKeyDown(SDL.SDL_Keycode key)
{
SDL.SDL_Event _event = new SDL.SDL_Event();
_event.type = SDL.SDL_EventType.SDL_KEYDOWN;
_event.key.keysym.sym = key;
SDL.SDL_PushEvent(ref _event);
}
Thanks to that I am able to get all key up/down events from the Avalonia into the SDL2 app.