| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 The Chromium OS 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 AUTOX_SCRIPT_RUNNER_H_ | |
| 6 #define AUTOX_SCRIPT_RUNNER_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <set> | |
| 10 #include <string> | |
| 11 | |
| 12 extern "C" { | |
| 13 #include <X11/Xlib.h> | |
| 14 } | |
| 15 | |
| 16 #include "base/values.h" | |
| 17 | |
| 18 namespace autox { | |
| 19 | |
| 20 // ScriptRunner reads a script and injects events into the X server using | |
| 21 // the XTEST extension. | |
| 22 class ScriptRunner { | |
| 23 public: | |
| 24 // Ownership of 'display' remains with the caller. | |
| 25 ScriptRunner(Display* display); | |
| 26 | |
| 27 // Run the passed-in script, which should be in JSON format as described | |
| 28 // in autox.cc's usage string. | |
| 29 void RunScript(const std::string& script); | |
| 30 | |
| 31 private: | |
| 32 // Update 'keysyms_to_keycodes_' with the X server's current keyboard | |
| 33 // mapping. | |
| 34 void LoadKeyboardMapping(); | |
| 35 | |
| 36 // Given an ASCII character, find the keysym that represents it. Returns | |
| 37 // true on success. | |
| 38 bool ConvertCharToKeySym(char ch, KeySym* keysym_out); | |
| 39 | |
| 40 // Returns true if shift needs to be held for the passed-in keysym to be | |
| 41 // entered. | |
| 42 bool KeySymRequiresShift(KeySym keysym); | |
| 43 | |
| 44 // Get the keycode corresponding to the passed-in keysym (per | |
| 45 // 'keysyms_to_keycodes_'), or 0 if no keycode maps to it. | |
| 46 KeyCode GetKeyCodeForKeySym(KeySym keysym); | |
| 47 | |
| 48 // Handle "button_down" and "button_up" commands. 'values' is the | |
| 49 // complete list consisting of the command name followed by X and Y | |
| 50 // integer arguments. | |
| 51 void HandleButtonCommand(int command_num, | |
| 52 const ListValue& values, | |
| 53 bool button_down); | |
| 54 | |
| 55 // Handle "hotkey" commands. 'values' is the command name and a string | |
| 56 // consisting of a sequence of keysyms to be pressed at the same time, | |
| 57 // joined by dashes. "Ctrl", "Alt", and "Shift" can also be used. | |
| 58 // "Ctrl-Alt-Tab" will type Tab while Control and Alt are held, for | |
| 59 // instance. | |
| 60 void HandleHotkeyCommand(int command_num, const ListValue& values); | |
| 61 | |
| 62 // Handle "key_down" and "key_up" commands. 'values' consists of the | |
| 63 // command name followed by a keysym name. The keysym must be | |
| 64 // produceable without holding the Shift key. | |
| 65 void HandleKeyCommand(int command_num, | |
| 66 const ListValue& values, | |
| 67 bool key_down); | |
| 68 | |
| 69 // Handle "motion" and "motion_relative" commands. 'values' consists of | |
| 70 // the command name followed by X and Y integer arguments, which are | |
| 71 // interpreted as either absolute or relative coordinates depending on | |
| 72 // 'absolute'. | |
| 73 void HandleMotionCommand(int command_num, | |
| 74 const ListValue& values, | |
| 75 bool absolute); | |
| 76 | |
| 77 // Handle "sleep" commands. 'values' consists of the command name | |
| 78 // followed by the number of milliseconds to sleep. | |
| 79 void HandleSleepCommand(int command_num, const ListValue& values); | |
| 80 | |
| 81 // Handle "string" commands. 'values' consists of the command name | |
| 82 // followed by a string containing the characters that should be typed. | |
| 83 // Keysym names may be embedded in the string, e.g. "\\(Control_L)". | |
| 84 void HandleStringCommand(int command_num, const ListValue& values); | |
| 85 | |
| 86 Display* display_; // not owned | |
| 87 | |
| 88 // Map from non-alphanumeric characters to their keysyms. | |
| 89 // Used by ConvertCharToKeySym(). | |
| 90 std::map<char, KeySym> chars_to_keysyms_; | |
| 91 | |
| 92 // Map from keysym to the keycode that is used to produce it and whether | |
| 93 // the Shift key needs to be pressed. | |
| 94 std::map<KeySym, std::pair<KeyCode, bool> > keysyms_to_keycodes_; | |
| 95 }; | |
| 96 | |
| 97 } // namespace autox | |
| 98 | |
| 99 #endif // AUTOX_SCRIPT_RUNNER_H_ | |
| OLD | NEW |