| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/host/event_executor.h" | 5 #include "remoting/host/event_executor.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 uint16_t UsbKeycodeToWinScancode(uint32_t usb_keycode) { | 87 uint16_t UsbKeycodeToWinScancode(uint32_t usb_keycode) { |
| 88 for (int i = 0; i < arraysize(usb_keycode_map); i++) { | 88 for (int i = 0; i < arraysize(usb_keycode_map); i++) { |
| 89 if (usb_keycode_map[i].usb_keycode == usb_keycode) | 89 if (usb_keycode_map[i].usb_keycode == usb_keycode) |
| 90 return usb_keycode_map[i].native_keycode; | 90 return usb_keycode_map[i].native_keycode; |
| 91 } | 91 } |
| 92 | 92 |
| 93 return INVALID_KEYCODE; | 93 return INVALID_KEYCODE; |
| 94 } | 94 } |
| 95 | 95 |
| 96 void EventExecutorWin::HandleKey(const KeyEvent& event) { | 96 void EventExecutorWin::HandleKey(const KeyEvent& event) { |
| 97 // Reset the system idle suspend timeout. |
| 98 SetThreadExecutionState(ES_SYSTEM_REQUIRED); |
| 99 |
| 100 // Calculate scan code from key event. |
| 97 int key = event.keycode(); | 101 int key = event.keycode(); |
| 98 bool down = event.pressed(); | 102 bool down = event.pressed(); |
| 99 | |
| 100 // Calculate scan code from key event. | |
| 101 int scancode = INVALID_KEYCODE; | 103 int scancode = INVALID_KEYCODE; |
| 102 if (event.has_usb_keycode() && event.usb_keycode() != 0) { | 104 if (event.has_usb_keycode() && event.usb_keycode() != 0) { |
| 103 scancode = UsbKeycodeToWinScancode(event.usb_keycode()); | 105 scancode = UsbKeycodeToWinScancode(event.usb_keycode()); |
| 104 LOG(INFO) << std::hex << "Host received keycode: " << event.keycode() | 106 LOG(INFO) << std::hex << "Host received keycode: " << event.keycode() |
| 105 << " usb_keycode: " << event.usb_keycode() | 107 << " usb_keycode: " << event.usb_keycode() |
| 106 << " to scancode: " << scancode | 108 << " to scancode: " << scancode |
| 107 << std::dec; | 109 << std::dec; |
| 108 } else { | 110 } else { |
| 109 HKL hkl = GetKeyboardLayout(0); | 111 HKL hkl = GetKeyboardLayout(0); |
| 110 scancode = MapVirtualKeyEx(key, MAPVK_VK_TO_VSC_EX, hkl); | 112 scancode = MapVirtualKeyEx(key, MAPVK_VK_TO_VSC_EX, hkl); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 131 if (!down) { | 133 if (!down) { |
| 132 input.ki.dwFlags |= KEYEVENTF_KEYUP; | 134 input.ki.dwFlags |= KEYEVENTF_KEYUP; |
| 133 } | 135 } |
| 134 | 136 |
| 135 if (SendInput(1, &input, sizeof(INPUT)) == 0) { | 137 if (SendInput(1, &input, sizeof(INPUT)) == 0) { |
| 136 LOG_GETLASTERROR(ERROR) << "Failed to inject a key event"; | 138 LOG_GETLASTERROR(ERROR) << "Failed to inject a key event"; |
| 137 } | 139 } |
| 138 } | 140 } |
| 139 | 141 |
| 140 void EventExecutorWin::HandleMouse(const MouseEvent& event) { | 142 void EventExecutorWin::HandleMouse(const MouseEvent& event) { |
| 143 // Reset the system idle suspend timeout. |
| 144 SetThreadExecutionState(ES_SYSTEM_REQUIRED); |
| 145 |
| 141 // TODO(garykac) Collapse mouse (x,y) and button events into a single | 146 // TODO(garykac) Collapse mouse (x,y) and button events into a single |
| 142 // input event when possible. | 147 // input event when possible. |
| 143 if (event.has_x() && event.has_y()) { | 148 if (event.has_x() && event.has_y()) { |
| 144 int x = event.x(); | 149 int x = event.x(); |
| 145 int y = event.y(); | 150 int y = event.y(); |
| 146 | 151 |
| 147 INPUT input; | 152 INPUT input; |
| 148 input.type = INPUT_MOUSE; | 153 input.type = INPUT_MOUSE; |
| 149 input.mi.time = 0; | 154 input.mi.time = 0; |
| 150 SkISize screen_size = capturer_->size_most_recent(); | 155 SkISize screen_size = capturer_->size_most_recent(); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 | 218 |
| 214 } // namespace | 219 } // namespace |
| 215 | 220 |
| 216 scoped_ptr<protocol::HostEventStub> EventExecutor::Create( | 221 scoped_ptr<protocol::HostEventStub> EventExecutor::Create( |
| 217 MessageLoop* message_loop, Capturer* capturer) { | 222 MessageLoop* message_loop, Capturer* capturer) { |
| 218 return scoped_ptr<protocol::HostEventStub>( | 223 return scoped_ptr<protocol::HostEventStub>( |
| 219 new EventExecutorWin(message_loop, capturer)); | 224 new EventExecutorWin(message_loop, capturer)); |
| 220 } | 225 } |
| 221 | 226 |
| 222 } // namespace remoting | 227 } // namespace remoting |
| OLD | NEW |