如何使用 Windows 消息按住 ALT 按钮?
是否有 WM_KEYHOLD 或类似的东西?
这是屏幕截图的代码,但我想有些东西是丢失的。我认为我使用的键码不好,对于 0x70 它发送 F1。对于 0x46,它会发送令人讨厌的窗口声音。
const uint WM_SYSKEYDOWN = 260;
const uint VK_MENU = 18;//virtual key code of Alt key
const uint VK_SNAPSHOT = 44;//virtual key code of Snapshot key
[DllImport("User32.Dll")]
public static extern long PostMessage(IntPtr hWnd, UInt32 wMsg, long wParam, long lParam);
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(String sClassName, String sAppName);
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern IntPtr GetForegroundWindow();
private void timer1_Tick(object sender, EventArgs e)
{
IntPtr hwnd = GetForegroundWindow();
//PostMessage(hwnd, WM_SYSKEYDOWN, VK_MENU, 1);
PostMessage(hwnd, WM_SYSKEYDOWN, VK_SNAPSHOT, 1);
}