Skip to content

Commit

Permalink
add autofocus to fullscreen view
Browse files Browse the repository at this point in the history
  • Loading branch information
Nonary committed Jun 5, 2023
1 parent 24f38d9 commit 9bc1afc
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion PlayniteWatcher.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ try {

$message = $streamReader.ReadLine()

if($message -eq "Terminate"){
if ($message -eq "Terminate") {
break;
return;
}
Expand Down Expand Up @@ -75,6 +75,35 @@ try {
Start-Sleep -Milliseconds 500
$elapsedSeconds += .5
}

try {

Add-Type -TypeDefinition -ErrorAction SilentlyContinue @"
using System;
using System.Runtime.InteropServices;
public class WindowHelper
{
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetForegroundWindow(IntPtr hWnd);
}
"@

# Get the process ID (PID) of the application you want to bring to the foreground
$processID = Get-Process -Name "Playnite.FullscreenApp" | Select-Object -ExpandProperty ID

# Find the application's main window handle using the process ID
$mainWindowHandle = (Get-Process -id $processID).MainWindowHandle

# Bring the application to the foreground
[WindowHelper]::SetForegroundWindow($mainWindowHandle)
}
catch {
Write-Host "Failed to apply focus on FullScreen app, application such as DS4Tool may not properly activate controller profiles."
Write-Host "This is not a serious error, and does not prevent the overall functionality of the script"
}

}


Expand Down

0 comments on commit 9bc1afc

Please sign in to comment.