By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,467 Members | 1,448 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,467 IT Pros & Developers. It's quick & easy.

SendKey and combo box

P: n/a
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,
Jul 11 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
SendMessage(hWnd, WM_KEYDOWN, key, 0);
SendMessage(hWnd.Handle, WM_KEYUP, key, 0);

You'll have to create the corresponding lParam and wParam.
Only "key-code" will not do.
http://msdn.microsoft.com/en-us/libr...80(VS.85).aspx
Try this out:
SendMessage(hWnd, WM_KEYDOWN, key, 0x220001)
SendMessage(hWnd, WM_KEYUP, key, 0xC0220001)

Derived from:
http://bytes.com/forum/thread124681.html

--
Happy Hacking,
Gaurav Vaish | http://dwt.sourceforge.net
http://blogs.mastergaurav.com | http://eduzine.edujini-labs.com
--------------------------------


Jul 11 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.