Exemplo n.º 1
0
 private unsafe void OnUiControlGotFocus()
 {
     lock (KeyboardInputEvents)
     {
         int nb;
         // Get the state for all keys on the keyboard.
         byte *p = (byte *)SDL.SDL_GetKeyboardState(out nb);
         for (int i = 0; i < nb; i++)
         {
             // Check if key of scancode `i' is pressed.
             if (p[i] != 0)
             {
                 SDL.SDL_Keycode keyCode = SDL.SDL_GetKeyFromScancode((SDL.SDL_Scancode)i);
                 Keys            key;
                 if (MapKeys.TryGetValue(keyCode, out key) && key != Keys.None)
                 {
                     KeyboardInputEvents.Add(new KeyboardInputEvent
                     {
                         Key        = key,
                         Type       = InputEventType.Down,
                         OutOfFocus = true
                     });
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
 private void OnKeyEvent(SDL.SDL_KeyboardEvent e, bool isKeyUp)
 {
     lock (KeyboardInputEvents)
     {
         Keys key;
         if (MapKeys.TryGetValue(e.keysym.sym, out key) && key != Keys.None)
         {
             var type = isKeyUp ? InputEventType.Up : InputEventType.Down;
             KeyboardInputEvents.Add(new KeyboardInputEvent {
                 Key = key, Type = type
             });
         }
     }
 }