// Action was triggered, handle it private void OnAction(string actionKey, InputDigitalActionData_t data, ulong inputSourceHandle) { KeyActivatedAction.Invoke(actionKey, data.bState); Debug.WriteLine($"{actionKey} : " + (data.bState ? "PRESSED" : "RELEASED")); if (MainModel.BindingExists(actionKey)) { var binding = MainModel.GetBinding(actionKey); if (data.bState) { if (MainModel.LoadSetting(MainModel.Setting.Haptic)) { if (inputSourceHandle == _inputSourceHandleLeft) { _ovr.TriggerHapticPulseInController(ETrackedControllerRole.LeftHand); } if (inputSourceHandle == _inputSourceHandleRight) { _ovr.TriggerHapticPulseInController(ETrackedControllerRole.RightHand); } } if (MainModel.LoadSetting(MainModel.Setting.Notification)) { var notificationBitmap = EasyOpenVRSingleton.BitmapUtils.NotificationBitmapFromBitmap(Properties.Resources.logo); _ovr.EnqueueNotification(_notificationOverlayHandle, $"{actionKey} simulated {GetKeysLabel(binding.Item1)}", notificationBitmap); } } SimulateKeyPress(data, binding); } }
// Load settings and apply them to the checkboxes private void InitSettings() { CheckBox_Minimize.IsChecked = MainModel.LoadSetting(MainModel.Setting.Minimize); CheckBox_Tray.IsChecked = MainModel.LoadSetting(MainModel.Setting.Tray); CheckBox_DebugNotifications.IsChecked = MainModel.LoadSetting(MainModel.Setting.Notification); CheckBox_HapticFeedback.IsChecked = MainModel.LoadSetting(MainModel.Setting.Haptic); Label_Version.Content = MainModel.GetVersion(); }
private void InitWindow() { var shouldMinimize = MainModel.LoadSetting(MainModel.Setting.Minimize); var onlyInTray = MainModel.LoadSetting(MainModel.Setting.Tray); if (shouldMinimize) { Hide(); WindowState = WindowState.Minimized; ShowInTaskbar = !onlyInTray; } }
// Load settings and apply them to the checkboxes private void InitSettings() { CheckBox_Minimize.IsChecked = MainModel.LoadSetting(MainModel.Setting.Minimize); CheckBox_Tray.IsChecked = MainModel.LoadSetting(MainModel.Setting.Tray); CheckBox_ExitWithSteamVR.IsChecked = MainModel.LoadSetting(MainModel.Setting.ExitWithSteam); CheckBox_DebugNotifications.IsChecked = MainModel.LoadSetting(MainModel.Setting.Notification); CheckBox_HapticFeedback.IsChecked = MainModel.LoadSetting(MainModel.Setting.Haptic); #if DEBUG Label_Version.Content = $"{MainModel.GetVersion()}d"; #else Label_Version.Content = MainModel.GetVersion(); #endif }
private void Window_StateChanged(object sender, EventArgs e) { var onlyInTray = MainModel.LoadSetting(MainModel.Setting.Tray); switch (WindowState) { case WindowState.Minimized: ShowInTaskbar = !onlyInTray; break; default: ShowInTaskbar = true; Show(); break; } }
public MainWindow() { InitWindow(); InitializeComponent(); Title = Properties.Resources.AppName; // Prevent multiple instances running at once _mutex = new Mutex(true, Properties.Resources.AppName, out bool createdNew); if (!createdNew) { MessageBox.Show( Application.Current.MainWindow, "This application is already running!", Properties.Resources.AppName, MessageBoxButton.OK, MessageBoxImage.Information ); Application.Current.Shutdown(); } _controller = new MainController { // Reports on the status of OpenVR StatusUpdateAction = (connected) => { Debug.WriteLine($"Status Update Action: connected={connected}"); var message = connected ? "Connected" : "Disconnected"; var color = connected ? Brushes.OliveDrab : Brushes.Tomato; Dispatcher.Invoke(() => { Label_OpenVR.Content = message; Label_OpenVR.Background = color; if (!connected && _initDone && MainModel.LoadSetting(MainModel.Setting.ExitWithSteam)) { if (_notifyIcon != null) { _notifyIcon.Dispose(); } System.Windows.Application.Current.Shutdown(); } }); }, // Triggered when a new scene app is detected AppUpdateAction = (appId) => { Debug.WriteLine($"App Update Action: appId={appId}"); _currentlyRunningAppId = appId; var color = Brushes.OliveDrab; if (appId == MainModel.CONFIG_DEFAULT) { color = Brushes.Gray; } var appIdFixed = appId.Replace("_", "__"); // Single underscores makes underlined chars Dispatcher.Invoke(() => { Debug.WriteLine($"Setting AppID to: {appId}"); Label_Application.Content = appIdFixed; Label_Application.Background = color; }); }, // We should update the text on the current binding we are recording KeyTextUpdateAction = (keyText, cancel) => { Debug.WriteLine($"Key Text Update Action: keyText={keyText}"); Dispatcher.Invoke(() => { if (_activeElement != null) { (_activeElement as Label).Content = keyText; if (cancel) { UpdateLabel(_activeElement as Label, false); } } }); }, // We have loaded a config ConfigRetrievedAction = (config, forceButtonOff) => { var loaded = config != null; if (loaded) { Debug.WriteLine($"Config Retrieved Action: count()={config.Count}"); } Dispatcher.Invoke(() => { if (loaded) { InitList(config); } UpdateConfigButton(loaded, forceButtonOff); }); }, KeyActivatedAction = (key, on) => { Dispatcher.Invoke(() => { 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; } }); } }; // Receives error messages from OpenVR _controller.SetDebugLogAction((message) => { Dispatcher.Invoke(() => { WriteToLog(message); }); }); // Init the things var actionKeys = InitList(); _controller.Init(actionKeys); InitSettings(); InitTrayIcon(); _initDone = true; }