I would like to keep a key pressed while my program runs, so I did this:
public partial class Form1 : Form
{
[DllImport("user32.dll", SetLastError = true)]
static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
const int KEY_DOWN_EVENT = 0x0001; //Key down flag
const int KEY_UP_EVENT = 0x0002; //Key up flag
byte VK_UP = 0x26;
public Form1()
{
InitializeComponent();
keybd_event(VK_UP, 0, KEY_DOWN_EVENT, 0);
}
void gkh_KeyDown(object sender, KeyEventArgs e)
{
Debug.WriteLine(e.KeyCode.ToString()); //it only executes once
}
but it only press the key once. What am I missing?
Can't believe it's impossible on C#!! even delphi can do it !!
What I really want to do is that:
Assuming I press the key 'a' and some seconds later I press the key 'b'. When I loose the key 'b' I want that 'a' continues to be displayed on screen.