/* * Copyright (C) 2007 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.commands.input; import android.hardware.input.InputManager; import android.os.SystemClock; import android.util.Log; import android.view.InputDevice; import android.view.KeyCharacterMap; import android.view.KeyEvent; import android.view.MotionEvent; /** * Command that sends key events to the device, either by their keycode, or by * desired character output. */ public class Input { private static final String TAG = "Input"; /** * Command-line entry point. * * @param args The command-line arguments */ public static void main(String[] args) { (new Input()).run(args); } private void run(String[] args) { if (args.length < 1) { showUsage(); return; } String command = args[0]; try { if (command.equals("text")) { if (args.length == 2) { sendText(args[1]); return; } } else if (command.equals("keyevent")) { if (args.length == 2) { int keyCode = KeyEvent.keyCodeFromString(args[1]); if (keyCode == KeyEvent.KEYCODE_UNKNOWN) { keyCode = KeyEvent.keyCodeFromString("KEYCODE_" + args[1]); } sendKeyEvent(keyCode); return; } } else if (command.equals("tap")) { if (args.length == 3) { sendTap(InputDevice.SOURCE_TOUCHSCREEN, Float.parseFloat(args[1]), Float.parseFloat(args[2])); return; } } else if (command.equals("swipe")) { if (args.length == 5) { sendSwipe(InputDevice.SOURCE_TOUCHSCREEN, Float.parseFloat(args[1]), Float.parseFloat(args[2]), Float.parseFloat(args[3]), Float.parseFloat(args[4]), -1); return; } } else if (command.equals("touchscreen") || command.equals("touchpad") || command.equals("touchnavigation")) { // determine input source int inputSource = InputDevice.SOURCE_TOUCHSCREEN; if (command.equals("touchpad")) { inputSource = InputDevice.SOURCE_TOUCHPAD; } else if (command.equals("touchnavigation")) { inputSource = InputDevice.SOURCE_TOUCH_NAVIGATION; } // determine subcommand if (args.length > 1) { String subcommand = args[1]; if (subcommand.equals("tap")) { if (args.length == 4) { sendTap(inputSource, Float.parseFloat(args[2]), Float.parseFloat(args[3])); return; } } else if (subcommand.equals("swipe")) { if (args.length == 6) { sendSwipe(inputSource, Float.parseFloat(args[2]), Float.parseFloat(args[3]), Float.parseFloat(args[4]), Float.parseFloat(args[5]), -1); return; } else if (args.length == 7) { sendSwipe(inputSource, Float.parseFloat(args[2]), Float.parseFloat(args[3]), Float.parseFloat(args[4]), Float.parseFloat(args[5]), Integer.parseInt(args[6])); return; } } } } else if (command.equals("trackball")) { // determine subcommand if (args.length > 1) { String subcommand = args[1]; if (subcommand.equals("press")) { sendTap(InputDevice.SOURCE_TRACKBALL, 0.0f, 0.0f); return; } else if (subcommand.equals("roll")) { if (args.length == 4) { sendMove(InputDevice.SOURCE_TRACKBALL, Float.parseFloat(args[2]), Float.parseFloat(args[3])); return; } } } } else { System.err.println("Error: Unknown command: " + command); showUsage(); return; } } catch (NumberFormatException ex) { } System.err.println("Error: Invalid arguments for command: " + command); showUsage(); } /** * Convert the characters of string text into key event's and send to * device. * * @param text is a string of characters you want to input to the device. */ private void sendText(String text) { StringBuffer buff = new StringBuffer(text); boolean escapeFlag = false; for (int i=0; i"); System.err.println(" input keyevent "); System.err.println(" input [touchscreen|touchpad|touchnavigation] tap "); System.err.println(" input [touchscreen|touchpad|touchnavigation] swipe " + " [duration(ms)]"); System.err.println(" input trackball press"); System.err.println(" input trackball roll "); } }