-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
56 lines (43 loc) · 1.41 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System.Diagnostics;
using System.Runtime.InteropServices;
using DiscordRPC;
using Kaikki;
DiscordPresence.Client = new DiscordRpcClient("932775385014353970");
DiscordPresence.Client.Initialize();
[DllImport("user32.dll")]
static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
static extern Int32 GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
string GetForegroundProcessName()
{
IntPtr hwnd = GetForegroundWindow();
if (hwnd == IntPtr.Zero)
return "Unknown";
uint pid;
GetWindowThreadProcessId(hwnd, out pid);
foreach (Process p in Process.GetProcesses())
{
if (p.Id == pid)
return p.ProcessName;
}
return "Unknown";
}
Console.WriteLine("Press ESC to stop");
do {
while (!Console.KeyAvailable) {
Thread.Sleep(1000);
Console.WriteLine($"Focused process name: {GetForegroundProcessName()}");
if (GetForegroundProcessName() != "Unknown")
{
string returnValue = DiscordPresence.RunDiscordRpc(GetForegroundProcessName());
Console.WriteLine(returnValue == "Unsupported process"
? "Set default Discord presence"
: returnValue);
}
else
{
DiscordPresence.Client.ClearPresence();
}
}
} while (Console.ReadKey(true).Key != ConsoleKey.Escape);
DiscordPresence.StopDiscordRpc();