使用 Windows 消息按住 Alt 按钮
如何在 Windows 消息中按住 ALT 按钮?
有 WM_KEYHOLD 或类似的东西吗?
这是屏幕截图的代码,但我猜缺少了一些东西。我认为我使用的关键代码很糟糕,对于 0x70 它发送 F1。对于 0x46,它会发送令人讨厌的 Windows 声音。
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);
}
How can I, with windows messages, Hold the ALT button?
Is there a WM_KEYHOLD or anything like that?
This is the code to screen shot but I guess something is missin. I think the key codes im using are bad, For 0x70 it sends F1. and for 0x46 it sends anoyying windows sound.
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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
DanielB 引用 lParam 位链接的文档 29 定义ALT状态,你尝试过吗?
The Docs linked by DanielB reference to lParam's bit 29 defining ALT status, have you tried that?
根据我的理解,发送
WM_SYSKEYDOWN
/WM_KEYDOWN
应该足够了。请参阅文档In my understanding, it should be enough to send
WM_SYSKEYDOWN
/WM_KEYDOWN
. see Docs