electron/shell/common/keyboard_util.cc

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

288 lines
8.4 KiB
C++
Raw Normal View History

2015-09-18 05:33:06 +00:00
// Copyright (c) 2015 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include <string>
2016-03-06 06:04:05 +00:00
#include "base/containers/fixed_flat_map.h"
2016-03-06 06:04:05 +00:00
#include "base/strings/string_util.h"
#include "shell/common/keyboard_util.h"
chore: bump chromium to 279aeeec3c9fe2237bc31f776f269 (master) (#21521) * chore: bump chromium in DEPS to 46d2d82e84d73806da623c5333dae4dd218172df * chore: bump chromium in DEPS to cbafe74731a5d1e59844ca59e0fc28f4a5f80a33 * chore: bump chromium in DEPS to d5dcd6b5cc76f4e1732083d775cdd7b533f0abe9 * Update patches * update for lint * Fix compilation errors * chore: bump chromium in DEPS to 1c19360fdaaf65d4ed006736c7f9804104095990 * Replace removed constant * chore: bump chromium in DEPS to 3b6639f5da26c1772c5d4f3ba634aca65df75fec * chore: bump chromium in DEPS to cc6b1b930d4b5eca06701820dac54fa0f41e8999 * chore: bump chromium in DEPS to 7d1445641ad1032c67f731ba6ff7798f29349ade * chore: bump chromium in DEPS to 6f7e5e79cefe982ad84a88927565a88db2e592be * chore: bump chromium in DEPS to bfb25dafff19cb41bf9781331d19ef0be819d1e4 * chore: bump chromium in DEPS to 1a8196b39f0e0cdc4935fd122fff5625d5fab06e * chore: bump chromium in DEPS to 9a03d8d2bb38ad8c0cbb9550ca81b2f94ff60c15 * chore: bump chromium in DEPS to 4c67f3505dab2d5457adb418cd3270a4f3236fd0 * chore: bump chromium in DEPS to 652394e7626fc1ae895a53fb34c64070494e648e * chore: bump chromium in DEPS to 07653652c58cc019af7f833bd63eb0c2eceaab5e * chore: bump chromium in DEPS to 451a1c5fec1fb073a5bae12a033bb342c72c905f * chore: bump chromium in DEPS to 86cdba00e233899a232868b412b333d08db63478 * chore: bump chromium in DEPS to 7c322faad1aee8abef2330d74aabf09ecf8c11af * Update patches * chore: bump chromium in DEPS to d0044fae7efc29eb201cfdd5fdbed77d48aba212 * Replace IsProcessingUserGesture with HasTransientUserActivation https://chromium.googlesource.com/chromium/src/+/4baa9a6e85e6c1784fd20d196c1c3c85fdb40101 * Fix 10.15 sdk build https://chromium.googlesource.com/chromium/src/+/0eaa6db358ca97b1cd358934068ade9a249c83db * Remove CancelPrerender https://chromium.googlesource.com/chromium/src/+/5eb33297194c3d3d6a7f2d744b3811033463194e * Remove no longer used WebFloatPoint https://chromium.googlesource.com/chromium/src/+/43ab96ce6bfc78440e5b1617a9974386a54c750c * Use base::span<const uint8_t> for devtools messages in content/public https://chromium.googlesource.com/chromium/src/+/21e19401af0b12d13ddc14d4a167f1b02ec65a6b * Update renamed header files * TODO: update with upstream changes This code needs to be updated to handle the changes made in: https://chromium.googlesource.com/chromium/src/+/19be6547a9a898104cd172de77184e243643ee19 * chore: bump chromium in DEPS to 82e5a2c6bd33c2e53634a09fbcbc9fcac1e7ff93 * chore: bump chromium in DEPS to 91f877cadd2995201c276e952b3bf2c60b226c64 * chore: bump chromium in DEPS to 43fcd2ab2677a06d38246b42761dc5b40cf87177 * chore: bump chromium in DEPS to e30957dcb710c0977a7ff95b8d3cf65843df12ca * chore: bump chromium in DEPS to 6a8335a56db12aae2fd06296f82579d804d92217 * chore: bump chromium in DEPS to a4a436cbc28ace88d71752f8f479e59559e54e46 * chore: bump chromium in DEPS to 982bbd0e4b2e1d57d515f384f6483ffc0d7073ad * chore: bump chromium in DEPS to 92bb7a99f84ffcdf41d4edca57e90b1f0c7c6c8b * update patches * add checkout_google_benchmark gclient var * FIXME: workaround grit bug * chore: bump chromium in DEPS to d3623fc53615739e6b59340a5d349e4b397cb7c5 * update patches * Remove color arg from DidChangeThemeColor(). https://chromium-review.googlesource.com/c/chromium/src/+/1982623 * update CreateFileURLLoader with new suffix CL: https://chromium-review.googlesource.com/c/chromium/src/+/1981414 * add node patch for removal of task API in v8 CL: https://chromium-review.googlesource.com/c/v8/v8/+/1868620 * add disable_secure_dns param for WillCreateURLLoaderFactory CL: https://chromium-review.googlesource.com/c/chromium/src/+/1888099 * switch to mojo-ified PrintMsg_PrintPreview CL: https://chromium-review.googlesource.com/c/chromium/src/+/1972307 * chore: bump chromium in DEPS to e7a6d173632660b6aeb9806e9132c34a315331c2 * update missing chrome/browser/ssl:proto dependency after chrome removal CL: https://chromium-review.googlesource.com/c/chromium/src/+/1986082 * chore: add libvulkan.so to the linux manifest CL: https://chromium-review.googlesource.com/c/chromium/src/+/1973042 * revert DidChangeThemeColor ternary change due to templates * match Chrome's mojo-ified implementation in geolocation_permission_context.cc CL: https://chromium-review.googlesource.com/c/chromium/src/+/1963371 * add vulkan-1.dll to zips https://github.com/KhronosGroup/Vulkan-Loader/commit/2d6f74c6d4319e94cf1fa33954c619ab4428f2b8 * add bug link to fixme_grit_conflicts.patch * Introduce device.mojom.DeviceService https://chromium-review.googlesource.com/c/chromium/src/+/1956277 * PDF Compositor rename to Print Compositor https://chromium-review.googlesource.com/c/chromium/src/+/1981135 * chore: bump chromium_version 00362ea584735b4acf4c5a0e1912d7987f8645ab * chore: update patches * Use a virtual base class to provide GetWidget(). https://chromium-review.googlesource.com/c/chromium/src/+/1996948 * [base] Remove usage of base::CurrentThread https://chromium-review.googlesource.com/c/chromium/src/+/1962019 * chore: gn format * Revert "ci: Use Visual Studio Build Tools instead of VS Studio (#21771)" This reverts commit 9c1310dadc09f88daf8866b38af9ebb385a2e9d3. * fix: trigger resize when iframe requests fullscreen * fix: Locking scheme registry is not necessary https://chromium-review.googlesource.com/c/chromium/src/+/1973198 * chore: bump chromium f707f1d6d428f84cf14b64bc2ca74372e25c6ce7 * chore: update patches * ui/base/clipboard: Remove redundant ANSI format functions https://chromium-review.googlesource.com/c/chromium/src/+/1992015 * [base] Prepare //chrome for Value::GetList() switch https://chromium-review.googlesource.com/c/chromium/src/+/1962255 Co-authored-by: John Kleinschmidt <jkleinsc@github.com> Co-authored-by: loc <andy@slack-corp.com> Co-authored-by: Jeremy Apthorp <nornagon@nornagon.net> Co-authored-by: Robo <hop2deep@gmail.com>
2020-01-17 18:41:52 +00:00
#include "third_party/blink/public/common/input/web_input_event.h"
2016-10-07 19:46:33 +00:00
#include "ui/events/event_constants.h"
2015-09-18 05:33:06 +00:00
namespace electron {
2016-03-06 06:04:05 +00:00
namespace {
using CodeAndShiftedChar = std::pair<ui::KeyboardCode, std::optional<char16_t>>;
constexpr CodeAndShiftedChar KeyboardCodeFromKeyIdentifier(
const std::string_view str) {
chore: bump chromium to 100.0.4857.0 (main) (#32419) * chore: bump chromium in DEPS to 99.0.4819.0 * chore: update patches * chore: bump chromium in DEPS to 99.0.4824.0 * chore: update patches * chore: bump chromium in DEPS to 99.0.4827.0 * chore: update patches * 3352511: PiP: Add inkdrop and pointer cursor to PiP window buttons https://chromium-review.googlesource.com/c/chromium/src/+/3352511 * 3309164: webhid: Show FIDO devices in the chooser if allowed https://chromium-review.googlesource.com/c/chromium/src/+/3309164 * 3297868: hid: Add experimental HIDDevice.forget() https://chromium-review.googlesource.com/c/chromium/src/+/3297868 * 3362491: [Extensions] Move i18n API to //extensions https://chromium-review.googlesource.com/c/chromium/src/+/3362491 * MCC Refactor step0: Allow embedders to register associated_interface binders with RenderFrameHostImpl::associated_registry_. https://chromium-review.googlesource.com/c/chromium/src/+/3281481 * 3352616: [Gtk] Remove libgtk from the link-line https://chromium-review.googlesource.com/c/chromium/src/+/3352616 * 3249211: Clear-Site-Data support for partitioned cookies https://chromium-review.googlesource.com/c/chromium/src/+/3249211 * [Extensions][COIL] Use [allow|block]list in //extensions/common https://chromium-review.googlesource.com/c/chromium/src/+/3372668 * Begin ScopedUserPrefUpdate migration to modern base::Value https://chromium-review.googlesource.com/c/chromium/src/+/3376154 * [Code Health] Refactor PrefService GetDict + GetList to use base::Value https://chromium-review.googlesource.com/c/chromium/src/+/3343526 * 3354997: [CodeHealth] Remove deprecated SetDictionary method https://chromium-review.googlesource.com/c/chromium/src/+/3354997 * 3287323: Add LacrosPrefStore for lacros settings https://chromium-review.googlesource.com/c/chromium/src/+/3287323 * 3365916: [PA] Clean up remaining lazy commit code https://chromium-review.googlesource.com/c/chromium/src/+/3365916 * [MPArch] Target the external protocol error at the responsible frame. https://chromium-review.googlesource.com/c/chromium/src/+/3011560 * Pass origin to RegisterNonNetworkSubresourceURLLoaderFactories https://chromium-review.googlesource.com/c/chromium/src/+/3350608 * Linux: Send OSCrypt raw encryption key to the Network Service https://chromium-review.googlesource.com/c/chromium/src/+/3320484 * [PlzServiceWorker] Remove remaining references to PlzServiceWorker. https://chromium-review.googlesource.com/c/chromium/src/+/3359441 * chore: fixup for lint * 3327621: Fix tablet mode detection for Win 11. https://chromium-review.googlesource.com/c/chromium/src/+/3327621 * 3342428: ax_mac: move AXTextMarker conversion utils under ui umbrella https://chromium-review.googlesource.com/c/chromium/src/+/3342428 * 3353974: Mac: Use base::Feature for overlay features https://chromium-review.googlesource.com/c/chromium/src/+/3353974 * chore: bump chromium in DEPS to 99.0.4828.0 * chore: update patches * chore: bump chromium in DEPS to 99.0.4837.0 * chore: update patches * chore: update patches * 3379142: Drop FALLTHROUGH macro Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3379142 * 3381749: C++17: Allow use of std::map::try_emplace and std::map::insert_or_assign Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3381749 * chore: bump chromium in DEPS to 99.0.4839.0 * chore: update patches * chore: bump chromium in DEPS to 99.0.4840.0 * chore: bump chromium in DEPS to 99.0.4844.0 * 3395881: [api] Deprecate Local<v8::Context> v8::Object::CreationContext() Ref: https://chromium-review.googlesource.com/c/v8/v8/+/3395881 * chore: update patches * chore: bump chromium in DEPS to 100.0.4845.0 * chore: update patches * chore: bump chromium in DEPS to 100.0.4847.0 * chore: update patches * chore: bump chromium in DEPS to 100.0.4849.0 * chore: update patches * chore: bump chromium in DEPS to 100.0.4851.0 * chore: bump chromium in DEPS to 100.0.4853.0 * update patches * chore: update patches * update patches * 3383599: Fonts Access: Remove prototype that uses a font picker. https://chromium-review.googlesource.com/c/chromium/src/+/3383599 * 3404768: Remove ALLOW_UNUSED macros https://chromium-review.googlesource.com/c/chromium/src/+/3404768 * 3374762: Remove ignore_result.h https://chromium-review.googlesource.com/c/chromium/src/+/3374762 * 3399305: [unseasoned-pdf] Apply proper frame offsets for touch selections https://chromium-review.googlesource.com/c/chromium/src/+/3399305 * 3402210: [Extensions] Don't trigger unload event for already unloaded extension https://chromium-review.googlesource.com/c/chromium/src/+/3402210 * 3410912: Combine URLLoaderClient OnReceiveResponse and OnStartLoadingResponseBody. https://chromium-review.googlesource.com/c/chromium/src/+/3410912 * 3370428: Make the AuthSchemes policy support dynamic refresh https://chromium-review.googlesource.com/c/chromium/src/+/3370428 * 3407603: Finish ScopedUserPrefUpdate migration to modern base::Value https://chromium-review.googlesource.com/c/chromium/src/+/3407603 * 3378352: ozone/x11: move code from //ui/p/x11 to //ui/ozone/p/x11 https://chromium-review.googlesource.com/c/chromium/src/+/3378352 * 3370810: Delete chrome/service, AKA the Cloud Print service process. https://chromium-review.googlesource.com/c/chromium/src/+/3370810 * chore: bump chromium in DEPS to 100.0.4855.0 * chore: update patches * fixup! 3370810: Delete chrome/service, AKA the Cloud Print service process. * revert 3348007 to fix windows build * 3318572: [Code health] Fix gn check errors in //extensions/browser:* https://chromium-review.googlesource.com/c/chromium/src/+/3318572 * fix printing.patch * fix iwyu issue * 3408515: win: Make ShorcutOperation an enum class and modernize names https://chromium-review.googlesource.com/c/chromium/src/+/3408515 * 3388333: [UIA] Remove dead code accessibility_misc_utils.h/cc https://chromium-review.googlesource.com/c/chromium/src/+/3388333 * fix windows build? i hope * patch gn visibility of //ui/ozone/platform/x11 * missing include base/logging.h * use BUILDFLAG for USE_NSS_CERTS https://chromium-review.googlesource.com/c/chromium/src/+/3379123 * defined(OS_*) ==> BUILDFLAG(IS_*) https://bugs.chromium.org/p/chromium/issues/detail?id=1234043 * fixup! 3404768: Remove ALLOW_UNUSED macros * another attempt to fix windows build * temporarily disable the custom scheme service worker test https://github.com/electron/electron/issues/32664 * fix loading mv3 extensions not sure what cl broke this unfort. * fixup! 3404768: Remove ALLOW_UNUSED macros * patch nan https://chromium-review.googlesource.com/c/v8/v8/+/3395880 * fix node test * fix nullptr in FindPdfFrame * patch perfetto to fix build issue on win-ia32 https://source.chromium.org/chromium/_/android/platform/external/perfetto.git/+/bc44c3c7533c00e56f88c06c592d634aecc884be * fix build for linux-x64-testing-no-run-as-node * fix patch * skip <webview>.capturePage() test https://github.com/electron/electron/issues/32705 * test: fix failing tests of focus/blur events of WebContents (#32711) * inherit stdio from app module test child processes this prevents them from timing out due to full stdout buffers * test to see if we can get better logs on windows ci * try again for appveyor log things * skip contentTracing tests on ia32 * ci: disable gpu compositing * drop applied patch * fix merge fail * Revert "ci: disable gpu compositing" This reverts commit 0344129fcb19ea3e87e06c1110d751f22eba3fec. Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: John Kleinschmidt <jkleinsc@github.com> Co-authored-by: VerteDinde <khammond@slack-corp.com> Co-authored-by: VerteDinde <vertedinde@electronjs.org> Co-authored-by: Jeremy Rose <jeremya@chromium.org> Co-authored-by: Jeremy Rose <nornagon@nornagon.net> Co-authored-by: Cheng Zhao <zcbenz@gmail.com> Co-authored-by: deepak1556 <hop2deep@gmail.com>
2022-02-10 02:58:52 +00:00
#if BUILDFLAG(IS_MAC)
constexpr auto CommandOrControl = ui::VKEY_COMMAND;
#else
constexpr auto CommandOrControl = ui::VKEY_CONTROL;
#endif
constexpr auto Lookup =
base::MakeFixedFlatMap<std::string_view, CodeAndShiftedChar>({
{"alt", {ui::VKEY_MENU, {}}},
{"altgr", {ui::VKEY_ALTGR, {}}},
{"backspace", {ui::VKEY_BACK, {}}},
{"capslock", {ui::VKEY_CAPITAL, {}}},
{"cmd", {ui::VKEY_COMMAND, {}}},
{"cmdorctrl", {CommandOrControl, {}}},
{"command", {ui::VKEY_COMMAND, {}}},
{"commandorcontrol", {CommandOrControl, {}}},
{"control", {ui::VKEY_CONTROL, {}}},
{"ctrl", {ui::VKEY_CONTROL, {}}},
{"delete", {ui::VKEY_DELETE, {}}},
{"down", {ui::VKEY_DOWN, {}}},
{"end", {ui::VKEY_END, {}}},
{"enter", {ui::VKEY_RETURN, {}}},
{"esc", {ui::VKEY_ESCAPE, {}}},
{"escape", {ui::VKEY_ESCAPE, {}}},
{"f1", {ui::VKEY_F1, {}}},
{"f10", {ui::VKEY_F10, {}}},
{"f11", {ui::VKEY_F11, {}}},
{"f12", {ui::VKEY_F12, {}}},
{"f13", {ui::VKEY_F13, {}}},
{"f14", {ui::VKEY_F14, {}}},
{"f15", {ui::VKEY_F15, {}}},
{"f16", {ui::VKEY_F16, {}}},
{"f17", {ui::VKEY_F17, {}}},
{"f18", {ui::VKEY_F18, {}}},
{"f19", {ui::VKEY_F19, {}}},
{"f2", {ui::VKEY_F2, {}}},
{"f20", {ui::VKEY_F20, {}}},
{"f21", {ui::VKEY_F21, {}}},
{"f22", {ui::VKEY_F22, {}}},
{"f23", {ui::VKEY_F23, {}}},
{"f24", {ui::VKEY_F24, {}}},
{"f3", {ui::VKEY_F3, {}}},
{"f4", {ui::VKEY_F4, {}}},
{"f5", {ui::VKEY_F5, {}}},
{"f6", {ui::VKEY_F6, {}}},
{"f7", {ui::VKEY_F7, {}}},
{"f8", {ui::VKEY_F8, {}}},
{"f9", {ui::VKEY_F9, {}}},
{"home", {ui::VKEY_HOME, {}}},
{"insert", {ui::VKEY_INSERT, {}}},
{"left", {ui::VKEY_LEFT, {}}},
{"medianexttrack", {ui::VKEY_MEDIA_NEXT_TRACK, {}}},
{"mediaplaypause", {ui::VKEY_MEDIA_PLAY_PAUSE, {}}},
{"mediaprevioustrack", {ui::VKEY_MEDIA_PREV_TRACK, {}}},
{"mediastop", {ui::VKEY_MEDIA_STOP, {}}},
{"meta", {ui::VKEY_COMMAND, {}}},
{"num0", {ui::VKEY_NUMPAD0, {}}},
{"num1", {ui::VKEY_NUMPAD1, {}}},
{"num2", {ui::VKEY_NUMPAD2, {}}},
{"num3", {ui::VKEY_NUMPAD3, {}}},
{"num4", {ui::VKEY_NUMPAD4, {}}},
{"num5", {ui::VKEY_NUMPAD5, {}}},
{"num6", {ui::VKEY_NUMPAD6, {}}},
{"num7", {ui::VKEY_NUMPAD7, {}}},
{"num8", {ui::VKEY_NUMPAD8, {}}},
{"num9", {ui::VKEY_NUMPAD9, {}}},
{"numadd", {ui::VKEY_ADD, {}}},
{"numdec", {ui::VKEY_DECIMAL, {}}},
{"numdiv", {ui::VKEY_DIVIDE, {}}},
{"numlock", {ui::VKEY_NUMLOCK, {}}},
{"nummult", {ui::VKEY_MULTIPLY, {}}},
{"numsub", {ui::VKEY_SUBTRACT, {}}},
{"option", {ui::VKEY_MENU, {}}},
{"pagedown", {ui::VKEY_NEXT, {}}},
{"pageup", {ui::VKEY_PRIOR, {}}},
{"plus", {ui::VKEY_OEM_PLUS, '+'}},
{"printscreen", {ui::VKEY_SNAPSHOT, {}}},
{"return", {ui::VKEY_RETURN, {}}},
{"right", {ui::VKEY_RIGHT, {}}},
{"scrolllock", {ui::VKEY_SCROLL, {}}},
{"shift", {ui::VKEY_SHIFT, {}}},
{"space", {ui::VKEY_SPACE, {}}},
{"super", {ui::VKEY_COMMAND, {}}},
{"tab", {ui::VKEY_TAB, {}}},
{"up", {ui::VKEY_UP, {}}},
{"volumedown", {ui::VKEY_VOLUME_DOWN, {}}},
{"volumemute", {ui::VKEY_VOLUME_MUTE, {}}},
{"volumeup", {ui::VKEY_VOLUME_UP, {}}},
});
if (auto* const iter = Lookup.find(str); iter != Lookup.end())
return iter->second;
return {ui::VKEY_UNKNOWN, {}};
}
constexpr CodeAndShiftedChar KeyboardCodeFromCharCode(char16_t c) {
2015-09-18 05:33:06 +00:00
switch (c) {
2018-04-18 01:55:30 +00:00
case ' ':
return {ui::VKEY_SPACE, {}};
case '!':
return {ui::VKEY_1, '!'};
case '"':
return {ui::VKEY_OEM_7, '"'};
case '#':
return {ui::VKEY_3, '#'};
case '$':
return {ui::VKEY_4, '$'};
case '%':
return {ui::VKEY_5, '%'};
case '&':
return {ui::VKEY_7, '&'};
case '(':
return {ui::VKEY_9, '('};
case ')':
return {ui::VKEY_0, ')'};
case '*':
return {ui::VKEY_8, '*'};
case '+':
return {ui::VKEY_OEM_PLUS, '+'};
case ',':
return {ui::VKEY_OEM_COMMA, {}};
case '-':
return {ui::VKEY_OEM_MINUS, {}};
case '.':
return {ui::VKEY_OEM_PERIOD, {}};
case '/':
return {ui::VKEY_OEM_2, {}};
case '0':
return {ui::VKEY_0, {}};
case '1':
return {ui::VKEY_1, {}};
case '2':
return {ui::VKEY_2, {}};
case '3':
return {ui::VKEY_3, {}};
case '4':
return {ui::VKEY_4, {}};
case '5':
return {ui::VKEY_5, {}};
case '6':
return {ui::VKEY_6, {}};
case '7':
return {ui::VKEY_7, {}};
case '8':
return {ui::VKEY_8, {}};
case '9':
return {ui::VKEY_9, {}};
case ':':
return {ui::VKEY_OEM_1, ':'};
case ';':
return {ui::VKEY_OEM_1, {}};
case '<':
return {ui::VKEY_OEM_COMMA, '<'};
case '=':
return {ui::VKEY_OEM_PLUS, {}};
case '>':
return {ui::VKEY_OEM_PERIOD, '>'};
case '?':
return {ui::VKEY_OEM_2, '?'};
case '@':
return {ui::VKEY_2, '@'};
case '[':
return {ui::VKEY_OEM_4, {}};
case '\'':
return {ui::VKEY_OEM_7, {}};
case '\\':
return {ui::VKEY_OEM_5, {}};
case ']':
return {ui::VKEY_OEM_6, {}};
case '^':
return {ui::VKEY_6, '^'};
case '_':
return {ui::VKEY_OEM_MINUS, '_'};
case '`':
return {ui::VKEY_OEM_3, {}};
2018-04-18 01:55:30 +00:00
case 'a':
return {ui::VKEY_A, {}};
2018-04-18 01:55:30 +00:00
case 'b':
return {ui::VKEY_B, {}};
2018-04-18 01:55:30 +00:00
case 'c':
return {ui::VKEY_C, {}};
2018-04-18 01:55:30 +00:00
case 'd':
return {ui::VKEY_D, {}};
2018-04-18 01:55:30 +00:00
case 'e':
return {ui::VKEY_E, {}};
2018-04-18 01:55:30 +00:00
case 'f':
return {ui::VKEY_F, {}};
2018-04-18 01:55:30 +00:00
case 'g':
return {ui::VKEY_G, {}};
2018-04-18 01:55:30 +00:00
case 'h':
return {ui::VKEY_H, {}};
2018-04-18 01:55:30 +00:00
case 'i':
return {ui::VKEY_I, {}};
2018-04-18 01:55:30 +00:00
case 'j':
return {ui::VKEY_J, {}};
2018-04-18 01:55:30 +00:00
case 'k':
return {ui::VKEY_K, {}};
2018-04-18 01:55:30 +00:00
case 'l':
return {ui::VKEY_L, {}};
2018-04-18 01:55:30 +00:00
case 'm':
return {ui::VKEY_M, {}};
2018-04-18 01:55:30 +00:00
case 'n':
return {ui::VKEY_N, {}};
2018-04-18 01:55:30 +00:00
case 'o':
return {ui::VKEY_O, {}};
2018-04-18 01:55:30 +00:00
case 'p':
return {ui::VKEY_P, {}};
2018-04-18 01:55:30 +00:00
case 'q':
return {ui::VKEY_Q, {}};
2018-04-18 01:55:30 +00:00
case 'r':
return {ui::VKEY_R, {}};
2018-04-18 01:55:30 +00:00
case 's':
return {ui::VKEY_S, {}};
2018-04-18 01:55:30 +00:00
case 't':
return {ui::VKEY_T, {}};
2018-04-18 01:55:30 +00:00
case 'u':
return {ui::VKEY_U, {}};
2018-04-18 01:55:30 +00:00
case 'v':
return {ui::VKEY_V, {}};
2018-04-18 01:55:30 +00:00
case 'w':
return {ui::VKEY_W, {}};
2018-04-18 01:55:30 +00:00
case 'x':
return {ui::VKEY_X, {}};
2018-04-18 01:55:30 +00:00
case 'y':
return {ui::VKEY_Y, {}};
2018-04-18 01:55:30 +00:00
case 'z':
return {ui::VKEY_Z, {}};
2018-04-18 01:55:30 +00:00
case '{':
return {ui::VKEY_OEM_4, '{'};
2018-04-18 01:55:30 +00:00
case '|':
return {ui::VKEY_OEM_5, '|'};
2018-04-18 01:55:30 +00:00
case '}':
return {ui::VKEY_OEM_6, '}'};
case '~':
return {ui::VKEY_OEM_3, '~'};
case 0x08:
return {ui::VKEY_BACK, {}};
case 0x09:
return {ui::VKEY_TAB, {}};
case 0x0D:
return {ui::VKEY_RETURN, {}};
case 0x1B:
return {ui::VKEY_ESCAPE, {}};
case 0x7F:
return {ui::VKEY_DELETE, {}};
2018-04-18 01:55:30 +00:00
default:
return {ui::VKEY_UNKNOWN, {}};
2015-09-18 05:33:06 +00:00
}
}
} // namespace
ui::KeyboardCode KeyboardCodeFromStr(const std::string_view str,
std::optional<char16_t>* shifted_char) {
auto const [code, shifted] =
str.size() == 1 ? KeyboardCodeFromCharCode(base::ToLowerASCII(str[0]))
: KeyboardCodeFromKeyIdentifier(base::ToLowerASCII(str));
if (code == ui::VKEY_UNKNOWN)
LOG(WARNING) << "Invalid accelerator token: " << str;
*shifted_char = shifted;
return code;
}
2015-09-18 05:33:06 +00:00
} // namespace electron