0

I need to make Post/SendMessage that will make Alt+Space that will open some tab that i need in windows aplication.I can't use SendKeys SendKeys.Send("% ") i have to use Post/SendMessage only.

This what i have tried so far

 private const uint WM_KEYDOWN = 0x0100;
 private const uint WM_KEYUP = 0x0101;
 private const uint WM_SYSKEYDOWN = 0x0104;
 private const uint WM_SYSKEYUP = 0x0105;
 private const int VK_MENU = 0x12;
 private const int VK_SPACE = 0x20;

 PostMessage(Main, WM_SYSKEYDOWN, VK_MENU, 0);//
 PostMessage(Main, WM_KEYDOWN, VK_SPACE, 0);
 Thread.Sleep(1000);
 PostMessage(Main, WM_KEYUP, VK_SPACE, 0);
 PostMessage(Main, WM_SYSKEYUP, VK_MENU, 0);

Now i can see that Alt is pressed because tabs get under-lined(first letter)(it's happened in 99% winapp's),but the combination of Alt+Space not happened,and i don't know why.

Any one know what i am doing wrong?

Vladimir Potapov
  • 2,347
  • 7
  • 44
  • 71
  • Your PostMessage declaration is wrong. With the ALT-key down, the VK_SPACE keystroke is reported with WM_SYSKEYDOWN/UP instead. Posting the VK_MENU key just fakes the state of the ALT key, it isn't actually down when the app checks the keyboard state with GetKeyState(). AttachThreadInput + SetKeyboardState is required to update the thread's keyboard state. Do consider a UI Automation library instead. – Hans Passant Sep 02 '14 at 09:06
  • I build thread that press the Alt,but i can't find the way how to SetKeyboardState to Alt Pressed, to avoid GetKeyState(). – Vladimir Potapov Sep 02 '14 at 12:51

0 Answers0