42 lines
1.3 KiB
C#
42 lines
1.3 KiB
C#
using System.Runtime.InteropServices;
|
|
|
|
namespace CursorLang.Core.Interop;
|
|
|
|
/// <summary>
|
|
/// Input details of the active application: which window holds keyboard focus
|
|
/// and where the caret is.
|
|
/// </summary>
|
|
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);
|
|
|
|
/// <summary>
|
|
/// The input state of the foreground thread.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// The zero thread identifier is not accidental: in modern applications the
|
|
/// top-level window and the input window live in different threads, and the
|
|
/// question has to be about the foreground as a whole.
|
|
/// </remarks>
|
|
internal static bool TryGetInfo(out GuiThreadInfo info)
|
|
{
|
|
info = new GuiThreadInfo { cbSize = Marshal.SizeOf<GuiThreadInfo>() };
|
|
return GetGUIThreadInfo(0, ref info);
|
|
}
|
|
}
|