| OLD | NEW |
| 1 #!/usr/bin/python2.4 | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2006-2008 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 """ |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 | 159 |
| 160 # Type the key with the specified length, then wait the specified delay | 160 # Type the key with the specified length, then wait the specified delay |
| 161 TypeKey(vk & 0xFF, keystroke_time) | 161 TypeKey(vk & 0xFF, keystroke_time) |
| 162 time.sleep(time_between_keystrokes) | 162 time.sleep(time_between_keystrokes) |
| 163 | 163 |
| 164 # Release the modifier keys, if held | 164 # Release the modifier keys, if held |
| 165 if shift_held: PressKey(False, win32con.VK_SHIFT) | 165 if shift_held: PressKey(False, win32con.VK_SHIFT) |
| 166 if ctrl_held: PressKey(False, win32con.VK_CONTROL) | 166 if ctrl_held: PressKey(False, win32con.VK_CONTROL) |
| 167 if alt_held: PressKey(False, win32con.VK_MENU) | 167 if alt_held: PressKey(False, win32con.VK_MENU) |
| 168 | 168 |
| 169 if __name__ == "__main__": | 169 |
| 170 def main(): |
| 170 # We're being invoked rather than imported. Let's do some tests | 171 # We're being invoked rather than imported. Let's do some tests |
| 171 | 172 |
| 172 # Press command-R to bring up the Run dialog | 173 # Press command-R to bring up the Run dialog |
| 173 PressKey(True, win32con.VK_LWIN) | 174 PressKey(True, win32con.VK_LWIN) |
| 174 TypeKey(ord('R')) | 175 TypeKey(ord('R')) |
| 175 PressKey(False, win32con.VK_LWIN) | 176 PressKey(False, win32con.VK_LWIN) |
| 176 | 177 |
| 177 # Wait a sec to make sure it comes up | 178 # Wait a sec to make sure it comes up |
| 178 time.sleep(1) | 179 time.sleep(1) |
| 179 | 180 |
| 180 # Invoke Notepad through the Run dialog | 181 # Invoke Notepad through the Run dialog |
| 181 TypeString("wordpad\n") | 182 TypeString("wordpad\n") |
| 182 | 183 |
| 183 # Wait another sec, then start typing | 184 # Wait another sec, then start typing |
| 184 time.sleep(1) | 185 time.sleep(1) |
| 185 TypeString("This is a test of SiteCompare's Keyboard.py module.\n\n") | 186 TypeString("This is a test of SiteCompare's Keyboard.py module.\n\n") |
| 186 TypeString("There should be a blank line above and below this one.\n\n") | 187 TypeString("There should be a blank line above and below this one.\n\n") |
| 187 TypeString("This line has control characters to make " | 188 TypeString("This line has control characters to make " |
| 188 "[b]boldface text[b] and [i]italic text[i] and normal text.\n\n", | 189 "[b]boldface text[b] and [i]italic text[i] and normal text.\n\n", |
| 189 use_modifiers=True) | 190 use_modifiers=True) |
| 190 TypeString(r"This line should be typed with a visible delay between " | 191 TypeString(r"This line should be typed with a visible delay between " |
| 191 "characters. When it ends, there should be a 3-second pause, " | 192 "characters. When it ends, there should be a 3-second pause, " |
| 192 "then the menu will select File/Exit, then another 3-second " | 193 "then the menu will select File/Exit, then another 3-second " |
| 193 "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", |
| 194 use_modifiers=True, | 195 use_modifiers=True, |
| 195 keystroke_time=0.05, | 196 keystroke_time=0.05, |
| 196 time_between_keystrokes=0.05) | 197 time_between_keystrokes=0.05) |
| 197 | 198 |
| 198 | 199 |
| 200 if __name__ == "__main__": |
| 201 sys.exit(main()) |
| OLD | NEW |