title: Get receive keyboard an mouse events from SDL2 in WPF application
body: <p>I'm trying to capture mouse and keyboard events from SDL2 using the <a href="https://github.com/flibitijibibo/SDL2-CS/" rel="nofollow">SDL2-CS</a> binding library. The events are polled for but these events are never raised.</p>
  
  <p>I think this is because the polling needs to happen on the UI thread. I tried initializing SDL from the UI thread by calling <code>App.Current.Dispatcher.Invoke(Init)</code> but no events are polled. </p>
  
  <p>Basic implementation of my class:</p>
  
  <pre><code>public override void Initialize()
  {
      if (hooked)
      {
          return;
      }
  
      App.Current.Dispatcher.Invoke(Init); //Run on the UI thread        
  }
  
  private void Init()
  {
      var init = SDL.SDL_Init(SDL.SDL_INIT_VIDEO);
      if (init != 0)
      {
          throw new Exception("Could not initialize SDL");
      }
      hooked = true;
      ListenForEvents();
  
  }
  
  private void ListenForEvents()
  {
      SDL.SDL_Event ev;
      while (true)
      {
          if (SDL.SDL_PollEvent(out ev) != 1) //This is continuously trigged
          {
              continue;
          }
  
          switch (ev.type) //This is never reached
          {
              case SDL.SDL_EventType.SDL_MOUSEMOTION:
                  if (MouseMoved != null) { MouseMoved(this, ev.motion); }
                  break;
  
              ...
          }
      }
  }
  </code></pre>
  
  <p>I'm wondring if I'm invoking the <code>Init</code> on the UI thread wrong, or if the SDL initialization is wrong.</p>
  
  <p>P.S. Hooking with user32.dll is not desired because this code will run on non windows environments as well.</p>