What I am trying to accomplish in this console program is to be able to press and hold a key, by using user32.dll. I know I am not sending an extended key. But I dont think sending it as a scancode is right either. And I think I am passing it the right flag to just hold the key.. I also know I will have to do a key up. but as of right now all I need is to get the key pushed down. Any help would be much appreciated, as of right now the code below does not work
public class Program
{
[DllImport("user32.dll")]
public static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, uint dwExtraInfo);
const int VK_UP = 0x26, VK_DOWN = 0x28, VK_LEFT = 0x25, VK_RIGHT = 0x27;
const uint KEYEVENTF_KEYUP = 0x0002, SCANCODE = 0x0008;
const int KEY_0 = 11;
internal enum ScanCodeShort : short
{
KEY_9 = 10, KEY_A = 30, KEY_B = 48, KEY_C = 46, KEY_D = 32, KEY_E = 18, KEY_F = 33,
KEY_G = 34, KEY_H = 35, KEY_I = 23, KEY_J = 36, KEY_K = 37, KEY_L = 38, KEY_M = 50, KEY_N = 49,
KEY_O = 24, KEY_P = 25, KEY_Q = 16, KEY_R = 19, KEY_S = 31, KEY_T = 20, KEY_U = 22, KEY_V = 47,
KEY_W = 17, KEY_X = 45, KEY_Y = 21, KEY_Z = 44, }
private static void Main(string[] args)
{
Thread.Sleep(2000);
// push V key
keybd_event((byte)ScanCodeShort.KEY_V, 0x45, 0, 0);
// release V key
keybd_event((byte)ScanCodeShort.KEY_V, 0x45, KEYEVENTF_KEYUP, 0);
Console.WriteLine("done");
Console.Read();
}
}