1 // Copyright (c) 2010 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_
12 #include "base/basictypes.h"
18 // A class for recording and playing back keyboard and mouse input events.
20 // Note - if you record events, and the playback with the windows in
21 // different sizes or positions, the playback will fail. When
22 // recording and playing, you should move the relevant windows
23 // to constant sizes and locations.
24 // TODO(mbelshe) For now this is a singleton. I believe that this class
25 // could be easily modified to:
26 // support two simultaneous recorders
27 // be playing back events while already recording events.
28 // Why? Imagine if the product had a "record a macro" feature.
29 // You might be recording globally, while recording or playing back
30 // a macro. I don't think two playbacks make sense.
33 // Get the singleton EventRecorder.
34 // We can only handle one recorder/player at a time.
35 static EventRecorder
* current() {
37 current_
= new EventRecorder();
41 // Starts recording events.
42 // Will clobber the file if it already exists.
43 // Returns true on success, or false if an error occurred.
44 bool StartRecording(const FilePath
& filename
);
49 // Is the EventRecorder currently recording.
50 bool is_recording() const { return is_recording_
; }
52 // Plays events previously recorded.
53 // Returns true on success, or false if an error occurred.
54 bool StartPlayback(const FilePath
& filename
);
59 // Is the EventRecorder currently playing.
60 bool is_playing() const { return is_playing_
; }
63 // C-style callbacks for the EventRecorder.
64 // Used for internal purposes only.
65 LRESULT
RecordWndProc(int nCode
, WPARAM wParam
, LPARAM lParam
);
66 LRESULT
PlaybackWndProc(int nCode
, WPARAM wParam
, LPARAM lParam
);
70 // Create a new EventRecorder. Events are saved to the file filename.
71 // If the file already exists, it will be deleted before recording
73 explicit EventRecorder()
74 : is_recording_(false),
80 playback_first_msg_time_(0),
81 playback_start_time_(0) {
85 static EventRecorder
* current_
; // Our singleton.
92 EVENTMSG playback_msg_
;
94 int playback_first_msg_time_
;
95 int playback_start_time_
;
97 DISALLOW_COPY_AND_ASSIGN(EventRecorder
);
102 #endif // BASE_EVENT_RECORDER_H_