如何在 C# 中测试 SendInput
如何判断对 SendInput 的调用是否正常工作?我在下面有一个小片段,但该消息似乎从未被点击。 SendInput() 返回 1,并且没有错误,因此我假设消息正常发出。
我还尝试过 Form KeyPress 和 KeyDown 事件,但我似乎也从未得到过这些。
private void button1_Click(object sender, EventArgs e)
{
INPUT input = new INPUT();
input.mkhi.ki.wVk = (byte)System.Windows.Forms.Keys.B;
uint result = SendInput(1, ref input, Marshal.SizeOf(new INPUT()));
}
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_KEYDOWN)
{
Console.WriteLine("GotIt");
}
base.WndProc(ref m);
}
How can I tell if my call to SendInput is working properly? I have a small snippet below, and the message never seems to get hit. SendInput() returns 1, and there's no errors, so I assume that the message is going out properly.
I've also tried the Form KeyPress and KeyDown Events, and I never seem to get those either.
private void button1_Click(object sender, EventArgs e)
{
INPUT input = new INPUT();
input.mkhi.ki.wVk = (byte)System.Windows.Forms.Keys.B;
uint result = SendInput(1, ref input, Marshal.SizeOf(new INPUT()));
}
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_KEYDOWN)
{
Console.WriteLine("GotIt");
}
base.WndProc(ref m);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,由于我正在查看向下键,因此我需要监听 ProcCmdKeys,而不仅仅是向下键事件。
It turns out since I was looking the down key, I needed to listen to ProcCmdKeys, and not just the key down event.