diff options
Diffstat (limited to 'remoting/host/event_executor_win.cc')
-rw-r--r-- | remoting/host/event_executor_win.cc | 41 |
1 files changed, 19 insertions, 22 deletions
diff --git a/remoting/host/event_executor_win.cc b/remoting/host/event_executor_win.cc index 02e0f4c..6398a74db 100644 --- a/remoting/host/event_executor_win.cc +++ b/remoting/host/event_executor_win.cc @@ -11,6 +11,7 @@ #include "base/location.h" #include "base/memory/ref_counted.h" #include "base/single_thread_task_runner.h" +#include "remoting/base/util.h" #include "remoting/host/clipboard.h" #include "remoting/proto/event.pb.h" // SkSize.h assumes that stdint.h-style types are already defined. @@ -128,6 +129,7 @@ void EventExecutorWin::Core::InjectClipboardEvent(const ClipboardEvent& event) { return; } + // |clipboard_| will ignore unknown MIME-types, and verify the data's format. clipboard_->InjectClipboardEvent(event); } @@ -177,12 +179,21 @@ EventExecutorWin::Core::~Core() { void EventExecutorWin::Core::HandleKey(const KeyEvent& event) { // HostEventDispatcher should filter events missing the pressed field. - DCHECK(event.has_pressed()); - DCHECK(event.has_usb_keycode()); + if (!event.has_pressed() || !event.has_usb_keycode()) + return; // Reset the system idle suspend timeout. SetThreadExecutionState(ES_SYSTEM_REQUIRED); + int scancode = UsbKeycodeToNativeKeycode(event.usb_keycode()); + + VLOG(3) << "Converting USB keycode: " << std::hex << event.usb_keycode() + << " to scancode: " << scancode << std::dec; + + // Ignore events which can't be mapped. + if (scancode == InvalidNativeKeycode()) + return; + // Populate the a Windows INPUT structure for the event. INPUT input; memset(&input, 0, sizeof(input)); @@ -192,26 +203,16 @@ void EventExecutorWin::Core::HandleKey(const KeyEvent& event) { if (!event.pressed()) input.ki.dwFlags |= KEYEVENTF_KEYUP; - int scancode = UsbKeycodeToNativeKeycode(event.usb_keycode()); - VLOG(3) << "Converting USB keycode: " << std::hex << event.usb_keycode() - << " to scancode: " << scancode << std::dec; - - // Ignore events which can't be mapped. - if (scancode == InvalidNativeKeycode()) - return; - // Windows scancodes are only 8-bit, so store the low-order byte into the // event and set the extended flag if any high-order bits are set. The only // high-order values we should see are 0xE0 or 0xE1. The extended bit usually // distinguishes keys with the same meaning, e.g. left & right shift. input.ki.wScan = scancode & 0xFF; - if ((scancode & 0xFF00) != 0x0000) { + if ((scancode & 0xFF00) != 0x0000) input.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY; - } - if (SendInput(1, &input, sizeof(INPUT)) == 0) { + if (SendInput(1, &input, sizeof(INPUT)) == 0) LOG_GETLASTERROR(ERROR) << "Failed to inject a key event"; - } } void EventExecutorWin::Core::HandleMouse(const MouseEvent& event) { @@ -236,9 +237,8 @@ void EventExecutorWin::Core::HandleMouse(const MouseEvent& event) { input.mi.dy = static_cast<int>((y * 65535) / (screen_size.height() - 1)); input.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_VIRTUALDESK; - if (SendInput(1, &input, sizeof(INPUT)) == 0) { + if (SendInput(1, &input, sizeof(INPUT)) == 0) LOG_GETLASTERROR(ERROR) << "Failed to inject a mouse move event"; - } } } @@ -257,16 +257,14 @@ void EventExecutorWin::Core::HandleMouse(const MouseEvent& event) { if (wheel_delta_x != 0) { wheel.mi.mouseData = wheel_delta_x; wheel.mi.dwFlags = MOUSEEVENTF_HWHEEL; - if (SendInput(1, &wheel, sizeof(INPUT)) == 0) { + if (SendInput(1, &wheel, sizeof(INPUT)) == 0) LOG_GETLASTERROR(ERROR) << "Failed to inject a mouse wheel(x) event"; - } } if (wheel_delta_y != 0) { wheel.mi.mouseData = wheel_delta_y; wheel.mi.dwFlags = MOUSEEVENTF_WHEEL; - if (SendInput(1, &wheel, sizeof(INPUT)) == 0) { + if (SendInput(1, &wheel, sizeof(INPUT)) == 0) LOG_GETLASTERROR(ERROR) << "Failed to inject a mouse wheel(y) event"; - } } } @@ -293,9 +291,8 @@ void EventExecutorWin::Core::HandleMouse(const MouseEvent& event) { down ? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_LEFTUP; } - if (SendInput(1, &button_event, sizeof(INPUT)) == 0) { + if (SendInput(1, &button_event, sizeof(INPUT)) == 0) LOG_GETLASTERROR(ERROR) << "Failed to inject a mouse button event"; - } } } |