Добавлен режим Android TouchPad

This commit is contained in:
Victor 2014-03-05 17:02:44 +02:00
parent d31a7c4446
commit 76a7955ae1

View File

@ -29,6 +29,7 @@ public class CursorOperation extends Operation {
TYPE_DRAG = 3,
TYPE_RELEASED = 4,
TYPE_KEY_RELEASED = 5,
TYPE_MOVE_RELATIVE = 6,
STOP = 10;
private RobotUtils robot;
@ -44,16 +45,21 @@ public class CursorOperation extends Operation {
@Override
public void startServerSide() throws IOException {
int type = NONE;
// Ñ÷èòûâàåì ðàçìåðû ýêðàíà, ÷òîáû íîðìàëüíî
// ïåðåìåùàòü êóðñîð ïðè íåñîâïàäåíèè ðàçðåøåíèé.
int width = dis.readInt();
int height = dis.readInt();
if (width == height && width == -100) {
androidTouchPadMode();
return;
}
// Ðàñ÷åò ïðèðàùåíèé.
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
double dx = screenSize.getWidth() / (double) width;
double dy = screenSize.getHeight() / (double) height;
int type = NONE;
do {
type = dis.readInt();
if (type == TYPE_MOVE) {
@ -77,6 +83,26 @@ public class CursorOperation extends Operation {
} while (type != STOP);
}
private void androidTouchPadMode() throws IOException {
int type = NONE;
do {
type = dis.readInt();
if (type == TYPE_CLICK) {
int button = dis.readInt();
robot.clickPoint(robot.getCursorPosition(), button);
} else if (type == TYPE_KEY_RELEASED) {
int key = dis.readInt();
robot.pressKey(key);
} else if (type == TYPE_MOVE_RELATIVE) {
int x = (int) (dis.readInt());
int y = (int) (dis.readInt());
robot.moveCursorRelative(x, y);
} else if (type == TYPE_RELEASED) {
robot.getRobot().mouseRelease(InputEvent.BUTTON1_MASK);
}
} while (type != STOP);
}
@Override
public void startClientSide(Object... params) throws Exception {
// Ñîçäàíèå äèàëîãà äëÿ ïðîñëóøèâàíèÿ ñîáûòèé.