diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index 7ee19783b0f2..3c523f8ccdb4 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -526,12 +526,14 @@ void Window::SendKeyboardEvent(v8::Isolate* isolate, const mate::Dictionary& dat auto type = blink::WebInputEvent::Type::Char; int modifiers = 0; int keycode = 0; + int native = 0; std::string type_str = ""; std::vector modifier_array; - data.Get(switches::kMouseEventType, &type_str); + data.Get(switches::kEventType, &type_str); data.Get(switches::kModifiers, &modifier_array); data.Get(switches::kKeyCode, &keycode); + data.Get(switches::kNativeKeyCode, &native); if(type_str.compare(event_types::kKeyDown) == 0){ type = blink::WebInputEvent::Type::KeyDown; @@ -565,7 +567,7 @@ void Window::SendKeyboardEvent(v8::Isolate* isolate, const mate::Dictionary& dat } } - window_->SendKeyboardEvent(type, modifiers, keycode); + window_->SendKeyboardEvent(type, modifiers, keycode, native); } void Window::SendMouseEvent(v8::Isolate* isolate, const mate::Dictionary& data){ @@ -578,7 +580,7 @@ void Window::SendMouseEvent(v8::Isolate* isolate, const mate::Dictionary& data){ blink::WebMouseEvent::Button button = blink::WebMouseEvent::Button::ButtonNone; int modifiers = 0; - data.Get(switches::kMouseEventType, &type_str); + data.Get(switches::kEventType, &type_str); data.Get(switches::kMouseEventButton, &button_str); data.Get(switches::kModifiers, &modifier_array); diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index f28a3a8bd41f..a9e0631489a8 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -47,6 +47,7 @@ #include "ui/gfx/geometry/size.h" #include "ui/gfx/screen.h" #include "ui/gl/gpu_switching_manager.h" +#include "ui/events/event.h" #if defined(OS_WIN) #include "ui/gfx/switches.h" @@ -572,10 +573,10 @@ void NativeWindow::DevToolsClosed() { FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnDevToolsClosed()); } -void NativeWindow::SendKeyboardEvent(blink::WebInputEvent::Type type, int modifiers, int keycode){ +void NativeWindow::SendKeyboardEvent(blink::WebInputEvent::Type type, int modifiers, int keycode, int nativeKeycode){ auto keyb_event = new content::NativeWebKeyboardEvent; - keyb_event->nativeKeyCode = keycode; + keyb_event->nativeKeyCode = nativeKeycode; keyb_event->windowsKeyCode = keycode; keyb_event->setKeyIdentifierFromWindowsKeyCode(); keyb_event->type = type; @@ -584,7 +585,7 @@ void NativeWindow::SendKeyboardEvent(blink::WebInputEvent::Type type, int modifi keyb_event->timeStampSeconds = base::Time::Now().ToDoubleT(); keyb_event->skip_in_browser = false; - if (type == blink::WebInputEvent::Char || type == blink::WebInputEvent::KeyDown) { + if (type == blink::WebInputEvent::Char || type == blink::WebInputEvent::RawKeyDown) { keyb_event->text[0] = keycode; keyb_event->unmodifiedText[0] = keycode; } @@ -592,6 +593,11 @@ void NativeWindow::SendKeyboardEvent(blink::WebInputEvent::Type type, int modifi const auto view = web_contents()->GetRenderWidgetHostView(); const auto host = view ? view->GetRenderWidgetHost() : nullptr; host->ForwardKeyboardEvent(*keyb_event); + + if(keyb_event->type == blink::WebInputEvent::Type::KeyDown){ + keyb_event->type = blink::WebInputEvent::RawKeyDown; + host->ForwardKeyboardEvent(*keyb_event); + } } void NativeWindow::SendMouseEvent(blink::WebInputEvent::Type type, int modifiers, blink::WebMouseEvent::Button button, int x, int y, int movementX, int movementY, int clickCount){ diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 8cc1d2ff2b9a..d361fcf69632 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -238,7 +238,7 @@ class NativeWindow : public content::WebContentsObserver, void OnFrameReceived(bool result, scoped_refptr frame); - void SendKeyboardEvent(blink::WebInputEvent::Type type, int modifiers, int keycode); + void SendKeyboardEvent(blink::WebInputEvent::Type type, int modifiers, int keycode, int nativeKeycode); void SendMouseEvent(blink::WebInputEvent::Type type, int modifiers, blink::WebMouseEvent::Button button, int x, int y, int movementX, int movementY, int clickCount); void SendMouseWheelEvent(int modifiers, int x, int y, bool clickCount); diff --git a/atom/common/event_types.cc b/atom/common/event_types.cc index dd87783e68bd..3d3b901ed3cc 100644 --- a/atom/common/event_types.cc +++ b/atom/common/event_types.cc @@ -16,8 +16,8 @@ const char kMouseLeave[] = "leave"; const char kContextMenu[] = "context-menu"; const char kMouseWheel[] = "wheel"; -const char kKeyDown[] = "key-down"; -const char kKeyUp[] = "key-up"; +const char kKeyDown[] = "down"; +const char kKeyUp[] = "up"; const char kChar[] = "char"; const char kMouseLeftButton[] = "left"; diff --git a/atom/common/options_switches.cc b/atom/common/options_switches.cc index ee70080ae6ae..b47e801c41b7 100644 --- a/atom/common/options_switches.cc +++ b/atom/common/options_switches.cc @@ -113,12 +113,13 @@ const char kAppUserModelId[] = "app-user-model-id"; const char kOffScreenRender[] = "offscreen-render"; const char kModifiers[] = "modifiers"; -const char kKeyCode[] = "keycode"; +const char kKeyCode[] = "code"; +const char kNativeKeyCode[] = "native"; const char kMovementX[] = "movement-x"; const char kMovementY[] = "movement-y"; const char kClickCount[] = "click-count"; -const char kMouseEventType[] = "type"; +const char kEventType[] = "type"; const char kMouseEventButton[] = "button"; const char kMouseWheelPrecise[] = "precise"; diff --git a/atom/common/options_switches.h b/atom/common/options_switches.h index 505305deb49c..062ee6846626 100644 --- a/atom/common/options_switches.h +++ b/atom/common/options_switches.h @@ -64,11 +64,12 @@ extern const char kOffScreenRender[]; extern const char kModifiers[]; extern const char kKeyCode[]; +extern const char kNativeKeyCode[]; extern const char kMovementX[]; extern const char kMovementY[]; extern const char kClickCount[]; -extern const char kMouseEventType[]; +extern const char kEventType[]; extern const char kMouseEventButton[]; extern const char kMouseWheelPrecise[]; diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index f0b8abc2792f..217844897aff 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -737,6 +737,61 @@ Returns whether the window is visible on all workspaces. Sets the offscreen rendering, if `true` the `frame-rendered` event will fire, when the frame changes. +### BrowserWindow.sendMouseEvent(options) + +Sends a mouse event to the BrowserWindow. +* `options` Object + * `type` String - The type of the mouse event. + * `down` String - Mouse down event. + * `up` String - Mouse up event. + * `move` String - Mouse move event. + * `enter` String - Mouse enter event. + * `leave` String - Mouse leave event. + * `context-menu` String - Context menu event. + * `wheel` String - Mouse wheel event. + * `x` Integer - The x component of the location of the mouse event. + * `y` Integer - The y component of the location of the mouse event. + * `movement-x` Integer - The x component of the mouse movement since the last event. + * `movement-y` Integer - The y component of the mouse movement since the last event. + * `button` String - The mouse button associated with the mouse event. Also sets the associated modifier values on the event. + * `left` String - The left button was pressed. + * `right` String - The right button was pressed. + * `middle` String - The middle button was pressed. + * `click-count` Integer - The number of clicks associated with the mouse event. + * `precise` Boolean - For the `wheel` event type, this option sets the `hasPreciseScrollingDeltas` option of the event. + * `modifiers` Array of Strings - The modifier values associated with the event. + * `left-button-down` String - The left mouse button was pressed. + * `middle-button-down` String - The right mouse button was pressed. + * `right-button-down` String - The middle mouse button was pressed. + * `shift` String - The shift key was pressed. + * `control` String - The control key was pressed. + * `alt` String - The alt key was pressed. + * `meta` String - The meta key was pressed. + * `caps-lock` String - The caps-lock key was pressed. + * `num-lock` String - The num-lock key was pressed. + +### BrowserWindow.sendKeyboardEvent(options) + +Sends a keyboard event to the BrowserWindow. +* `options` Object + * `type` String - The type of the keyboard event. + * `down` String - Key down event. + * `up` String - Key up event. + * `char` String - Character event. + * `code` Integer - The key code of the key that generated the event. + * `native` Integer - The native key code of the key that generated the event. + * `modifiers` Array of Strings - The modifier values associated with the event. + * `keypad` String - Sets the `IsKeyPad` option of the event. + * `auto-repeat` String - Sets the `IsAutoRepeat` option of the event. + * `left` String - Sets the `IsLeft` option of the event. + * `right` String - Sets the `IsRight` option of the event. + * `shift` String - The shift key was pressed. + * `control` String - The control key was pressed. + * `alt` String - The alt key was pressed. + * `meta` String - The meta key was pressed. + * `caps-lock` String - The caps-lock key was pressed. + * `num-lock` String - The num-lock key was pressed. + ## Class: WebContents A `WebContents` is responsible for rendering and controlling a web page.