5#include "flutter/shell/platform/fuchsia/flutter/keyboard.h"
7#include <fuchsia/input/cpp/fidl.h>
8#include <fuchsia/ui/input/cpp/fidl.h>
9#include <fuchsia/ui/input3/cpp/fidl.h>
16using fuchsia::ui::input::kModifierCapsLock;
17using fuchsia::ui::input::kModifierLeftAlt;
18using fuchsia::ui::input::kModifierLeftControl;
19using fuchsia::ui::input::kModifierLeftShift;
20using fuchsia::ui::input::kModifierNone;
21using fuchsia::ui::input::kModifierRightAlt;
22using fuchsia::ui::input::kModifierRightControl;
23using fuchsia::ui::input::kModifierRightShift;
24using fuchsia::ui::input3::KeyEvent;
33static const uint32_t QWERTY_TO_CODE_POINTS[][2] = {
164 : any_events_received_(
false),
165 stateful_caps_lock_(
false),
175 if (!
event.has_type()) {
178 if (!
event.has_key() && !
event.has_key_meaning()) {
182 last_event_ = std::move(
event);
183 any_events_received_ =
true;
185 if (!
event.has_key()) {
192 const Key&
key = last_event_.key();
196 case KeyEventType::SYNC:
199 stateful_caps_lock_ =
true;
207 case Key::LEFT_SHIFT:
213 case Key::RIGHT_CTRL:
216 case Key::RIGHT_SHIFT:
224 case KeyEventType::PRESSED:
227 stateful_caps_lock_ = !stateful_caps_lock_;
235 case Key::LEFT_SHIFT:
241 case Key::RIGHT_CTRL:
244 case Key::RIGHT_SHIFT:
252 case KeyEventType::RELEASED:
263 case Key::LEFT_SHIFT:
269 case Key::RIGHT_CTRL:
272 case Key::RIGHT_SHIFT:
273 right_shift_ =
false;
280 case KeyEventType::CANCEL:
290bool Keyboard::IsShift() {
291 return left_shift_ | right_shift_ | stateful_caps_lock_;
294bool Keyboard::IsKeys() {
299 return kModifierNone + (kModifierLeftShift * left_shift_) +
300 (kModifierLeftAlt * left_alt_) + (kModifierLeftControl * left_ctrl_) +
301 (kModifierRightShift * right_shift_) +
302 (kModifierRightAlt * right_alt_) +
303 (kModifierRightControl * right_ctrl_) +
304 (kModifierCapsLock * stateful_caps_lock_);
310 if (last_event_.has_key_meaning()) {
311 const auto& key_meaning = last_event_.key_meaning();
312 if (key_meaning.is_codepoint()) {
313 return key_meaning.codepoint();
316 static const int qwerty_map_size =
317 sizeof(QWERTY_TO_CODE_POINTS) /
sizeof(QWERTY_TO_CODE_POINTS[0]);
322 if (
usage < qwerty_map_size) {
323 return QWERTY_TO_CODE_POINTS[
usage][IsShift() & 1];
329uint32_t Keyboard::GetLastKey() {
335 if (!last_event_.has_key()) {
338 return static_cast<uint32_t
>(last_event_.key());
342 return GetLastKey() & 0xFFFFFFFF;
346 return GetLastKey() & 0xFFFF;
350 return (GetLastKey() >> 16) & 0xFFFF;
ax::mojom::Event event_type
uint16_t LastHIDUsagePage()
uint16_t LastHIDUsageID()
bool ConsumeEvent(fuchsia::ui::input3::KeyEvent event)
static void usage(char *argv0)