I've created a custom form for a numeric keyboard which implements the following code:
private void btn1_Click(object sender, EventArgs e)
{
PressKey(Keys.D1);
}
[DllImport("user32.dll", SetLastError = true)]
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo);
public static void PressKey(Keys key)
{
const int KEYEVENTF_EXTENDEDKEY = 0x1;
keybd_event((byte)key, 0x45, KEYEVENTF_EXTENDEDKEY, (UIntPtr)0);
}
I've also used the following block
protected override bool ShowWithoutActivation
{
get { return true; }
}
It works as charm for notepad, word or other editors (and also using the basic SendKeys method), but in my app, in the grid cell i intend to use it (or other editable control) it fails to insert a value. Accidentally i've found that it can insert a value only once, when the cell is not on edit mode, but it has focus.
Any example of virtual keyboard implementation from one form to another would be highly appreciated