| 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 #include <cstdio> | |
| 6 #include <string> | |
| 7 | |
| 8 extern "C" { | |
| 9 #include <X11/Xlib.h> | |
| 10 } | |
| 11 | |
| 12 #include "autox/script_runner.h" | |
| 13 #include "base/file_path.h" | |
| 14 #include "base/file_util.h" | |
| 15 #include "base/logging.h" | |
| 16 | |
| 17 using std::string; | |
| 18 | |
| 19 | |
| 20 const static char* kUsage = | |
| 21 "Usage: autox SCRIPT-FILE\n" | |
| 22 "\n" | |
| 23 "SCRIPT-FILE is a JSON file (with trailing commas allowed) consisting\n" | |
| 24 "of a list of input events that should be injected into the X server\n" | |
| 25 "using the XTEST extension. Each event is described by a list containing\n" | |
| 26 "the following:\n" | |
| 27 "\n" | |
| 28 " COMMAND, ARG1, ARG2, ...\n" | |
| 29 "\n" | |
| 30 "The following commands are available:\n" | |
| 31 "\n" | |
| 32 " button_down, BUTTON - mouse button press for given button\n" | |
| 33 " button_up, BUTTON - mouse button release for given button\n" | |
| 34 " hotkey, TEXT - hotkey combo (e.g. \"Ctrl-Alt-Tab\")\n" | |
| 35 " key_down, KEYSYM - key press for named keysym (e.g. from xev)\n" | |
| 36 " key_up, KEYSYM - key release for named keysym\n" | |
| 37 " motion, X, Y - mouse motion to absolute coordinates\n" | |
| 38 " motion_relative, X, Y - mouse motion relative to current position\n" | |
| 39 " sleep, TIME_MS - sleep for given number of milliseconds\n" | |
| 40 " string, TEXT - ASCII characters (keysyms may be also\n" | |
| 41 " be included, e.g. \"\\(Control_L)\")\n" | |
| 42 "\n" | |
| 43 "The following is a valid script file:\n" | |
| 44 "\n" | |
| 45 " { \"script\": [\n" | |
| 46 " [ \"motion\", 10, 20 ],\n" | |
| 47 " [ \"button_down\", 1 ],\n" | |
| 48 " [ \"motion_relative\", 500, 20 ],\n" | |
| 49 " [ \"button_up\", 1 ],\n" | |
| 50 " [ \"sleep\", 500 ],\n" | |
| 51 " [ \"string\", \"one line\\nand a second line\\\\(Return)\" ],\n" | |
| 52 " [ \"key_down\", \"Alt_L\" ],\n" | |
| 53 " [ \"key_down\", \"Tab\" ],\n" | |
| 54 " [ \"key_up\", \"Tab\" ],\n" | |
| 55 " [ \"key_up\", \"Alt_L\" ],\n" | |
| 56 " [ \"hotkey\", \"Alt-Tab\" ], // faster\n" | |
| 57 " ],\n" | |
| 58 " }\n"; | |
| 59 | |
| 60 int main(int argc, char** argv) { | |
| 61 if (argc != 2 || argv[1][0] == '-') { | |
| 62 fprintf(stderr, "%s", kUsage); | |
| 63 return 1; | |
| 64 } | |
| 65 | |
| 66 FilePath script_path = FilePath(argv[1]); | |
| 67 string script; | |
| 68 CHECK(file_util::ReadFileToString(script_path, &script)) | |
| 69 << "Unable to read script file \"" << script_path.value() << "\""; | |
| 70 Display* display = XOpenDisplay(NULL); | |
| 71 CHECK(display) << "Couldn't open connection to X server"; | |
| 72 | |
| 73 autox::ScriptRunner script_runner(display); | |
| 74 script_runner.RunScript(script); | |
| 75 | |
| 76 XCloseDisplay(display); | |
| 77 return 0; | |
| 78 } | |
| OLD | NEW |