3

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

Sastrija
  • 3,284
  • 6
  • 47
  • 64
Bali C
  • 30,582
  • 35
  • 123
  • 152
  • 8
    `...manually triggered bsod.` Wait...what? – Bobby Sep 05 '11 at 12:11
  • 5
    http://www.wikihow.com/Force-a-Blue-Screen-in-Windows – Bali C Sep 05 '11 at 12:13
  • I don't know if that's awesome, stupid or just a left-over debug key (most likely the last one)...anyway, nice to know, thanks. – Bobby Sep 05 '11 at 12:15
  • 3
    I'm going to enable this on my co-worker's PC and use AutoHotKey to emulate the key-presses when he types his name. Muahahahahahaha. – mdm Sep 05 '11 at 12:32

3 Answers3

17

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.

Sastrija
  • 3,284
  • 6
  • 47
  • 64
Renatas M.
  • 11,694
  • 1
  • 43
  • 62
3

You might have some luck with the Windows Input Simulator http://inputsimulator.codeplex.com/

Chris Wood
  • 132
  • 2
  • 8
1

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

Tomasz Jakub Rup
  • 10,502
  • 7
  • 48
  • 49
Iridio
  • 9,213
  • 4
  • 49
  • 71
  • Thanks 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. – Bali C Sep 05 '11 at 12:42