Skip to content

Commit 9a2b40f

Browse files
committed
Add missing key, move version to strings, update icon tooltip
1 parent b703012 commit 9a2b40f

File tree

8 files changed

+49
-47
lines changed

8 files changed

+49
-47
lines changed

OpenVR2Key/App.config

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
<setting name="Haptic" serializeAs="String">
2323
<value>False</value>
2424
</setting>
25-
<setting name="Version" serializeAs="String">
26-
<value>v0.44</value>
27-
</setting>
2825
</OpenVR2Key.Properties.Settings>
2926
</userSettings>
3027
</configuration>

OpenVR2Key/MainModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ static public bool LoadSetting(Setting setting)
183183

184184
static public string GetVersion()
185185
{
186-
return (string) p["Version"];
186+
return (string)Properties.Resources.Version;
187187
}
188188
#endregion
189189

OpenVR2Key/MainUtils.cs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,16 @@ public static class MainUtils
3434
{ Key.OemMinus, VirtualKeyCode.OEM_MINUS},
3535
{ Key.OemPeriod, VirtualKeyCode.OEM_PERIOD},
3636
{ Key.OemPlus, VirtualKeyCode.OEM_PLUS},
37-
// Keys added [ = '
37+
/*
38+
* References for virtual key codes.
39+
* https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
40+
* https://sites.google.com/site/douglaslash/Home/programming/c-notes--snippets/c-keycodes
41+
* http://www.kbdedit.com/manual/low_level_vk_list.html
42+
*/
3843
{ Key.OemOpenBrackets, VirtualKeyCode.OEM_4},
3944
{ Key.OemQuestion, VirtualKeyCode.OEM_2},
40-
{ Key.OemQuotes, VirtualKeyCode.OEM_7}
41-
45+
{ Key.OemQuotes, VirtualKeyCode.OEM_7},
46+
{ Key.OemBackslash, VirtualKeyCode.OEM_102}
4247
};
4348

4449
/**
@@ -51,28 +56,34 @@ public static Tuple<VirtualKeyCode, bool> MatchVirtualKey(Key key)
5156

5257
// Check for direct translation
5358
if (translationTableKeys.ContainsKey(key))
59+
{
5460
return new Tuple<VirtualKeyCode, bool>(translationTableKeys[key], false);
61+
}
5562

5663
// Check for translation as modifier key
5764
if (translationTableModifiers.ContainsKey(key))
65+
{
5866
return new Tuple<VirtualKeyCode, bool>(translationTableModifiers[key], true);
59-
60-
61-
// Check for translation using some rules based on how GregsStack names the keys
62-
// Looks related to this info: http://www.kbdedit.com/manual/low_level_vk_list.html
67+
}
6368

6469
// Character keys which come in as A-Z
6570
if (keyStr.Length == 1) keyStr = $"VK_{keyStr}";
6671

6772
// Number keys which come in as D0-D9
68-
else if (keyStr.Length == 2 && keyStr[0] == 'D' && Char.IsDigit(keyStr[1])) keyStr = $"VK_{keyStr[1]}";
69-
73+
else if (keyStr.Length == 2 && keyStr[0] == 'D' && Char.IsDigit(keyStr[1]))
74+
{
75+
keyStr = $"VK_{keyStr[1]}";
76+
}
7077
// OEM Number keys (these are weird and some require direct mapping from translation dictionaries translationTables above)
71-
else if (keyStr.StartsWith("OEM") && (int.TryParse(keyStr.Substring(3), out _))) keyStr = $"OEM_{keyStr.Substring(3)}";
72-
78+
else if (keyStr.StartsWith("OEM") && (int.TryParse(keyStr.Substring(3), out _)))
79+
{
80+
keyStr = $"OEM_{keyStr.Substring(3)}";
81+
}
7382
var success = Enum.TryParse(keyStr, out VirtualKeyCode result);
7483
if (!success)
84+
{
7585
Debug.WriteLine("Key not found.");
86+
}
7687
return success ? new Tuple<VirtualKeyCode, bool>(result, false) : null;
7788
// If no key found, returns null
7889
}

OpenVR2Key/MainWindow.xaml.cs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,7 @@ public MainWindow()
120120
{
121121
Dispatcher.Invoke(() =>
122122
{
123-
var time = DateTime.Now.ToString("HH:mm:ss");
124-
var oldLog = TextBox_Log.Text;
125-
var lines = oldLog.Split('\n');
126-
Array.Resize(ref lines, 3);
127-
var newLog = string.Join("\n", lines);
128-
TextBox_Log.Text = $"{time}: {message}\n{newLog}";
123+
WriteToLog(message);
129124
});
130125
});
131126

@@ -136,6 +131,16 @@ public MainWindow()
136131
InitTrayIcon();
137132
}
138133

134+
private void WriteToLog(String message)
135+
{
136+
var time = DateTime.Now.ToString("HH:mm:ss");
137+
var oldLog = TextBox_Log.Text;
138+
var lines = oldLog.Split('\n');
139+
Array.Resize(ref lines, 3);
140+
var newLog = string.Join("\n", lines);
141+
TextBox_Log.Text = $"{time}: {message}\n{newLog}";
142+
}
143+
139144
private void InitWindow()
140145
{
141146
var shouldMinimize = MainModel.LoadSetting(MainModel.Setting.Minimize);
@@ -154,7 +159,7 @@ private void InitTrayIcon()
154159
var icon = Properties.Resources.icon.Clone() as System.Drawing.Icon;
155160
_notifyIcon = new System.Windows.Forms.NotifyIcon();
156161
_notifyIcon.Click += NotifyIcon_Click;
157-
_notifyIcon.Text = "Click to show main OpenVR2Key window.";
162+
_notifyIcon.Text = "Click to show the OpenVR2Key window";
158163
_notifyIcon.Icon = icon;
159164
_notifyIcon.Visible = true;
160165
}
@@ -211,16 +216,8 @@ private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
211216
var key = e.Key == Key.System ? e.SystemKey : e.Key;
212217
if (!_controller.OnKeyDown(key))
213218
{
214-
Dispatcher.Invoke(() =>
215-
{
216-
string message = $"Key not mapped: " + key.ToString();
217-
var time = DateTime.Now.ToString("HH:mm:ss");
218-
var oldLog = TextBox_Log.Text;
219-
var lines = oldLog.Split('\n');
220-
Array.Resize(ref lines, 3);
221-
var newLog = string.Join("\n", lines);
222-
TextBox_Log.Text = $"{time}: {message}\n{newLog}";
223-
});
219+
string message = $"Key not mapped: " + key.ToString();
220+
WriteToLog(message);
224221
}
225222

226223
}

OpenVR2Key/Properties/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

OpenVR2Key/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,7 @@
124124
<data name="logo" type="System.Resources.ResXFileRef, System.Windows.Forms">
125125
<value>..\resources\logo.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
126126
</data>
127+
<data name="Version" xml:space="preserve">
128+
<value>v0.45</value>
129+
</data>
127130
</root>

OpenVR2Key/Properties/Settings.Designer.cs

Lines changed: 0 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

OpenVR2Key/Properties/Settings.settings

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,5 @@
1414
<Setting Name="Haptic" Type="System.Boolean" Scope="User">
1515
<Value Profile="(Default)">False</Value>
1616
</Setting>
17-
<Setting Name="Version" Type="System.String" Scope="User">
18-
<Value Profile="(Default)">v0.43</Value>
19-
</Setting>
2017
</Settings>
2118
</SettingsFile>

0 commit comments

Comments
 (0)