-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActionManager_edit.cs
214 lines (175 loc) · 6.63 KB
/
ActionManager_edit.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
using System;
using System.Windows.Forms;
using InputManager;
namespace WiiBalanceWalker
{
/// <summary>Actions place holders as controls are passed after they load.</summary>
public class ActionList
{
public ActionItem Left;
public ActionItem Right;
public ActionItem Forward;
public ActionItem Backward;
public ActionItem Modifier;
public ActionItem Jump;
public ActionItem DiagonalLeft;
public ActionItem DiagonalRight;
}
/// <summary>Abstracts away selecting, saving, and sending multiple input types.</summary>
public class ActionItem
{
public bool IsActive { get; private set; }
string settingName;
string inputText;
int inputAmount;
int inputType;
Keys inputKeys;
Mouse.MouseKeys inputMouseKeys;
System.Timers.Timer inputTimer = new System.Timers.Timer() { Interval = 2, Enabled = false };
public ActionItem(string settingName, ComboBox controlType, NumericUpDown controlAmount)
{
// The name where the action should be saved.
this.settingName = settingName;
// Track changes to the controls.
controlType.SelectedIndexChanged += new EventHandler(ControlType_SelectedIndexChanged);
controlAmount.ValueChanged += new EventHandler(ControlAmount_ValueChanged);
// Add nothing and mouse movement options to control.
controlType.Items.Add(new ItemWithText("", "Do Nothing"));
controlType.Items.Add(new ItemWithText("MouseMoveX", "Mouse Move X"));
controlType.Items.Add(new ItemWithText("MouseMoveY", "Mouse Move Y"));
// Add mouse button options to control.
foreach (Mouse.MouseKeys item in Enum.GetValues(typeof(Mouse.MouseKeys)))
{
controlType.Items.Add(new ItemWithText(item, "Mouse Hold " + item));
}
// Add keyboard options to control.
foreach (Keys item in Enum.GetValues(typeof(Keys)))
{
controlType.Items.Add(new ItemWithText(item, "Key " + item));
}
// Get the last known settings.
inputText = (string)Properties.Settings.Default["Action" + settingName];
inputAmount = (int)Properties.Settings.Default["Amount" + settingName];
// Put the controls to the last known settings.
controlType.Text = inputText;
controlAmount.Value = inputAmount;
inputTimer.Elapsed += new System.Timers.ElapsedEventHandler(inputTimer_Elapsed);
}
public void ControlType_SelectedIndexChanged(object sender, EventArgs e)
{
// Convert control generic object back into item.
var itemWithText = (ItemWithText)((ComboBox)sender).SelectedItem;
var itemTypeName = itemWithText.Item.GetType().Name;
// Set the active item.
if (itemTypeName == "Keys")
{
inputKeys = (Keys)itemWithText.Item;
inputType = 1;
}
else if (itemTypeName == "MouseKeys")
{
inputType = 2;
inputMouseKeys = (Mouse.MouseKeys)itemWithText.Item;
}
else if (itemTypeName == "String")
{
var itemText = (String)itemWithText.Item;
if (itemText == "") inputType = 0;
else if (itemText == "MouseMoveX") inputType = 3;
else if (itemText == "MouseMoveY") inputType = 4;
}
// Remember settings.
inputText = ((ComboBox)sender).Text;
Save();
}
public void ControlAmount_ValueChanged(object sender, EventArgs e)
{
// Convert control decimal to integer and remember setting.
inputAmount = (int)((NumericUpDown)sender).Value;
Save();
}
public void changeAmount(int amount)
{
inputAmount = amount;
}
void inputTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
switch (inputType)
{
case 3:
Mouse.MoveRelative(inputAmount, 0);
break;
case 4:
Mouse.MoveRelative(0, inputAmount);
break;
}
}
public void Start()
{
// Keyboard Keys and Mouse buttons need only to signal down then up to hold.
// Mouse movement is incremental jumps so needs a faster repeating timer for smooth movement.
if (this.IsActive) return;
this.IsActive = true;
switch (inputType)
{
case 0:
return;
case 1:
Keyboard.KeyDown(inputKeys);
break;
case 2:
Mouse.ButtonDown(inputMouseKeys);
break;
case 3:
inputTimer.Enabled = true;
break;
case 4:
inputTimer.Enabled = true;
break;
}
}
public void Stop()
{
if (!this.IsActive) return;
this.IsActive = false;
switch (inputType)
{
case 0:
return;
case 1:
Keyboard.KeyUp(inputKeys);
break;
case 2:
Mouse.ButtonUp(inputMouseKeys);
break;
case 3:
inputTimer.Enabled = false;
break;
case 4:
inputTimer.Enabled = false;
break;
}
}
public void Save()
{
Properties.Settings.Default["Action" + settingName] = inputText;
Properties.Settings.Default["Amount" + settingName] = inputAmount;
Properties.Settings.Default.Save();
}
}
/// <summary>Used to store objects with custom text as a control item.</summary>
public class ItemWithText
{
public object Item { get; private set; }
public string Text { get; private set; }
public ItemWithText(object item, string text)
{
this.Item = item;
this.Text = text;
}
public override string ToString()
{
return this.Text;
}
}
}