-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
99 lines (85 loc) · 2.76 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using System;
using System.Windows.Forms;
using MouseRecorder.Interfaces;
using System.Threading;
namespace MouseRecorder
{
public partial class Form1 : Form
{
private bool isRecording = false;
private RecorderData recorderData;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
recorderData = new RecorderData();
recorderData.OnNewData += AddData;
}
private void buttonRecord_Click(object sender, EventArgs e)
{
Recording();
}
private void Recording()
{
if (!isRecording)
{
//Start record mouse/keyboard
//TODO CALL DATA EMPTHY
timelineView.Items.Clear();
if (checkBoxKeyboard.Checked) recorderData.StartKeyboardRecord();
if (checkBoxMouseClick.Checked) recorderData.StartMouseRecord();
buttonRecord.Text = "Stop record";
}
else
{
//Stop record mouse/keyboard
recorderData.StopKeyboardRecord();
recorderData.StopMouseRecord();
buttonRecord.Text = "Record";
}
isRecording = !isRecording;
}
private void AddData(HookData data)
{
if (data is MouseData)
{
timelineView.Items.Add(new ListViewItem(new string[] {
"Mouse",
(data as MouseData).mouse.ToString(),
"X: " + (data as MouseData).point.x + " Y: "+ (data as MouseData).point.y
}));
} else if (data is KeyboardData)
{
timelineView.Items.Add(new ListViewItem(new string[] { "Keyboard", "Up", (data as KeyboardData).keyboard.ToString() }));
}
//Set items scroll to bottom
timelineView.Items[timelineView.Items.Count - 1].EnsureVisible();
}
private void buttonPlay_Click(object sender, EventArgs e)
{
PlayRecorder();
}
public void PlayRecorder()
{
if (isRecording)
{
//Stop first recording
Recording();
}
foreach (HookData data in recorderData.data)
{
if (data is MouseData)
{
MouseRecorder.Events.PlayEvent.PlayMouse(data as MouseData);
}
else if (data is KeyboardData)
{
MouseRecorder.Events.PlayEvent.PlayKeyboard(data as KeyboardData);
}
Thread.Sleep(100);
}
}
}
}