Search code examples
c#.netwinapiprocesspostmessage

PostMessage WM_KEYDOWN send multiply keys?


I have this code:

    public static void Next()
    {
        Process[] processes = Process.GetProcessesByName("test");

        foreach (Process proc in processes)
            PostMessage(proc.MainWindowHandle, WM_KEYDOWN, VK_RIGHT, 0);
    }

This code sents the Right Arrow key, i want to sent ALT+CTRL+RIGHT i tried this:

    public static void Forward()
    {
        Process[] processes = Process.GetProcessesByName("test");

        foreach (Process proc in processes)
        {
            PostMessage(proc.MainWindowHandle, WM_KEYDOWN, VK_CONTROL, 0);
            PostMessage(proc.MainWindowHandle, WM_KEYDOWN, VK_ALT, 0);
            PostMessage(proc.MainWindowHandle, WM_KEYDOWN, VK_RIGHT, 0);
        }
    }

But it doesn't work...

Any ideas?


Solution

  • You can't simulate keyboard input with PostMessage, at least not reliably use SendInput instead.