-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathKeyboard.cs
151 lines (139 loc) · 4.94 KB
/
Keyboard.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
//#define DISABLE_KEYBOARD_CONTROL
using System.Windows.Forms;
namespace MainForm
{
public partial class MainForm
{
/// <summary>
/// 鍵盤控制。
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MainForm_KeyDown(object sender, KeyEventArgs e)
{
#if (!DISABLE_KEYBOARD_CONTROL)
switch (e.KeyCode)
{
// F1: 選擇 J1/X 數字欄。
case Keys.F1:
if (TargetPosition[0].Focused)
{
TargetPosition[0].ResetText();
}
else
{
TargetPosition[0].Focus();
}
break;
// F2: 選擇 J2/Y 數字欄。
case Keys.F2:
if (TargetPosition[1].Focused)
{
TargetPosition[1].ResetText();
}
else
{
TargetPosition[1].Focus();
}
break;
// F3: 選擇 J3/Z 數字欄。
case Keys.F3:
if (TargetPosition[2].Focused)
{
TargetPosition[2].ResetText();
}
else
{
TargetPosition[2].Focus();
}
break;
// F4: 執行「進行動作」。
case Keys.F4:
button_arm_motion_start.PerformClick();
break;
// F5: 更新目前位置。
case Keys.F5:
UpdateNowPosition();
break;
// F6: 執行「複製目前位置到目標位置/歸零目標位置」。
case Keys.F6:
button_arm_copy_position_from_now_to_target.PerformClick();
break;
// PageUp: 增加數值。
case Keys.PageUp:
for (int i = 0; i < TargetPosition.Count; i++)
{
if (TargetPosition[i].Focused)
{
decimal value;
if (!e.Control && e.Shift && !e.Alt)
{
value = 1;
}
else if (!e.Control && !e.Shift && e.Alt)
{
value = (decimal)0.1;
}
else if (!e.Control && e.Shift && e.Alt)
{
value = (decimal)0.05;
}
else
{
value = 10;
}
TargetPosition[i].Value += value;
break;
}
}
break;
// PageDown: 減少數值。
case Keys.PageDown:
for (int i = 0; i < TargetPosition.Count; i++)
{
if (TargetPosition[i].Focused)
{
decimal value;
if (!e.Control && e.Shift && !e.Alt)
{
value = 1;
}
else if (!e.Control && !e.Shift && e.Alt)
{
value = (decimal)0.1;
}
else if (!e.Control && e.Shift && e.Alt)
{
value = (decimal)0.05;
}
else
{
value = 10;
}
TargetPosition[i].Value -= value;
break;
}
}
break;
// Home: 執行「手臂回到原點」。
case Keys.Home:
button_arm_homing.PerformClick();
break;
// End: 執行「連線或斷線」。
case Keys.End:
if (Arm.Connected)
{
button_disconnect.PerformClick();
}
else
{
button_connect.PerformClick();
}
break;
default:
break;
}
#endif // (!DISABLE_KEYBOARD_CONTROL)
}
}
}