Merge pull request #3454 from brenca/keyboard-pr
Adding further options to specify the character being sent with sendInputEvent (keyboard)
This commit is contained in:
commit
202d2eeb8a
4 changed files with 48 additions and 8 deletions
|
@ -2,12 +2,13 @@
|
||||||
// Use of this source code is governed by the MIT license that can be
|
// Use of this source code is governed by the MIT license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
#include <string>
|
||||||
#include "atom/common/keyboad_util.h"
|
#include "atom/common/keyboad_util.h"
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
// Return key code of the char.
|
// Return key code of the char.
|
||||||
ui::KeyboardCode KeyboardCodeFromCharCode(char c, bool* shifted) {
|
ui::KeyboardCode KeyboardCodeFromCharCode(base::char16 c, bool* shifted) {
|
||||||
*shifted = false;
|
*shifted = false;
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 0x08: return ui::VKEY_BACK;
|
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(const 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
|
} // namespace atom
|
||||||
|
|
|
@ -5,13 +5,18 @@
|
||||||
#ifndef ATOM_COMMON_KEYBOAD_UTIL_H_
|
#ifndef ATOM_COMMON_KEYBOAD_UTIL_H_
|
||||||
#define ATOM_COMMON_KEYBOAD_UTIL_H_
|
#define ATOM_COMMON_KEYBOAD_UTIL_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
#include "ui/events/keycodes/keyboard_codes.h"
|
#include "ui/events/keycodes/keyboard_codes.h"
|
||||||
|
#include "base/strings/string_util.h"
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
// Return key code of the char, and also determine whether the SHIFT key is
|
// Return key code of the char, and also determine whether the SHIFT key is
|
||||||
// pressed.
|
// pressed.
|
||||||
ui::KeyboardCode KeyboardCodeFromCharCode(char c, bool* shifted);
|
ui::KeyboardCode KeyboardCodeFromCharCode(base::char16 c, bool* shifted);
|
||||||
|
|
||||||
|
// Return key code of the char from a string representation of the char
|
||||||
|
ui::KeyboardCode KeyboardCodeFromKeyIdentifier(const std::string& chr);
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
||||||
|
|
|
@ -159,10 +159,17 @@ bool Converter<blink::WebKeyboardEvent>::FromV8(
|
||||||
if (!ConvertFromV8(isolate, val, static_cast<blink::WebInputEvent*>(out)))
|
if (!ConvertFromV8(isolate, val, static_cast<blink::WebInputEvent*>(out)))
|
||||||
return false;
|
return false;
|
||||||
base::char16 code;
|
base::char16 code;
|
||||||
if (!dict.Get("keyCode", &code))
|
std::string identifier;
|
||||||
return false;
|
|
||||||
bool shifted = false;
|
bool shifted = false;
|
||||||
out->windowsKeyCode = atom::KeyboardCodeFromCharCode(code, &shifted);
|
|
||||||
|
if (dict.Get("keyCode", &code))
|
||||||
|
out->windowsKeyCode = atom::KeyboardCodeFromCharCode(code, &shifted);
|
||||||
|
else if (dict.Get("keyCode", &identifier))
|
||||||
|
out->windowsKeyCode = atom::KeyboardCodeFromKeyIdentifier(
|
||||||
|
base::StringToLowerASCII(identifier));
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
|
||||||
if (shifted)
|
if (shifted)
|
||||||
out->modifiers |= blink::WebInputEvent::ShiftKey;
|
out->modifiers |= blink::WebInputEvent::ShiftKey;
|
||||||
out->setKeyIdentifierFromWindowsKeyCode();
|
out->setKeyIdentifierFromWindowsKeyCode();
|
||||||
|
|
|
@ -590,7 +590,7 @@ Disable device emulation enabled by `webContents.enableDeviceEmulation`.
|
||||||
* `event` Object
|
* `event` Object
|
||||||
* `type` String (**required**) - The type of the event, can be `mouseDown`,
|
* `type` String (**required**) - The type of the event, can be `mouseDown`,
|
||||||
`mouseUp`, `mouseEnter`, `mouseLeave`, `contextMenu`, `mouseWheel`,
|
`mouseUp`, `mouseEnter`, `mouseLeave`, `contextMenu`, `mouseWheel`,
|
||||||
`keyDown`, `keyUp`, `char`.
|
`mouseMove`, `keyDown`, `keyUp`, `char`.
|
||||||
* `modifiers` Array - An array of modifiers of the event, can
|
* `modifiers` Array - An array of modifiers of the event, can
|
||||||
include `shift`, `control`, `alt`, `meta`, `isKeypad`, `isAutoRepeat`,
|
include `shift`, `control`, `alt`, `meta`, `isKeypad`, `isAutoRepeat`,
|
||||||
`leftButtonDown`, `middleButtonDown`, `rightButtonDown`, `capsLock`,
|
`leftButtonDown`, `middleButtonDown`, `rightButtonDown`, `capsLock`,
|
||||||
|
@ -600,8 +600,11 @@ Sends an input `event` to the page.
|
||||||
|
|
||||||
For keyboard events, the `event` object also have following properties:
|
For keyboard events, the `event` object also have following properties:
|
||||||
|
|
||||||
* `keyCode` String (**required**) - A single character that will be sent as
|
* `keyCode` Char or String (**required**) - The character that will be sent
|
||||||
keyboard event. Can be any UTF-8 character.
|
as the keyboard event. Can be a single UTF-8 character, or the name of the
|
||||||
|
key that generates the event. Accepted key names are `enter`, `backspace`,
|
||||||
|
`delete`, `tab`, `escape`, `control`, `alt`, `shift`, `end`, `home`, `insert`,
|
||||||
|
`left`, `up`, `right`, `down`, `pageUp`, `pageDown`, `printScreen`
|
||||||
|
|
||||||
For mouse events, the `event` object also have following properties:
|
For mouse events, the `event` object also have following properties:
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue