Verbunden wird nur beim Start ueber die Lobby, bricht die Verbindung ab alle 10 s neu (nicht nach Ablehnung oder Konto-Problem). release.ps1 legt jetzt Gitea-Releases mit bso-release.json an. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
39 lines
1.3 KiB
C#
39 lines
1.3 KiB
C#
using System;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace BSO
|
|
{
|
|
/// <summary>Tasten der Mod (F9-F11): "gerade gedrueckt" erkennen, nur wenn das Spielfenster vorne ist.</summary>
|
|
public static class Input
|
|
{
|
|
[DllImport("user32.dll")] static extern short GetAsyncKeyState(int key);
|
|
[DllImport("user32.dll")] static extern nint GetForegroundWindow();
|
|
[DllImport("user32.dll")] static extern uint GetWindowThreadProcessId(nint window, out uint process);
|
|
|
|
public const int F9 = 0x78, F10 = 0x79, F11 = 0x7A;
|
|
|
|
static readonly bool[] down = new bool[256], pressed = new bool[256];
|
|
static readonly int[] watched = { F9, F10, F11 };
|
|
|
|
/// <summary>Einmal pro Bild vor allen Pressed-Abfragen.</summary>
|
|
public static void Update()
|
|
{
|
|
bool focus = GameHasFocus();
|
|
foreach (int key in watched)
|
|
{
|
|
bool now = focus && GetAsyncKeyState(key) < 0;
|
|
pressed[key] = now && !down[key];
|
|
down[key] = now;
|
|
}
|
|
}
|
|
|
|
public static bool Pressed(int key) => pressed[key];
|
|
|
|
public static bool GameHasFocus()
|
|
{
|
|
GetWindowThreadProcessId(GetForegroundWindow(), out uint pid);
|
|
return pid == (uint)Environment.ProcessId;
|
|
}
|
|
}
|
|
}
|