24static constexpr char kKeyUp[] =
"keyup";
37struct UTF8CodePointInfo {
46UTF8CodePointInfo GetUTF8CodePointInfo(
int first_byte) {
47 UTF8CodePointInfo byte_info;
52 byte_info.first_byte_mask = 0x07;
55 byte_info.first_byte_mask = 0x0F;
58 byte_info.first_byte_mask = 0x1F;
61 byte_info.first_byte_mask = 0xFF;
71bool GetUTF32CodePointFromGLFWKey(
int key,
73 uint32_t* code_point) {
78 const char* utf8 = glfwGetKeyName(
key, scan_code);
79 if (utf8 ==
nullptr) {
83 const auto byte_info = GetUTF8CodePointInfo(utf8[0]);
85 int shift = byte_info.length - 1;
87 const int complement_mask = 0x3F;
90 size_t current_byte_index = 0;
91 while (current_byte_index < byte_info.length) {
92 const int current_byte = utf8[current_byte_index];
94 current_byte_index == 0 ? byte_info.first_byte_mask : complement_mask;
96 const int bits_to_shift = 6 * shift--;
97 result += (current_byte & mask) << bits_to_shift;
123 rapidjson::Document event(rapidjson::kObjectType);
124 auto& allocator =
event.GetAllocator();
132 bool result = GetUTF32CodePointFromGLFWKey(
key,
scancode, &unicodeInt);
146 std::cerr <<
"Unknown key event action: " <<
action << std::endl;
149 channel_->Send(event);
virtual ~KeyEventHandler()
KeyEventHandler(flutter::BinaryMessenger *messenger)
void CharHook(GLFWwindow *window, unsigned int code_point) override
void KeyboardHook(GLFWwindow *window, int key, int scancode, int action, int mods) override
static constexpr char kScanCodeKey[]
static constexpr int kFourByteMask
static constexpr char kKeyMapKey[]
static constexpr char kToolkitKey[]
static constexpr char kTypeKey[]
static constexpr char kGLFWKey[]
static constexpr char kKeyDown[]
static constexpr char kLinuxKeyMap[]
static constexpr char kChannelName[]
static constexpr char kKeyUp[]
static constexpr char kModifiersKey[]
static constexpr int kTwoByteMask
static constexpr int kThreeByteMask
static constexpr char kUnicodeScalarValues[]
static constexpr char kKeyCodeKey[]
constexpr char kTypeKey[]