I have been using some P/Invoke code to simulate a key press, but I can’t work out how to press more than one key at once. I am trying to simulate pressing and holding CTRL and then pressing C and then V, so just a copy and paste.
The code I am using so far is this, but so far I can only manage to press CTRL, not hold it and press C and V:
[DllImport("user32.dll", SetLastError = true)]
static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
public const int VK_LCONTROL = 0xA2;
static void Main(string[] args)
{
keybd_event(VK_LCONTROL, 0, 0, 0);
}
I would really appreciate any suggestions. Thanks.
The
dwFlagscontrols if the key is released or not.Try the following: