[UWP] Add modifier keys support (flutter/engine#28724)
Implement GetModsForKeyState in keyboard_key_channel_handler.cc
This commit is contained in:
@@ -6,6 +6,11 @@
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#ifdef WINUWP
|
||||
#include "third_party/cppwinrt/generated/winrt/Windows.System.h"
|
||||
#include "third_party/cppwinrt/generated/winrt/Windows.UI.Core.h"
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "flutter/shell/platform/common/json_message_codec.h"
|
||||
@@ -64,10 +69,48 @@ static constexpr int kScrollLock = 1 << 13;
|
||||
/// with the re-defined values declared above for compatibility with the Flutter
|
||||
/// framework.
|
||||
int GetModsForKeyState() {
|
||||
// TODO(clarkezone) need to add support for get modifier state for UWP
|
||||
// https://github.com/flutter/flutter/issues/70202
|
||||
#ifdef WINUWP
|
||||
return 0;
|
||||
using namespace winrt::Windows::System;
|
||||
using namespace winrt::Windows::UI::Core;
|
||||
|
||||
auto window = CoreWindow::GetForCurrentThread();
|
||||
|
||||
auto key_is_down = [&window](VirtualKey key) {
|
||||
auto state = window.GetKeyState(key);
|
||||
return (state & CoreVirtualKeyStates::Down) == CoreVirtualKeyStates::Down;
|
||||
};
|
||||
|
||||
int mods = 0;
|
||||
|
||||
if (key_is_down(VirtualKey::Shift))
|
||||
mods |= kShift;
|
||||
if (key_is_down(VirtualKey::LeftShift))
|
||||
mods |= kShiftLeft;
|
||||
if (key_is_down(VirtualKey::RightShift))
|
||||
mods |= kShiftRight;
|
||||
if (key_is_down(VirtualKey::Control))
|
||||
mods |= kControl;
|
||||
if (key_is_down(VirtualKey::LeftControl))
|
||||
mods |= kControlLeft;
|
||||
if (key_is_down(VirtualKey::RightControl))
|
||||
mods |= kControlRight;
|
||||
if (key_is_down(VirtualKey::Menu))
|
||||
mods |= kAlt;
|
||||
if (key_is_down(VirtualKey::LeftMenu))
|
||||
mods |= kAltLeft;
|
||||
if (key_is_down(VirtualKey::RightMenu))
|
||||
mods |= kAltRight;
|
||||
if (key_is_down(VirtualKey::LeftWindows))
|
||||
mods |= kWinLeft;
|
||||
if (key_is_down(VirtualKey::RightWindows))
|
||||
mods |= kWinRight;
|
||||
if (key_is_down(VirtualKey::CapitalLock))
|
||||
mods |= kCapsLock;
|
||||
if (key_is_down(VirtualKey::NumberKeyLock))
|
||||
mods |= kNumLock;
|
||||
if (key_is_down(VirtualKey::Scroll))
|
||||
mods |= kScrollLock;
|
||||
return mods;
|
||||
#else
|
||||
int mods = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user