Methods Summary |
---|
private static boolean | byteMatch(byte[] a, byte[] b)Checks if two byte arrays match.
if (a.length != b.length)
return false;
int len = a.length;
for (int i = 0; i < len; i++) {
if (a[i] != b[i])
return false;
}
return true;
|
public byte[] | captureScreen()Capture the current contents of the physical display in the form of a
byte array. The byte array may be some reduced form of the display, such
as a checksum or hash, but must be guaranteed unique for the display
such that no two differing displays will have the same return value
byte x[] = (ScreenGrabber.getInstance()).getData();
return x;
|
void | commandEvent(int type)Process a command event
if (recordingInProgress) {
int time = (int)(System.currentTimeMillis() - this.millis);
RecordedEvent event = new RecordedEvent(time, type);
eventSequence.appendEvent(event);
// set the clock
this.millis = System.currentTimeMillis();
}
super.commandEvent(type);
|
public static AutomationHandler | getAutomationHandler()
return thisReference;
|
private void | initializeEventSequence()Initialize the event sequence for recording.
Currently, this allocates a new EventSequence
eventSequence = new EventSequence();
|
void | keyEvent(int type, java.lang.String str, int code)Process a key event
// we have a key event
// do we need to take a hot key action on this?
if (type == 1 && // key press
(code == hotKey_StartRecording ||
code == hotKey_StopRecording ||
code == hotKey_CaptureScreen)) {
// process the hot key
if (code == hotKey_StartRecording) {
startEventSequence();
}
if (code == hotKey_StopRecording) {
stopEventSequence();
// note : this method also performs a screen capture
// does this have any implications?
if (sequenceHandler != null) {
sequenceHandler.handleEventSequence(eventSequence);
}
}
if (code == hotKey_CaptureScreen) {
byte s_cap[] = captureScreen();
if (sequenceHandler != null) {
sequenceHandler.handleScreenCapture(s_cap);
}
}
} else {
if (recordingInProgress) {
if (type == IME) {
int time = (int)(System.currentTimeMillis() - this.millis);
// this is an input method event
RecordedEvent event = new RecordedEvent(time, str);
eventSequence.appendEvent(event);
// set the clock
this.millis = System.currentTimeMillis();
} else {
int time = (int)(System.currentTimeMillis() - this.millis);
// this is a KEY_EVENT
RecordedEvent event = new RecordedEvent(time, type, code);
eventSequence.appendEvent(event);
// set the clock
this.millis = System.currentTimeMillis();
}
}
}
super.keyEvent(type, str, code);
|
void | pointerEvent(int type, int x, int y)Process a pointer event
if (recordingInProgress) {
int time = (int)(System.currentTimeMillis() - this.millis);
RecordedEvent event = new RecordedEvent(time, type, x, y);
eventSequence.appendEvent(event);
// set the clock
this.millis = System.currentTimeMillis();
}
super.pointerEvent(type, x, y);
|
public void | registerHotKey(int action, int keyCode)Establish a specific key code for the given action to serve as
a 'hotkey'. The action must be one of START_RECORDING, STOP_RECORDING,
or CAPTURE_SCREEN.
switch (action) {
case START_RECORDING :
hotKey_StartRecording = keyCode;
break;
case STOP_RECORDING :
hotKey_StopRecording = keyCode;
break;
case CAPTURE_SCREEN :
hotKey_CaptureScreen = keyCode;
break;
}
|
public void | registerSequenceHandler(SequenceHandler handler)Establish a SequenceHandler to handle the completion of EventSequences.
and screen captures which occur as a result of a 'hotkey' press.
If a sequence handler is set, that handler will be called when any
event sequence is completed, either as a result of stopEventSequence()
being called, or as a result of some "hot key" being pressed which
the event handler recognizes as a signal to stop event recording.
The EventSequence object passed to the handler will be the same as
the return result of the stopEventSequence() method. If a handler has
already been set, and this method is called again the old handler will
be discarded and the new handler will be used. If 'null' is passed,
any previous handler will be discarded.
sequenceHandler = handler;
|
public boolean | replayEventSequence(EventSequence sequence)Replay a given event sequence. This will replay a sequence of
events represented in the given EventSequence object. It will
then capture the contents of the screen at the end of the event
sequence and compare it to the screen capture that is included
in the EventSequence object.
// NOTE: Do we check if an event sequence is currently being recorded
// replayed, before starting replay?
sequence.initializeReplay();
EventPlaybackThread eventPlaybackThread
= new EventPlaybackThread(sequence, 100);
eventPlaybackThread.start();
// hang around until replay is finished.
synchronized (thisReference) {
try {
thisReference.wait();
} catch (InterruptedException e) {
// ERROR!
e.printStackTrace();
}
}
return lastScreenCaptureComparisonTrue;
|
public boolean | replayEventSequence(EventSequence sequence, int speed)Replay a given event sequence. This will replay a sequence of
events represented in the given EventSequence object. It will
then capture the contents of the screen at the end of the event
sequence and compare it to the screen capture that is included
in the EventSequence object.
// NOTE: Do we check if an event sequence is currently being recorded/
// replayed, before starting replay?
sequence.initializeReplay();
EventPlaybackThread eventPlaybackThread
= new EventPlaybackThread(sequence, speed);
eventPlaybackThread.start();
// hang around until replay is finished.
synchronized (thisReference) {
try {
thisReference.wait();
} catch (InterruptedException e) {
// ERROR!
e.printStackTrace();
}
}
return lastScreenCaptureComparisonTrue;
|
public void | startEventSequence()Start recording an event sequence. Any event sequence currently
being recorded will be destroyed and a new event sequence will
be started.
initializeEventSequence();
recordingInProgress = true;
// set the clock
this.millis = System.currentTimeMillis();
|
public EventSequence | stopEventSequence()Stop recording an event sequence. This will stop recording the
current event sequence and capture the current contents of the
screen. It will then return an EventSequence object which is
the representation of the entire event sequence as well as the
screen capture resulting at the end of the sequence. If no events
occurred during the capture, the sequence will simply be a timed
delay with a screen capture. The timed delay will be the time delay
between the call to startEventSequence() and stopEventSequence().
If stopEventSequence() is called without previously calling
startEventSequence(), an EventSequence will be returned which is
essentially "empty" and only contains the current contents of
the captured screen.
if (recordingInProgress != true) {
// If stopEventSequence() is called without previously
// calling startEventSequence(), an EventSequence
// will be returned which is essentially "empty"
initializeEventSequence();
}
int time = (int)(System.currentTimeMillis() - this.millis);
// this is a delay event
RecordedEvent event = new RecordedEvent(time);
eventSequence.appendEvent(event);
// no need to set the clock
// we won't we using it in recording anymore
recordingInProgress = false;
// append screen capture to event sequence
byte[] s_cap = (ScreenGrabber.getInstance()).getData();
eventSequence.setScreenCapture(s_cap);
return eventSequence;
|
public EventSequence | updateScreenForSequence(EventSequence sequence)Update the screen capture for this event sequence. Over time, the
screen captures in a stored event sequence may become out of date.
Calling this method will run the given event sequence, capture
the resulting screen, and return the same EventSequence object
with the updated screen value.
return eventSequence;
|