I am trying to create a on screen key board.
I simply want to send a key (Simulate the keyboard) to a combo box using the Handle of the control.
The below code is not working
public const ushort WM_KEYDOWN = 0x0100;
public const ushort WM_KEYUP = 0x0101;
//Set the active window
[DllImport("user 32.dll")]
public static extern IntPtr SetActiveWindow (IntPtr hWnd);
//sends a windows message to the specified window
[DllImport("user 32.dll")]
public static extern int SendMessage(Int Ptr hWnd, int Msg, uint wParam, int lParam);
public void SendKey(ushort key, IntPtr hWnd)
{
SetActiveWindow (hWnd);
// Control c = this.ActiveCont rol;
// MessageBox.Show (c.Name.ToStrin g());
SendMessage(hWn d, WM_KEYDOWN, key, 0);
// c = this.ActiveCont rol;
// MessageBox.Show (c.Name.ToStrin g());
// SendMessage(hWn d, 0, key, 0);
SendMessage(hWn d.Handle, WM_KEYUP, key, 0);
}
#endregion
private void button3_Click(o bject sender, EventArgs e)
{
SendKey((int)Ke ys.A, comboBox1.Handl e);
}
I have tested SendKeys, Key_evnt and sendinput, they don't satisfy what is needed.
Thanks,
I simply want to send a key (Simulate the keyboard) to a combo box using the Handle of the control.
The below code is not working
public const ushort WM_KEYDOWN = 0x0100;
public const ushort WM_KEYUP = 0x0101;
//Set the active window
[DllImport("user 32.dll")]
public static extern IntPtr SetActiveWindow (IntPtr hWnd);
//sends a windows message to the specified window
[DllImport("user 32.dll")]
public static extern int SendMessage(Int Ptr hWnd, int Msg, uint wParam, int lParam);
public void SendKey(ushort key, IntPtr hWnd)
{
SetActiveWindow (hWnd);
// Control c = this.ActiveCont rol;
// MessageBox.Show (c.Name.ToStrin g());
SendMessage(hWn d, WM_KEYDOWN, key, 0);
// c = this.ActiveCont rol;
// MessageBox.Show (c.Name.ToStrin g());
// SendMessage(hWn d, 0, key, 0);
SendMessage(hWn d.Handle, WM_KEYUP, key, 0);
}
#endregion
private void button3_Click(o bject sender, EventArgs e)
{
SendKey((int)Ke ys.A, comboBox1.Handl e);
}
I have tested SendKeys, Key_evnt and sendinput, they don't satisfy what is needed.
Thanks,
Comment