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) 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 mouse input. | 6 """SiteCompare module for simulating mouse 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 navigating using a pointing device. This includes mouse movement, | 9 navigating using a pointing device. This includes mouse movement, |
10 clicking with any button, and dragging. | 10 clicking with any button, and dragging. |
11 """ | 11 """ |
12 | 12 |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 click_time: duration of the clicks | 182 click_time: duration of the clicks |
183 time_between_clicks: length of time to pause between clicks | 183 time_between_clicks: length of time to pause between clicks |
184 | 184 |
185 Returns: | 185 Returns: |
186 Nothing | 186 Nothing |
187 """ | 187 """ |
188 ClickInWindow(hwnd, offset, button, click_time) | 188 ClickInWindow(hwnd, offset, button, click_time) |
189 time.sleep(time_between_clicks) | 189 time.sleep(time_between_clicks) |
190 ClickInWindow(hwnd, offset, button, click_time) | 190 ClickInWindow(hwnd, offset, button, click_time) |
191 | 191 |
192 if __name__ == "__main__": | 192 |
| 193 def main(): |
193 # We're being invoked rather than imported. Let's do some tests | 194 # We're being invoked rather than imported. Let's do some tests |
194 | 195 |
195 screen_size = win32gui.GetClientRect(win32gui.GetDesktopWindow()) | 196 screen_size = win32gui.GetClientRect(win32gui.GetDesktopWindow()) |
196 screen_size = (screen_size[2], screen_size[3]) | 197 screen_size = (screen_size[2], screen_size[3]) |
197 | 198 |
198 # move the mouse (instantly) to the upper right corner | 199 # move the mouse (instantly) to the upper right corner |
199 MoveToLocation((screen_size[0], 0)) | 200 MoveToLocation((screen_size[0], 0)) |
200 | 201 |
201 # move the mouse (over five seconds) to the lower left corner | 202 # move the mouse (over five seconds) to the lower left corner |
202 MoveToLocation((0, screen_size[1]), 5) | 203 MoveToLocation((0, screen_size[1]), 5) |
203 | 204 |
204 # click the left mouse button. This will open up the Start menu | 205 # click the left mouse button. This will open up the Start menu |
205 # if the taskbar is at the bottom | 206 # if the taskbar is at the bottom |
206 | 207 |
207 ClickButton() | 208 ClickButton() |
208 | 209 |
209 # wait a bit, then click the right button to open the context menu | 210 # wait a bit, then click the right button to open the context menu |
210 time.sleep(3) | 211 time.sleep(3) |
211 ClickButton('right') | 212 ClickButton('right') |
212 | 213 |
213 # move the mouse away and then click the left button to dismiss the | 214 # move the mouse away and then click the left button to dismiss the |
214 # context menu | 215 # context menu |
215 MoveToLocation((screen_size[0]/2, screen_size[1]/2), 3) | 216 MoveToLocation((screen_size[0]/2, screen_size[1]/2), 3) |
216 MoveToLocation((0, 0), 3) | 217 MoveToLocation((0, 0), 3) |
217 ClickButton() | 218 ClickButton() |
218 | 219 |
| 220 |
| 221 if __name__ == "__main__": |
| 222 sys.exit(main()) |
OLD | NEW |