| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "chrome/test/chromedriver/keycode_text_conversion.h" | 5 #include "chrome/test/chromedriver/keycode_text_conversion.h" |
| 6 | 6 |
| 7 #include <VersionHelpers.h> |
| 7 #include <stdlib.h> | 8 #include <stdlib.h> |
| 8 #include <windows.h> | 9 #include <windows.h> |
| 9 | 10 |
| 11 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/test/chromedriver/chrome/ui_events.h" | 13 #include "chrome/test/chromedriver/chrome/ui_events.h" |
| 12 | 14 |
| 13 bool ConvertKeyCodeToText( | 15 bool ConvertKeyCodeToText( |
| 14 ui::KeyboardCode key_code, int modifiers, std::string* text, | 16 ui::KeyboardCode key_code, int modifiers, std::string* text, |
| 15 std::string* error_msg) { | 17 std::string* error_msg) { |
| 16 UINT scan_code = ::MapVirtualKeyW(key_code, MAPVK_VK_TO_VSC); | 18 UINT scan_code = ::MapVirtualKeyW(key_code, MAPVK_VK_TO_VSC); |
| 17 BYTE keyboard_state[256]; | 19 BYTE keyboard_state[256]; |
| 18 memset(keyboard_state, 0, 256); | 20 memset(keyboard_state, 0, 256); |
| 19 *error_msg = std::string(); | 21 *error_msg = std::string(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 50 modifiers |= kShiftKeyModifierMask; | 52 modifiers |= kShiftKeyModifierMask; |
| 51 if (win_modifiers & 0x02) | 53 if (win_modifiers & 0x02) |
| 52 modifiers |= kControlKeyModifierMask; | 54 modifiers |= kControlKeyModifierMask; |
| 53 if (win_modifiers & 0x04) | 55 if (win_modifiers & 0x04) |
| 54 modifiers |= kAltKeyModifierMask; | 56 modifiers |= kAltKeyModifierMask; |
| 55 // Ignore bit 0x08: It is for Hankaku key. | 57 // Ignore bit 0x08: It is for Hankaku key. |
| 56 *necessary_modifiers = modifiers; | 58 *necessary_modifiers = modifiers; |
| 57 } | 59 } |
| 58 return translated; | 60 return translated; |
| 59 } | 61 } |
| 62 |
| 63 bool SwitchToUSKeyboardLayout() { |
| 64 // For LoadKeyboardLayout - Prior to Windows 8: If the specified input |
| 65 // locale identifier is not already loaded, the function loads and |
| 66 // activates the input locale identifier for the current thread. |
| 67 // Beginning in Windows 8: If the specified input locale identifier is not |
| 68 // already loaded, the function loads and activates the input |
| 69 // locale identifier for the system. |
| 70 // For Windows 8 - Use ActivateKeyboardLayout instead of LoadKeyboardLayout |
| 71 LPCTSTR kUsKeyboardLayout = TEXT("00000409"); |
| 72 |
| 73 if (IsWindows8OrGreater()) { |
| 74 int size; |
| 75 TCHAR active_keyboard[KL_NAMELENGTH]; |
| 76 |
| 77 if ((size = ::GetKeyboardLayoutList(0, NULL)) <= 0) |
| 78 return false; |
| 79 |
| 80 scoped_ptr<HKL[]> keyboard_handles_list(new HKL[size]); |
| 81 ::GetKeyboardLayoutList(size, keyboard_handles_list.get()); |
| 82 |
| 83 for (int keyboard_index = 0; keyboard_index < size; keyboard_index++) { |
| 84 ::ActivateKeyboardLayout(keyboard_handles_list[keyboard_index], |
| 85 KLF_SETFORPROCESS); |
| 86 ::GetKeyboardLayoutName(active_keyboard); |
| 87 if (wcscmp(active_keyboard, kUsKeyboardLayout) == 0) |
| 88 return true; |
| 89 } |
| 90 return false; |
| 91 } else { |
| 92 return ::LoadKeyboardLayout(kUsKeyboardLayout, KLF_ACTIVATE) != NULL; |
| 93 } |
| 94 } |
| OLD | NEW |