Added the option to KeyboardEvent to specify the sent character by it's name (if it can't be sent via the keyCode parameter)

This commit is contained in:
Heilig Benedek 2015-11-16 04:15:13 +01:00
parent 9987082de5
commit bb6d7d1498
3 changed files with 42 additions and 5 deletions

View file

@ -2,12 +2,13 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include <string>
#include "atom/common/keyboad_util.h"
namespace atom {
// Return key code of the char.
ui::KeyboardCode KeyboardCodeFromCharCode(char c, bool* shifted) {
ui::KeyboardCode KeyboardCodeFromCharCode(base::char16 c, bool* shifted) {
*shifted = false;
switch (c) {
case 0x08: return ui::VKEY_BACK;
@ -71,4 +72,28 @@ ui::KeyboardCode KeyboardCodeFromCharCode(char c, bool* shifted) {
}
}
// Return key code of the char.
ui::KeyboardCode KeyboardCodeFromKeyIdentifier(std::string chr) {
if (chr == "enter") return ui::VKEY_RETURN;
if (chr == "backspace") return ui::VKEY_BACK;
if (chr == "delete") return ui::VKEY_DELETE;
if (chr == "tab") return ui::VKEY_TAB;
if (chr == "escape") return ui::VKEY_ESCAPE;
if (chr == "control") return ui::VKEY_CONTROL;
if (chr == "alt") return ui::VKEY_MENU;
if (chr == "shift") return ui::VKEY_SHIFT;
if (chr == "end") return ui::VKEY_END;
if (chr == "home") return ui::VKEY_HOME;
if (chr == "insert") return ui::VKEY_INSERT;
if (chr == "left") return ui::VKEY_LEFT;
if (chr == "up") return ui::VKEY_UP;
if (chr == "right") return ui::VKEY_RIGHT;
if (chr == "down") return ui::VKEY_DOWN;
if (chr == "pageup") return ui::VKEY_PRIOR;
if (chr == "pagedown") return ui::VKEY_NEXT;
if (chr == "printscreen") return ui::VKEY_SNAPSHOT;
return ui::VKEY_UNKNOWN;
}
} // namespace atom