Skip to content

Commit

Permalink
Add detection for the SteamVR dashboard, which blocks input
Browse files Browse the repository at this point in the history
  • Loading branch information
BOLL7708 committed Apr 2, 2022
1 parent 82e7d1d commit 5892c17
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 9 deletions.
10 changes: 10 additions & 0 deletions OpenVR2Key/MainController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class MainController
public Action<string, bool> KeyTextUpdateAction { get; set; } = (status, cancel) => { Debug.WriteLine("No key text action set."); };
public Action<Dictionary<string, Key[]>, bool> ConfigRetrievedAction { get; set; } = (config, forceButtonOff) => { Debug.WriteLine("No config loaded."); };
public Action<string, bool> KeyActivatedAction { get; set; } = (key, on) => { Debug.WriteLine("No key simulated action set."); };
public Action<bool> DashboardVisibleAction { get; set; } = (visible) => { Debug.WriteLine("No dashboard visible action set."); };

// Other
private string _currentApplicationId = "";
Expand Down Expand Up @@ -182,6 +183,15 @@ private void WorkerThread()
UpdateInputSourceHandles();
}
);
_ovr.RegisterEvent(EVREventType.VREvent_DashboardActivated, (data) =>
{
DashboardVisibleAction.Invoke(true);
});
_ovr.RegisterEvent(EVREventType.VREvent_DashboardDeactivated, (data) =>
{
DashboardVisibleAction.Invoke(false);
});
DashboardVisibleAction.Invoke(OpenVR.Overlay.IsDashboardVisible()); // To convey the initial state if the Dashboard is visible on launch of application.
}
else
{
Expand Down
39 changes: 32 additions & 7 deletions OpenVR2Key/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public partial class MainWindow : Window
private System.Windows.Forms.NotifyIcon _notifyIcon;
private HashSet<string> _activeKeys = new HashSet<string>();
private bool _initDone = false;
private bool _dashboardIsVisible = false;
public MainWindow()
{
InitWindow();
Expand Down Expand Up @@ -91,7 +92,7 @@ public MainWindow()
if (_activeElement != null)
{
(_activeElement as Label).Content = keyText;
if(cancel) UpdateLabel(_activeElement as Label, false);
if (cancel) UpdateLabel(_activeElement as Label, false);
}
});
},
Expand All @@ -100,10 +101,10 @@ public MainWindow()
ConfigRetrievedAction = (config, forceButtonOff) =>
{
var loaded = config != null;
if(loaded) Debug.WriteLine($"Config Retrieved Action: count()={config.Count}");
if (loaded) Debug.WriteLine($"Config Retrieved Action: count()={config.Count}");
Dispatcher.Invoke(() =>
{
if(loaded) InitList(config);
if (loaded) InitList(config);
UpdateConfigButton(loaded, forceButtonOff);
});
},
Expand All @@ -112,10 +113,34 @@ public MainWindow()
{
Dispatcher.Invoke(() =>
{
if (on) _activeKeys.Add(key);
else _activeKeys.Remove(key);
if (_activeKeys.Count > 0) Label_Keys.Content = string.Join(", ", _activeKeys);
else Label_Keys.Content = "None";
if (!_dashboardIsVisible) {
if (on) _activeKeys.Add(key);
else _activeKeys.Remove(key);
if (_activeKeys.Count > 0) Label_Keys.Content = string.Join(", ", _activeKeys);
else Label_Keys.Content = "None";
Label_Keys.ToolTip = "";
Label_Keys.Background = Brushes.Gray;
}
});
},

// Dashboard Visible
DashboardVisibleAction = (visible) => {
Dispatcher.Invoke(() =>
{
_dashboardIsVisible = visible;
if (visible)
{
Label_Keys.Content = "Blocked";
Label_Keys.ToolTip = "The SteamVR Dashboard is visible which will block input from this application.";
Label_Keys.Background = Brushes.Tomato;
}
else
{
Label_Keys.Content = "Unblocked";
Label_Keys.ToolTip = "";
Label_Keys.Background = Brushes.Gray;
}
});
}
};
Expand Down
2 changes: 1 addition & 1 deletion OpenVR2Key/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion OpenVR2Key/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,6 @@
<value>..\resources\logo.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="Version" xml:space="preserve">
<value>v0.55</value>
<value>v0.57</value>
</data>
</root>

0 comments on commit 5892c17

Please sign in to comment.