1
// Copyright (c) 2011 The Chromium 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.
5
#ifndef BASE_EVENT_RECORDER_H_
6
#define BASE_EVENT_RECORDER_H_
8
#include "base/base_export.h"
9
#include "base/basictypes.h"
10
#include "build/build_config.h"
22
// A class for recording and playing back keyboard and mouse input events.
24
// Note - if you record events, and the playback with the windows in
25
// different sizes or positions, the playback will fail. When
26
// recording and playing, you should move the relevant windows
27
// to constant sizes and locations.
28
// TODO(mbelshe) For now this is a singleton. I believe that this class
29
// could be easily modified to:
30
// support two simultaneous recorders
31
// be playing back events while already recording events.
32
// Why? Imagine if the product had a "record a macro" feature.
33
// You might be recording globally, while recording or playing back
34
// a macro. I don't think two playbacks make sense.
35
class BASE_EXPORT EventRecorder {
37
// Get the singleton EventRecorder.
38
// We can only handle one recorder/player at a time.
39
static EventRecorder* current() {
41
current_ = new EventRecorder();
45
// Starts recording events.
46
// Will clobber the file if it already exists.
47
// Returns true on success, or false if an error occurred.
48
bool StartRecording(const FilePath& filename);
53
// Is the EventRecorder currently recording.
54
bool is_recording() const { return is_recording_; }
56
// Plays events previously recorded.
57
// Returns true on success, or false if an error occurred.
58
bool StartPlayback(const FilePath& filename);
63
// Is the EventRecorder currently playing.
64
bool is_playing() const { return is_playing_; }
67
// C-style callbacks for the EventRecorder.
68
// Used for internal purposes only.
69
LRESULT RecordWndProc(int nCode, WPARAM wParam, LPARAM lParam);
70
LRESULT PlaybackWndProc(int nCode, WPARAM wParam, LPARAM lParam);
74
// Create a new EventRecorder. Events are saved to the file filename.
75
// If the file already exists, it will be deleted before recording
78
: is_recording_(false),
84
playback_first_msg_time_(0),
85
playback_start_time_(0) {
87
memset(&playback_msg_, 0, sizeof(playback_msg_));
92
static EventRecorder* current_; // Our singleton.
99
EVENTMSG playback_msg_;
101
int playback_first_msg_time_;
102
int playback_start_time_;
104
DISALLOW_COPY_AND_ASSIGN(EventRecorder);
109
#endif // BASE_EVENT_RECORDER_H_