OLD | NEW |
| (Empty) |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_FRAME_TEST_SIMULATE_INPUT_H_ | |
6 #define CHROME_FRAME_TEST_SIMULATE_INPUT_H_ | |
7 | |
8 #include <windows.h> | |
9 #include <string> | |
10 | |
11 #include "base/basictypes.h" | |
12 #include "base/process/process_handle.h" | |
13 | |
14 namespace simulate_input { | |
15 | |
16 enum Modifier { | |
17 NONE, | |
18 SHIFT = 1, | |
19 CONTROL = 2, | |
20 ALT = 4 | |
21 }; | |
22 | |
23 enum KeyMode { | |
24 KEY_DOWN, | |
25 KEY_UP, | |
26 }; | |
27 | |
28 // Bring a window into foreground to receive user input. | |
29 // Note that this may not work on | |
30 bool ForceSetForegroundWindow(HWND window); | |
31 | |
32 // Looks for a top level window owned by the given process id and | |
33 // calls ForceSetForegroundWindow on it. | |
34 bool EnsureProcessInForeground(base::ProcessId process_id); | |
35 | |
36 // Helper function to set keyboard focus to a window. This is achieved by | |
37 // sending a mouse move followed by a mouse down/mouse up combination to the | |
38 // window. | |
39 void SetKeyboardFocusToWindow(HWND window); | |
40 | |
41 // Sends a keystroke to the currently active application with optional modifiers | |
42 // set. Sends one "key (down|up)" input event for each modifier set, plus one | |
43 // for |mnemonic_char| depending on the value of |key_mode|. This can be useful | |
44 // as it has been observed that tests will exit after receiving the "key down" | |
45 // events leaving the keyboard in an inconsistent state. | |
46 void SendMnemonic(WORD mnemonic_char, uint32 modifiers, bool extended, | |
47 bool unicode, KeyMode key_mode); | |
48 | |
49 // Sends a mouse click to the desktop. | |
50 enum MouseButton { LEFT, RIGHT, MIDDLE, X }; | |
51 void SendMouseClick(int x, int y, MouseButton button); | |
52 // Sends a mouse click to the window passed in, after ensuring that the window | |
53 // is in the foreground. | |
54 void SendMouseClick(HWND window, int x, int y, MouseButton button); | |
55 | |
56 // Translates a single char to a virtual key. | |
57 void SendScanCode(short scan_code, uint32 modifiers); | |
58 void SendCharA(char c, uint32 modifiers); | |
59 void SendCharW(wchar_t c, uint32 modifiers); | |
60 | |
61 // Sends extended keystroke to the currently active application with optional | |
62 // modifiers set. | |
63 void SendExtendedKey(WORD key, uint32 modifiers); | |
64 | |
65 // Iterates through all the characters in the string and simulates | |
66 // keyboard input. The input goes to the currently active application. | |
67 void SendStringW(const std::wstring& s); | |
68 void SendStringA(const std::string& s); | |
69 | |
70 } // end namespace simulate_input | |
71 | |
72 #endif // CHROME_FRAME_TEST_SIMULATE_INPUT_H_ | |
73 | |
OLD | NEW |