79231803

Date: 2024-11-27 20:40:15
Score: 1
Natty:
Report link

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.

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Starts with a question (0.5): What I
  • Low reputation (0.5):
Posted by: gryz