SendKey and combo box


J

John Dio

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("user32.dll")]

public static extern IntPtr SetActiveWindow(IntPtr hWnd);



//sends a windows message to the specified window

[DllImport("user32.dll")]

public static extern int SendMessage(IntPtr hWnd, int Msg, uint wParam, int lParam);











public void SendKey(ushort key, IntPtr hWnd)

{

SetActiveWindow(hWnd);

// Control c = this.ActiveControl;

// MessageBox.Show(c.Name.ToString());

SendMessage(hWnd, WM_KEYDOWN, key, 0);

// c = this.ActiveControl;

// MessageBox.Show(c.Name.ToString());

// SendMessage(hWnd, 0, key, 0);

SendMessage(hWnd.Handle, WM_KEYUP, key, 0);

}







#endregion



private void button3_Click(object sender, EventArgs e)

{



SendKey((int)Keys.A, comboBox1.Handle);

}





I have tested SendKeys, Key_evnt and sendinput, they don't satisfy what is needed.



Thanks,
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top