emoji_panel_helper_win.cc 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ui/base/emoji/emoji_panel_helper.h"
  5. #include <windows.h>
  6. #include "base/win/windows_version.h"
  7. #include "ui/events/keycodes/keyboard_code_conversion_win.h"
  8. namespace ui {
  9. bool IsEmojiPanelSupported() {
  10. // Emoji picker is supported on Windows 10's Spring 2018 Update and
  11. // above.
  12. return base::win::GetVersion() >= base::win::Version::WIN10_RS4;
  13. }
  14. void ShowEmojiPanel() {
  15. // This sends Windows Key + '.' (both keydown and keyup events).
  16. // "SendInput" is used because Windows needs to receive these events and
  17. // open the Emoji picker.
  18. // TODO(crbug.com/827404): Move to a specialized Windows API once it is
  19. // available.
  20. INPUT input[4] = {};
  21. input[0].type = INPUT_KEYBOARD;
  22. input[0].ki.wVk = ui::WindowsKeyCodeForKeyboardCode(ui::VKEY_COMMAND);
  23. input[1].type = INPUT_KEYBOARD;
  24. input[1].ki.wVk = ui::WindowsKeyCodeForKeyboardCode(ui::VKEY_OEM_PERIOD);
  25. input[2].type = INPUT_KEYBOARD;
  26. input[2].ki.wVk = ui::WindowsKeyCodeForKeyboardCode(ui::VKEY_COMMAND);
  27. input[2].ki.dwFlags |= KEYEVENTF_KEYUP;
  28. input[3].type = INPUT_KEYBOARD;
  29. input[3].ki.wVk = ui::WindowsKeyCodeForKeyboardCode(ui::VKEY_OEM_PERIOD);
  30. input[3].ki.dwFlags |= KEYEVENTF_KEYUP;
  31. ::SendInput(4, input, sizeof(INPUT));
  32. }
  33. } // namespace ui