steam-deck-tools/PowerControl/Helpers/TopLevelWindow.cs
Kamil Trzciński b4c07be511 Add PowerControl
Add NeptuneController support (kind of works)

Add Neptune controller directly from hidapi (to reduce rate of requests)

Add README
2022-11-15 20:36:36 +01:00

28 lines
758 B
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace PowerControl.Helpers
{
public class TopLevelWindow
{
[DllImport("user32.dll", SetLastError= true)]
static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
public static uint? GetTopLevelProcessId()
{
var hWnd = GetForegroundWindow();
var result = GetWindowThreadProcessId(hWnd, out uint processId);
if (result != 0)
return processId;
return null;
}
}
}