using System.Runtime.InteropServices; namespace CursorLang.Interop; /// /// Сведения о вводе в активном приложении: какое окно держит фокус клавиатуры /// и где находится каретка. /// internal static class ForegroundInputNative { [StructLayout(LayoutKind.Sequential)] internal struct GuiThreadInfo { public int cbSize; public uint flags; public IntPtr hwndActive; public IntPtr hwndFocus; public IntPtr hwndCapture; public IntPtr hwndMenuOwner; public IntPtr hwndMoveSize; public IntPtr hwndCaret; public PopupWindowNative.Rect rcCaret; } [DllImport("user32.dll")] private static extern bool GetGUIThreadInfo(uint idThread, ref GuiThreadInfo lpgui); /// /// Состояние ввода потока переднего плана. /// /// /// Нулевой идентификатор потока не случаен: у современных приложений окно /// верхнего уровня и окно ввода живут в разных потоках, и спрашивать нужно /// именно про передний план целиком. /// internal static bool TryGetInfo(out GuiThreadInfo info) { info = new GuiThreadInfo { cbSize = Marshal.SizeOf() }; return GetGUIThreadInfo(0, ref info); } }