-
Notifications
You must be signed in to change notification settings - Fork 0
/
KeyUtil.cs
68 lines (65 loc) · 2.23 KB
/
KeyUtil.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
using System;
using System.Windows.Input;
namespace Autoclicker {
internal class KeyUtil {
public static string ConvertKeyToString(Key key) {
switch (key) {
case Key.Oem1:
return "SemiColon";
case Key.Oem3:
// The ` symbol
return "Acute";
case Key.Oem5:
return "Backslash";
case Key.Oem6:
return "CloseSquareBracket";
case Key.OemMinus:
return "Minus";
case Key.OemPlus:
return "Plus";
case Key.OemOpenBrackets:
return "OpenSquareBracket";
case Key.OemQuotes:
return "Quote";
case Key.OemComma:
return "Comma";
case Key.OemPeriod:
return "Period";
case Key.OemQuestion:
return "ForwardSlash";
default:
return key.ToString();
}
}
public static Key ConvertStringToKey(string keyString) {
switch (keyString) {
case "SemiColon":
return Key.Oem1;
case "Acute":
// The ` symbol
return Key.Oem3;
case "Backslash":
return Key.Oem5;
case "CloseSquareBracket":
return Key.Oem6;
case "Minus":
return Key.OemMinus;
case "Plus":
return Key.OemPlus;
case "OpenSquareBracket":
return Key.OemOpenBrackets;
case "Quote":
return Key.OemQuotes;
case "Comma":
return Key.OemComma;
case "Period":
return Key.OemPeriod;
case "ForwardSlash":
return Key.OemQuestion;
default:
bool parseResult = Enum.TryParse(keyString, out Key parseKey);
return parseResult ? parseKey : Key.None;
}
}
}
}