开发者

How do I test SendInput in c#

开发者 https://www.devze.com 2022-12-23 02:57 出处:网络
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 me

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 Wnd开发者_JAVA技巧Proc(ref Message m)
    {
        if (m.Msg == WM_KEYDOWN)
        {
            Console.WriteLine("GotIt");
        }
        base.WndProc(ref m);
    }


It turns out since I was looking the down key, I needed to listen to ProcCmdKeys, and not just the key down event.

0

精彩评论

暂无评论...
验证码 换一张
取 消