A small host helper for ImGui integration. It exposes a clipboard provider delegate, a flag to simulate input, tracks keyboard keys that are unavailable, and provides PollKeyDown which maps an ImGuiKey to an S&box input name and checks Input.Keyboard.Down, marking names that throw as unavailable.
using Sandbox;
namespace SboxSuperuser.Engine.Vendor.ImGui;
internal static class ImGuiHost
{
internal static Func<bool, string> ClipboardCopyProvider { get; set; }
internal static bool SimulateInput { get; set; }
private static readonly HashSet<string> UnavailableKeys = new();
internal static bool PollKeyDown( ImGuiKey key )
{
if ( !Game.IsPlaying || SimulateInput || key >= ImGuiKey.MouseLeft ) return false;
var name = ImGuiKeyNames.ToSboxName( key );
if ( name is null || UnavailableKeys.Contains( name ) ) return false;
try
{
return Input.Keyboard.Down( name );
}
catch ( Exception )
{
UnavailableKeys.Add( name );
return false;
}
}
}