Create an on-screen keyboard

I use PostMessage to simulate keystrokes in a program that is in the background. It works great, except for characters that require a shift on the physical keyboard. How to simulate a shift? "

The code I use is approximately:

 VK vk = VkKeyScanEx (c, GetKeyboardLayout (0));

 AttachThreadInput (_attachedThredId, _attachedProcessId, true);
 PostMessage       (_window, WM_KEYDOWN, vk.key, 0x1);
 PostMessage       (_window, WM_KEYUP,   vk.key, 0xC0010001);
 AttachThreadInput (_attachedThredId, _attachedProcessId, false);

How do I handle the extended part of VK?

Edit

I am trying to create an on-screen keyboard. Each button on the on-screen keyboard mimics a sequence of keystrokes. The receiver is an old program that performs different tasks depending on the keyboard sequence being performed. The key sequence is as follows:

  • {ESC} {NN ESC} NN
  • {ESC} NN
  • ½NN
  • §NN

where {ESC} simulates pressing the Esc key, NN - hexadecimal values ​​and § / ½ get the program to listen to.

, . , ,

+1
3

:

, SendInput, , . SendInput . , , - ALT+TAB .

, :

  • -. WM_KEYDOWN/WM_KEYUP . , (GetKeyboardState()), . , , , .
  • . , , .
  • . .
  • ( ..). , / , , DirectInput... , - .

; .


, , , PostMessage SetKeyboardState , .

+4

, , , PostMessage() , , . Microsoft SendInput(), . , , , , , , .

, .

, WM_KEYDOWN, , , WM_KEYUP. , , .

+2

Personally, I would use SendKey.Send () for this purpose.

MSDN page

+1
source

All Articles