hal/drivers/hid/keyboard_win.cc
/**
 * @brief Handle raw input.
 * @param raw_input Raw input.
 * @param keyboard_input Raw input as keyboard input if it is keyboard input.
 * @return true if raw input is keyboard input, false otherwise.
 */
@brief Handle raw input.
@param raw_input Raw input.
@param keyboard_input Raw input as keyboard input if it is keyboard input.
@return true if raw input is keyboard input, false otherwise.
@brief Handle raw input . @param raw_input Raw input . @param keyboard_input Raw input as keyboard input if it is keyboard input . @return true if raw input is keyboard input false otherwise .
[[nodiscard]] bool Keyboard::Handle(const RAWINPUT& raw_input,
                                    KeyboardInput& keyboard_input) noexcept {
  if (raw_input.header.dwType == RIM_TYPEKEYBOARD) {
    const auto& keyboard = raw_input.data.keyboard;
    keyboard_input.make_code = keyboard.MakeCode;
    static_assert(std::is_same_v<
                  decltype(keyboard.Flags),
                  std::underlying_type_t<decltype(keyboard_input.key_flags)>>);
    keyboard_input.key_flags = static_cast<KeyboardKeyFlags>(keyboard.Flags);
    if (keyboard.Flags == RI_KEY_MAKE ||
        !(keyboard.Flags & RI_KEY_BREAK) &&
            ((keyboard.Flags & RI_KEY_E0) || (keyboard.Flags & RI_KEY_E1))) {
      G3CHECK(
          !(keyboard.Flags & base::underlying_cast(KeyboardKeyFlags::kDown)))
          << "Windows raw input keyboard data contains flags used for app "
             "itself.  It means app can't detect key down in some cases.  "
             "Please, contact support.";
      keyboard_input.key_flags =
          keyboard_input.key_flags | KeyboardKeyFlags::kDown;
    }
    keyboard_input.virtual_key = keyboard.VKey;
    keyboard_input.message = keyboard.Message;
    return true;
  }
  return false;
}
[[ nodiscard ]] bool Keyboard :: Handle ( const RAWINPUT & raw_input , KeyboardInput & keyboard_input ) noexcept { if ( raw_input . header . dwType == RIM_TYPEKEYBOARD ) { const auto & keyboard = raw_input . data . keyboard ; keyboard_input . make_code = keyboard . MakeCode ; static_assert ( std :: is_same_v < decltype ( keyboard . Flags ) , std :: underlying_type_t < decltype ( keyboard_input . key_flags ) > > ) ; keyboard_input . key_flags = static_cast < KeyboardKeyFlags > ( keyboard . Flags ) ; if ( keyboard . Flags == RI_KEY_MAKE || ! ( keyboard . Flags & RI_KEY_BREAK ) && ( ( keyboard . Flags & RI_KEY_E0 ) || ( keyboard . Flags & RI_KEY_E1 ) ) ) { G3CHECK ( ! ( keyboard . Flags & base :: underlying_cast ( KeyboardKeyFlags :: kDown ) ) ) << " " " " " " ; keyboard_input . key_flags = keyboard_input . key_flags | KeyboardKeyFlags :: kDown ; } keyboard_input . virtual_key = keyboard . VKey ; keyboard_input . message = keyboard . Message ; return true ; } return false ; }
@brief Handle raw input.
@brief Handle raw input .
// Remap key down event to allow check it via & operator. // If key down or not key up + E0 / E1 than it means key down. // Fix this one if Windows will use our custom flag.  App will be // terminated, fix required (or we will assume key down when it is not).