C# Simulate Key Press
15,250
Solution 1
You can use keybd_event event to simulate right Ctrl key press.
[DllImport("user32.dll", SetLastError = true)]
static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
public const int KEYEVENTF_EXTENDEDKEY = 0x0001; //Key down flag
public const int KEYEVENTF_KEYUP = 0x0002; //Key up flag
public const int VK_RCONTROL = 0xA3; //Right Control key code
Usage:
keybd_event(VK_RCONTROL, 0, KEYEVENTF_EXTENDEDKEY, 0);
keybd_event(VK_RCONTROL, 0, KEYEVENTF_KEYUP, 0);
For other key simulation here is virtual key codes list.
Solution 2
You might have some luck with the Windows Input Simulator http://inputsimulator.codeplex.com/
Solution 3
If you are usign AutoHotKey try looking here. with {RControl}
you should get what you want
Update: For .NET try looking at this for more info, but AFAIK you can't send right Ctrl key. guess you must use win32 to accomplish it
Author by
Bali C
Updated on June 14, 2022Comments
-
Bali C about 2 years
I was looking for a way to simulate pressing the right Ctrl key in C#, it must be the right one. I know this can be done for the left one but I couldn't find anything on the right one. It is so I can simulate the key press for the manually triggered bsod.
Thanks
-
Bali C almost 13 yearsThanks for the link but I was looking to do it from a vs app with C#, is this possible? If not I will look at the AutoHotKey, thanks.