diff --git a/UEVR/MainWindow.xaml b/UEVR/MainWindow.xaml index 51b1a14..05704f2 100644 --- a/UEVR/MainWindow.xaml +++ b/UEVR/MainWindow.xaml @@ -158,6 +158,10 @@ + + + + diff --git a/UEVR/MainWindow.xaml.cs b/UEVR/MainWindow.xaml.cs index 5039c3c..d615f74 100644 --- a/UEVR/MainWindow.xaml.cs +++ b/UEVR/MainWindow.xaml.cs @@ -150,6 +150,7 @@ public class ValueTemplateSelector : DataTemplateSelector { } } } + public partial class MainWindow : Window { // variables // process list @@ -173,6 +174,9 @@ public partial class MainWindow : Window { private string? m_commandLineAttachExe = null; private bool m_ignoreFutureVDWarnings = false; + [System.Runtime.InteropServices.DllImport("user32.dll")] + public static extern void SwitchToThisWindow(IntPtr hWnd, bool fAltTab); + public MainWindow() { InitializeComponent(); @@ -204,6 +208,7 @@ private void MainWindow_Loaded(object sender, RoutedEventArgs e) { m_openxrRadio.IsChecked = m_mainWindowSettings.OpenXRRadio; m_nullifyVRPluginsCheckbox.IsChecked = m_mainWindowSettings.NullifyVRPluginsCheckbox; m_ignoreFutureVDWarnings = m_mainWindowSettings.IgnoreFutureVDWarnings; + m_focusGameOnInjectionCheckbox.IsChecked = m_mainWindowSettings.FocusGameOnInjection; m_updateTimer.Tick += (sender, e) => Dispatcher.Invoke(MainWindow_Update); m_updateTimer.Start(); @@ -351,6 +356,10 @@ private void Update_InjectStatus() { m_lastAutoInjectTime = now; m_commandLineAttachExe = null; // no need anymore. FillProcessList(); + if (m_focusGameOnInjectionCheckbox.IsChecked == true) + { + SwitchToThisWindow(process.MainWindowHandle, true); + } } } } @@ -574,6 +583,7 @@ private void MainWindow_Closing(object sender, System.ComponentModel.CancelEvent m_mainWindowSettings.OpenVRRadio = m_openvrRadio.IsChecked == true; m_mainWindowSettings.NullifyVRPluginsCheckbox = m_nullifyVRPluginsCheckbox.IsChecked == true; m_mainWindowSettings.IgnoreFutureVDWarnings = m_ignoreFutureVDWarnings; + m_mainWindowSettings.FocusGameOnInjection = m_focusGameOnInjectionCheckbox.IsChecked == true; m_mainWindowSettings.Save(); } @@ -1040,6 +1050,11 @@ private void Inject_Clicked(object sender, RoutedEventArgs e) { Injector.InjectDll(process.Id, "UEVRBackend.dll"); } + + if (m_focusGameOnInjectionCheckbox.IsChecked == true) + { + SwitchToThisWindow(process.MainWindowHandle, true); + } } private string GenerateProcessName(Process p) { diff --git a/UEVR/MainWindowSettings.cs b/UEVR/MainWindowSettings.cs index 1bb0300..4ac4d09 100644 --- a/UEVR/MainWindowSettings.cs +++ b/UEVR/MainWindowSettings.cs @@ -34,5 +34,13 @@ public bool IgnoreFutureVDWarnings { get { return (bool)this["IgnoreFutureVDWarnings"]; } set { this["IgnoreFutureVDWarnings"] = value; } } + + [UserScopedSettingAttribute()] + [DefaultSettingValueAttribute("true")] + public bool FocusGameOnInjection + { + get { return (bool)this["FocusGameOnInjection"]; } + set { this["FocusGameOnInjection"] = value; } + } } }