Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(330)

Side by Side Diff: remoting/host/input_injector_win.cc

Issue 2843213002: When receiving a key event on Windows, set host lock state to match client's (Closed)
Patch Set: Don't try to toggle lock states if current keypres is a lock key. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/input_injector.h" 5 #include "remoting/host/input_injector.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <windows.h> 8 #include <windows.h>
9 9
10 #include <utility> 10 #include <utility>
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 192
193 private: 193 private:
194 friend class base::RefCountedThreadSafe<Core>; 194 friend class base::RefCountedThreadSafe<Core>;
195 virtual ~Core(); 195 virtual ~Core();
196 196
197 void HandleKey(const KeyEvent& event); 197 void HandleKey(const KeyEvent& event);
198 void HandleText(const TextEvent& event); 198 void HandleText(const TextEvent& event);
199 void HandleMouse(const MouseEvent& event); 199 void HandleMouse(const MouseEvent& event);
200 void HandleTouch(const TouchEvent& event); 200 void HandleTouch(const TouchEvent& event);
201 201
202 // Check if the given scan code is caps lock or num lock
joedow 2017/04/27 19:43:43 nit: add period to end of comment
rkjnsn 2017/04/28 17:06:27 Done.
203 void IsLockKey(int scancode);
joedow 2017/04/27 19:43:42 nit: add newline here
rkjnsn 2017/04/28 17:06:27 Done.
204 // Sets the keyboard lock states to those provided.
205 void SetLockStates(uint32_t states);
206
202 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; 207 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
203 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; 208 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
204 std::unique_ptr<Clipboard> clipboard_; 209 std::unique_ptr<Clipboard> clipboard_;
205 std::unique_ptr<TouchInjectorWin> touch_injector_; 210 std::unique_ptr<TouchInjectorWin> touch_injector_;
206 211
207 DISALLOW_COPY_AND_ASSIGN(Core); 212 DISALLOW_COPY_AND_ASSIGN(Core);
208 }; 213 };
209 214
210 scoped_refptr<Core> core_; 215 scoped_refptr<Core> core_;
211 216
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 346
342 int scancode = 347 int scancode =
343 ui::KeycodeConverter::UsbKeycodeToNativeKeycode(event.usb_keycode()); 348 ui::KeycodeConverter::UsbKeycodeToNativeKeycode(event.usb_keycode());
344 VLOG(3) << "Converting USB keycode: " << std::hex << event.usb_keycode() 349 VLOG(3) << "Converting USB keycode: " << std::hex << event.usb_keycode()
345 << " to scancode: " << scancode << std::dec; 350 << " to scancode: " << scancode << std::dec;
346 351
347 // Ignore events which can't be mapped. 352 // Ignore events which can't be mapped.
348 if (scancode == ui::KeycodeConverter::InvalidNativeKeycode()) 353 if (scancode == ui::KeycodeConverter::InvalidNativeKeycode())
349 return; 354 return;
350 355
356 if (event.has_lock_states() && !IsLockKey(scancode)) {
joedow 2017/04/27 19:43:43 When testing this change, it looks like the lock s
rkjnsn 2017/04/28 17:06:27 Looks like I had | where I should have had &.
357 SetLockStates(event.lock_states());
358 }
359
351 uint32_t flags = KEYEVENTF_SCANCODE | (event.pressed() ? 0 : KEYEVENTF_KEYUP); 360 uint32_t flags = KEYEVENTF_SCANCODE | (event.pressed() ? 0 : KEYEVENTF_KEYUP);
352 SendKeyboardInput(flags, scancode); 361 SendKeyboardInput(flags, scancode);
353 } 362 }
354 363
355 void InputInjectorWin::Core::HandleText(const TextEvent& event) { 364 void InputInjectorWin::Core::HandleText(const TextEvent& event) {
356 // HostEventDispatcher should filter events missing the pressed field. 365 // HostEventDispatcher should filter events missing the pressed field.
357 DCHECK(event.has_text()); 366 DCHECK(event.has_text());
358 367
359 base::string16 text = base::UTF8ToUTF16(event.text()); 368 base::string16 text = base::UTF8ToUTF16(event.text());
360 for (base::string16::const_iterator it = text.begin(); 369 for (base::string16::const_iterator it = text.begin();
(...skipping 16 matching lines...) Expand all
377 if (SendInput(inputs.size(), inputs.data(), sizeof(INPUT)) != inputs.size()) 386 if (SendInput(inputs.size(), inputs.data(), sizeof(INPUT)) != inputs.size())
378 PLOG(ERROR) << "Failed to inject a mouse event"; 387 PLOG(ERROR) << "Failed to inject a mouse event";
379 } 388 }
380 } 389 }
381 390
382 void InputInjectorWin::Core::HandleTouch(const TouchEvent& event) { 391 void InputInjectorWin::Core::HandleTouch(const TouchEvent& event) {
383 DCHECK(touch_injector_); 392 DCHECK(touch_injector_);
384 touch_injector_->InjectTouchEvent(event); 393 touch_injector_->InjectTouchEvent(event);
385 } 394 }
386 395
396 void InputInjectorWin::Core::IsLockKey(int scancode) {
397 UINT virtual_key = MapVirtualKey(scancode, MAPVK_VSC_TO_VK);
398 return virtual_key == VK_CAPITAL || virtual_key == VK_NUMLOCK;
399 }
400
401 void InputInjectorWin::Core::SetLockStates(uint32_t states) {
402 // Can't use SendKeyboardInput because we need to send virtual key codes, not
403 // scan codes.
404 INPUT input[2];
joedow 2017/04/27 19:43:43 You can remove the memset call and use this for in
rkjnsn 2017/04/28 17:06:27 Ah, right. I took and modified the code from SendK
joedow 2017/04/28 17:16:26 Either way is fine with me :)
405 memset(&input, 0, sizeof(input));
406 input[0].type = INPUT_KEYBOARD;
407 input[1].type = INPUT_KEYBOARD;
408 input[1].ki.dwFlags = KEYEVENTF_KEYUP;
409 if (!!(states | protocol::KeyEvent::LOCK_STATES_CAPSLOCK) !=
410 !!(GetKeyState(VK_CAPITAL) & 1)) {
Jamie 2017/04/27 19:06:32 I find !! to be not very readable. A better approa
joedow 2017/04/27 19:43:43 +1, double-bang boolification is less readable in
rkjnsn 2017/04/28 17:06:27 Would changing `!!(states & protocol::KeyEvent::LO
joedow 2017/04/28 17:16:26 My preference is to extract the work needed to det
rkjnsn 2017/04/28 17:33:12 Fun fact: C++11 apparently disallowed non-constant
411 input[0].ki.wVk = VK_CAPITAL;
412 input[1].ki.wVk = VK_CAPITAL;
413 SendInput(arraysize(input), input, sizeof(INPUT));
414 }
415 if (!!(states | protocol::KeyEvent::LOCK_STATES_NUMLOCK) !=
416 !!(GetKeyState(VK_NUMLOCK) & 1)) {
417 input[0].ki.wVk = VK_NUMLOCK;
418 input[1].ki.wVk = VK_NUMLOCK;
419 SendInput(arraysize(input), input, sizeof(INPUT));
420 }
421 }
422
387 } // namespace 423 } // namespace
388 424
389 // static 425 // static
390 std::unique_ptr<InputInjector> InputInjector::Create( 426 std::unique_ptr<InputInjector> InputInjector::Create(
391 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, 427 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
392 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { 428 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) {
393 return base::WrapUnique( 429 return base::WrapUnique(
394 new InputInjectorWin(main_task_runner, ui_task_runner)); 430 new InputInjectorWin(main_task_runner, ui_task_runner));
395 } 431 }
396 432
397 // static 433 // static
398 bool InputInjector::SupportsTouchEvents() { 434 bool InputInjector::SupportsTouchEvents() {
399 return base::win::GetVersion() >= base::win::VERSION_WIN8; 435 return base::win::GetVersion() >= base::win::VERSION_WIN8;
400 } 436 }
401 437
402 } // namespace remoting 438 } // namespace remoting
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698