Skip to content

Instantly share code, notes, and snippets.

@RyuaNerin
Last active April 5, 2016 23:39
Show Gist options
  • Save RyuaNerin/b38656708a11dc2dc402 to your computer and use it in GitHub Desktop.
Save RyuaNerin/b38656708a11dc2dc402 to your computer and use it in GitHub Desktop.
static class NativeMethods
{
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PeekMessage(
[In] ref MSG lpMsg,
IntPtr hwnd,
uint wMsgFilterMin,
uint wMsgFilterMax,
uint wRemoveMsg);
[DllImport("user32.dll")]
public static extern bool TranslateMessage(
[In] ref MSG lpMsg);
[DllImport("user32.dll")]
public static extern IntPtr DispatchMessage(
[In] ref MSG lpmsg);
[StructLayout(LayoutKind.Sequential)]
public struct MSG
{
public int hwnd;
public int message;
public int wParam;
public int lParam;
public int time;
public POINTAPI pt;
}
[StructLayout(LayoutKind.Sequential)]
public struct POINTAPI
{
public int x;
public int y;
}
}
var msg = new NativeMethods.MSG();
while (true)
{
if (NativeMethods.PeekMessage(ref msg, IntPtr.Zero, 0, 0, NativeMethods.PM_REMOVE))
{
NativeMethods.TranslateMessage(ref msg);
NativeMethods.DispatchMessage(ref msg);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment