9 #include "flutter/fml/logging.h"
17 static constexpr
char kChannelName[] =
"flutter/keyevent";
19 static constexpr
char kKeyCodeKey[] =
"keyCode";
20 static constexpr
char kScanCodeKey[] =
"scanCode";
21 static constexpr
char kCharacterCodePointKey[] =
"characterCodePoint";
22 static constexpr
char kModifiersKey[] =
"modifiers";
23 static constexpr
char kKeyMapKey[] =
"keymap";
24 static constexpr
char kTypeKey[] =
"type";
25 static constexpr
char kHandledKey[] =
"handled";
27 static constexpr
char kWindowsKeyMap[] =
"windows";
28 static constexpr
char kKeyUp[] =
"keyup";
29 static constexpr
char kKeyDown[] =
"keydown";
33 static constexpr
int kMaxPendingEvents = 1000;
42 static constexpr
int kScancodeExtended = 0xe000;
48 static constexpr
int kShift = 1 << 0;
49 static constexpr
int kShiftLeft = 1 << 1;
50 static constexpr
int kShiftRight = 1 << 2;
51 static constexpr
int kControl = 1 << 3;
52 static constexpr
int kControlLeft = 1 << 4;
53 static constexpr
int kControlRight = 1 << 5;
54 static constexpr
int kAlt = 1 << 6;
55 static constexpr
int kAltLeft = 1 << 7;
56 static constexpr
int kAltRight = 1 << 8;
57 static constexpr
int kWinLeft = 1 << 9;
58 static constexpr
int kWinRight = 1 << 10;
59 static constexpr
int kCapsLock = 1 << 11;
60 static constexpr
int kNumLock = 1 << 12;
61 static constexpr
int kScrollLock = 1 << 13;
66 int 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;
131 std::function<
void(
bool)>
callback) {
134 rapidjson::Document event(rapidjson::kObjectType);
135 auto& allocator =
event.GetAllocator();
136 event.AddMember(kKeyCodeKey,
key, allocator);
137 event.AddMember(kScanCodeKey,
scancode | (
extended ? kScancodeExtended : 0),
140 event.AddMember(kKeyMapKey, kWindowsKeyMap, allocator);
141 event.AddMember(kModifiersKey, GetModsForKeyState(), allocator);
146 event.AddMember(kTypeKey, kKeyDown, allocator);
150 event.AddMember(kTypeKey, kKeyUp, allocator);
153 FML_LOG(WARNING) <<
"Unknown key event action: " <<
action;
157 channel_->Send(event, [
callback = std::move(
callback)](
const uint8_t* reply,
161 bool handled = decoded ? (*decoded)[kHandledKey].GetBool() :
false;