-2

I'm currently trying to experiment with using PostMessage.

I got the hang of how to use it and apply different keys and such but I've met a problem: When using PostMessage while I myself am pressing Shift or Ctrl, it will be a combined Keypress of Shift + Key.

In some situations this isnt optimal or actually wrong and I was wondering if it's possible to either ignore the Keystate of Shift or set it to No through Flags or something

        PostMessage(hWnd, WM_SYSKEYDOWN, VK_S, 0);
        PostMessage(hWnd, WM_SYSKEYUP, VK_S, 0);

I'm using it like this. I've tried using WM_KEYDOWN and UP or WM_CHAR but it seems like my application doesn't react to WM_CHAR and WM_KEYDOWN does the same as WM_SYSKEYDOWN

Simon Mourier
  • 132,049
  • 21
  • 248
  • 298
Hoesl
  • 13
  • 6
  • 1
    *"I got the hang of how to use it"* - Do not fool yourself. [You can't simulate keyboard input with PostMessage](https://devblogs.microsoft.com/oldnewthing/20050530-11/?p=35513). – IInspectable Apr 03 '22 at 13:08
  • I didnt say that I fully understand the background to it but at least I am able to use it to achieve what I need in most cases. – Hoesl Apr 04 '22 at 16:13

1 Answers1

0

Don't try to synthesize keyboard (or mouse) messages directly. Use SendInput instead.

Note, however, that this will still add the new input to the end of the message queue, so if you want to act like a certain key combination is pressed right now you will need to handle that situation in some other manner.

SoronelHaetir
  • 14,104
  • 1
  • 12
  • 23