Chromium Code Reviews| Index: remoting/host/input_injector_win.cc |
| diff --git a/remoting/host/input_injector_win.cc b/remoting/host/input_injector_win.cc |
| index 9354eda63932baf3730db215a64314e34a1fe823..d2a52f4b12d6d12424f959adfa56a0078fbb8ea6 100644 |
| --- a/remoting/host/input_injector_win.cc |
| +++ b/remoting/host/input_injector_win.cc |
| @@ -199,6 +199,12 @@ class InputInjectorWin : public InputInjector { |
| void HandleMouse(const MouseEvent& event); |
| void HandleTouch(const TouchEvent& event); |
| + // Check if the given scan code is caps lock or num lock. |
| + bool IsLockKey(int scancode); |
| + |
| + // Sets the keyboard lock states to those provided. |
| + void SetLockStates(uint32_t states); |
| + |
| scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
| scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; |
| std::unique_ptr<Clipboard> clipboard_; |
| @@ -348,6 +354,10 @@ void InputInjectorWin::Core::HandleKey(const KeyEvent& event) { |
| if (scancode == ui::KeycodeConverter::InvalidNativeKeycode()) |
| return; |
| + if (event.has_lock_states() && !IsLockKey(scancode)) { |
| + SetLockStates(event.lock_states()); |
| + } |
| + |
| uint32_t flags = KEYEVENTF_SCANCODE | (event.pressed() ? 0 : KEYEVENTF_KEYUP); |
| SendKeyboardInput(flags, scancode); |
| } |
| @@ -384,6 +394,37 @@ void InputInjectorWin::Core::HandleTouch(const TouchEvent& event) { |
| touch_injector_->InjectTouchEvent(event); |
| } |
| +bool InputInjectorWin::Core::IsLockKey(int scancode) { |
| + UINT virtual_key = MapVirtualKey(scancode, MAPVK_VSC_TO_VK); |
| + return virtual_key == VK_CAPITAL || virtual_key == VK_NUMLOCK; |
| +} |
| + |
| +void InputInjectorWin::Core::SetLockStates(uint32_t states) { |
| + // Can't use SendKeyboardInput because we need to send virtual key codes, not |
| + // scan codes. |
| + INPUT input[2] = {}; |
| + input[0].type = INPUT_KEYBOARD; |
| + input[1].type = INPUT_KEYBOARD; |
| + input[1].ki.dwFlags = KEYEVENTF_KEYUP; |
| + |
| + bool client_capslock_state = |
| + states & protocol::KeyEvent::LOCK_STATES_CAPSLOCK; |
|
joedow
2017/05/01 15:14:28
I get a build error, this works though:
bool clien
rkjnsn
2017/05/01 17:46:27
I ran the code through Clang before uploading, but
|
| + bool host_capslock_state = GetKeyState(VK_CAPITAL) & 1; |
| + if (client_capslock_state != host_capslock_state) { |
| + input[0].ki.wVk = VK_CAPITAL; |
| + input[1].ki.wVk = VK_CAPITAL; |
| + SendInput(arraysize(input), input, sizeof(INPUT)); |
| + } |
| + |
| + bool client_numlock_state = states & protocol::KeyEvent::LOCK_STATES_NUMLOCK; |
|
joedow
2017/05/01 15:14:28
Another build error:
bool client_numlock_state =
rkjnsn
2017/05/01 17:46:27
Changed along with following line.
|
| + bool host_numlock_state = GetKeyState(VK_NUMLOCK) & 1; |
| + if (client_numlock_state != host_numlock_state) { |
| + input[0].ki.wVk = VK_NUMLOCK; |
| + input[1].ki.wVk = VK_NUMLOCK; |
| + SendInput(arraysize(input), input, sizeof(INPUT)); |
| + } |
| +} |
| + |
| } // namespace |
| // static |