-
Notifications
You must be signed in to change notification settings - Fork 527
Expand file tree
/
Copy pathReplaceKey.cs
More file actions
123 lines (116 loc) · 3.77 KB
/
ReplaceKey.cs
File metadata and controls
123 lines (116 loc) · 3.77 KB
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
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace Carnac.Logic
{
public static class ReplaceKey
{
static readonly Dictionary<Keys, string> ShiftReplacements = new Dictionary<Keys, string>
{
{Keys.D0, ")"},
{Keys.D1, "!"},
{Keys.D2, "@"},
{Keys.D3, "#"},
{Keys.D4, "$"},
{Keys.D5, "%"},
{Keys.D6, "^"},
{Keys.D7, "&"},
{Keys.D8, "*"},
{Keys.D9, "("},
{Keys.OemOpenBrackets, "{"},
{Keys.Oem6, "}"},
{Keys.OemMinus, "_"},
{Keys.Oemplus, "+"},
{Keys.OemBackslash, "|"},
{Keys.Oem5, "|"},
{Keys.OemQuestion, "?"},
{Keys.OemPeriod, ">"},
{Keys.Oemcomma, "<"},
{Keys.Oem1, ":"},
{Keys.Oem7, "\""},
{Keys.Oemtilde, "~"},
{Keys.Insert, "ins"},
{Keys.Delete, "del"}
};
static readonly Dictionary<Keys, string> Replacements = new Dictionary<Keys, string>
{
{Keys.Space, " "},
{Keys.D0, "0"},
{Keys.D1, "1"},
{Keys.D2, "2"},
{Keys.D3, "3"},
{Keys.D4, "4"},
{Keys.D5, "5"},
{Keys.D6, "6"},
{Keys.D7, "7"},
{Keys.D8, "8"},
{Keys.D9, "9"},
{Keys.NumPad0, "0"},
{Keys.NumPad1, "1"},
{Keys.NumPad2, "2"},
{Keys.NumPad3, "3"},
{Keys.NumPad4, "4"},
{Keys.NumPad5, "5"},
{Keys.NumPad6, "6"},
{Keys.NumPad7, "7"},
{Keys.NumPad8, "8"},
{Keys.NumPad9, "9"},
{Keys.OemOpenBrackets, "["},
{Keys.Oem6, "]"},
{Keys.OemMinus, "-"},
{Keys.Oemplus, "="},
{Keys.Oem5, "\\"},
{Keys.OemBackslash, "\\"},
{Keys.OemQuestion, "/"},
{Keys.OemPeriod, "."},
{Keys.Oemcomma, ","},
{Keys.Oem1, ";"},
{Keys.Oem7, "'"},
{Keys.Oemtilde, "`"},
{Keys.Decimal, "."},
{Keys.Divide, " / "},
{Keys.Multiply, " * "},
{Keys.Subtract, " - "},
{Keys.Add, " + "},
{Keys.LShiftKey, "Shift"},
{Keys.RShiftKey, "Shift"},
{Keys.LWin, "Win"},
{Keys.RWin, "Win"},
{Keys.LControlKey, "Ctrl"},
{Keys.RControlKey, "Ctrl"},
{Keys.Alt, "Alt"},
{Keys.LMenu, "Alt"},
};
public static Keys? ToKey(string keyText)
{
foreach (var shiftReplacement in ShiftReplacements)
{
if (shiftReplacement.Value.Equals(keyText, StringComparison.CurrentCultureIgnoreCase))
return shiftReplacement.Key;
}
Keys parsedKey;
if (Enum.TryParse(keyText, true, out parsedKey))
return parsedKey;
foreach (var replacement in Replacements)
{
if (replacement.Value.Equals(keyText, StringComparison.CurrentCultureIgnoreCase))
return replacement.Key;
}
return null;
}
public static string Sanitise(this Keys key)
{
return Replacements.ContainsKey(key) ? Replacements[key] : string.Format(key.ToString());
}
public static bool SanitiseShift(this Keys key, out string sanitisedKeyInput)
{
if (ShiftReplacements.ContainsKey(key))
{
sanitisedKeyInput = ShiftReplacements[key];
return true;
}
sanitisedKeyInput = key.Sanitise();
return false;
}
}
}