5#include "flutter/shell/platform/windows/keyboard_key_channel_handler.h"
9#include "flutter/fml/logging.h"
10#include "flutter/shell/platform/common/json_message_codec.h"
11#include "flutter/shell/platform/windows/keyboard_utils.h"
17static constexpr char kChannelName[] =
"flutter/keyevent";
21static constexpr char kCharacterCodePointKey[] =
"characterCodePoint";
24static constexpr char kTypeKey[] =
"type";
25static constexpr char kHandledKey[] =
"handled";
27static constexpr char kWindowsKeyMap[] =
"windows";
28static constexpr char kKeyUp[] =
"keyup";
29static constexpr char kKeyDown[] =
"keydown";
33static constexpr int kMaxPendingEvents = 1000;
42static constexpr int kScancodeExtended = 0xe000;
48static constexpr int kShift = 1 << 0;
49static constexpr int kShiftLeft = 1 << 1;
50static constexpr int kShiftRight = 1 << 2;
51static constexpr int kControl = 1 << 3;
52static constexpr int kControlLeft = 1 << 4;
53static constexpr int kControlRight = 1 << 5;
54static constexpr int kAlt = 1 << 6;
55static constexpr int kAltLeft = 1 << 7;
56static constexpr int kAltRight = 1 << 8;
57static constexpr int kWinLeft = 1 << 9;
58static constexpr int kWinRight = 1 << 10;
59static constexpr int kCapsLock = 1 << 11;
60static constexpr int kNumLock = 1 << 12;
61static constexpr int kScrollLock = 1 << 13;
66int GetModsForKeyState() {
69 if (GetKeyState(VK_SHIFT) < 0)
71 if (GetKeyState(VK_LSHIFT) < 0)
73 if (GetKeyState(VK_RSHIFT) < 0)
75 if (GetKeyState(VK_CONTROL) < 0)
77 if (GetKeyState(VK_LCONTROL) < 0)
79 if (GetKeyState(VK_RCONTROL) < 0)
80 mods |= kControlRight;
81 if (GetKeyState(VK_MENU) < 0)
83 if (GetKeyState(VK_LMENU) < 0)
85 if (GetKeyState(VK_RMENU) < 0)
87 if (GetKeyState(VK_LWIN) < 0)
89 if (GetKeyState(VK_RWIN) < 0)
91 if (GetKeyState(VK_CAPITAL) < 0)
93 if (GetKeyState(VK_NUMLOCK) < 0)
95 if (GetKeyState(VK_SCROLL) < 0)
120 std::map<uint64_t, uint64_t> empty_state;
134 rapidjson::Document
event(rapidjson::kObjectType);
135 auto& allocator =
event.GetAllocator();
140 event.AddMember(
kKeyMapKey, kWindowsKeyMap, allocator);
141 event.AddMember(
kModifiersKey, GetModsForKeyState(), allocator);
161 bool handled = decoded ? (*decoded)[kHandledKey].GetBool() :
false;
static const JsonMessageCodec & GetInstance()
~KeyboardKeyChannelHandler()
void KeyboardHook(int key, int scancode, int action, char32_t character, bool extended, bool was_down, std::function< void(bool)> callback)
void SyncModifiersIfNeeded(int modifiers_state)
KeyboardKeyChannelHandler(flutter::BinaryMessenger *messenger)
std::map< uint64_t, uint64_t > GetPressedState()
std::unique_ptr< T > DecodeMessage(const uint8_t *binary_message, const size_t message_size) const
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
#define FML_LOG(severity)
Dart_NativeFunction function
static constexpr char kScanCodeKey[]
static constexpr char kKeyMapKey[]
static constexpr char kKeyDown[]
static constexpr char kKeyUp[]
static constexpr char kModifiersKey[]
static constexpr char kKeyCodeKey[]
constexpr char kTypeKey[]
uint32_t UndeadChar(uint32_t ch)