| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """SiteCompare module for simulating keyboard input. | 6 """SiteCompare module for simulating keyboard input. |
| 7 | 7 |
| 8 This module contains functions that can be used to simulate a user | 8 This module contains functions that can be used to simulate a user |
| 9 pressing keys on a keyboard. Support is provided for formatted strings | 9 pressing keys on a keyboard. Support is provided for formatted strings |
| 10 including special characters to represent modifier keys like CTRL and ALT | 10 including special characters to represent modifier keys like CTRL and ALT |
| 11 """ | 11 """ |
| 12 | 12 |
| 13 import time # for sleep | 13 import time # for sleep |
| 14 import win32api # for keybd_event and VkKeyCode | 14 import win32api # for keybd_event and VkKeyCode |
| 15 import win32con # Windows constants | 15 import win32con # Windows constants |
| 16 | 16 |
| 17 # TODO(jhaas): Ask the readability guys if this would be acceptable: | 17 # TODO(jhaas): Ask the readability people if this would be acceptable: |
| 18 # | 18 # |
| 19 # from win32con import VK_SHIFT, VK_CONTROL, VK_MENU, VK_LWIN, KEYEVENTF_KEYUP | 19 # from win32con import VK_SHIFT, VK_CONTROL, VK_MENU, VK_LWIN, KEYEVENTF_KEYUP |
| 20 # | 20 # |
| 21 # This is a violation of the style guide but having win32con. everywhere | 21 # This is a violation of the style guide but having win32con. everywhere |
| 22 # is just plain ugly, and win32con is a huge import for just a handful of | 22 # is just plain ugly, and win32con is a huge import for just a handful of |
| 23 # constants | 23 # constants |
| 24 | 24 |
| 25 | 25 |
| 26 def PressKey(down, key): | 26 def PressKey(down, key): |
| 27 """Presses or unpresses a key. | 27 """Presses or unpresses a key. |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 "characters. When it ends, there should be a 3-second pause, " | 192 "characters. When it ends, there should be a 3-second pause, " |
| 193 "then the menu will select File/Exit, then another 3-second " | 193 "then the menu will select File/Exit, then another 3-second " |
| 194 "pause, then No to exit without saving. Ready?\p\p\p{f}x\p\p\pn", | 194 "pause, then No to exit without saving. Ready?\p\p\p{f}x\p\p\pn", |
| 195 use_modifiers=True, | 195 use_modifiers=True, |
| 196 keystroke_time=0.05, | 196 keystroke_time=0.05, |
| 197 time_between_keystrokes=0.05) | 197 time_between_keystrokes=0.05) |
| 198 | 198 |
| 199 | 199 |
| 200 if __name__ == "__main__": | 200 if __name__ == "__main__": |
| 201 sys.exit(main()) | 201 sys.exit(main()) |
| OLD | NEW |