473,396 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

SendKey and combo box

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
1 3123
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: vgrssrtrs | last post by:
<html> <head> <script language="JavaScript"> <!-- /* *** Multiple dynamic combo boxes *** by Mirko Elviro, 9 Mar 2005 *** ***Please do not remove this comment
3
by: baileystuff | last post by:
I have an issue where I have three Cases that SHOULD act the same but don't. If you look at the code below you will see that the general premise is to open a MSWord template and then use SendKey...
3
by: hmiller | last post by:
Hey everyone, I am having a hell of a time trying to set this menu system up. Here's what I'm trying to do. Combo Box One; is populated by names under properties "row source" "Phase 1"...
2
by: kiranmn75 | last post by:
I want to dynamically populate a combo box through javascript. Data is coming from a array. Sometimes data list may contain items in excess of 2000. Explorer takes more than 5 seconds to...
0
by: angelsoft | last post by:
How to send Microsoft Natural Keyboard keys with sendkey method ej. Windows Logo: Start menú, Windows Logo+R: Run dialog box
0
by: Gunawan | last post by:
Can someone help me how to write console application to sendkey c:>sendkey {ALT}+{TAB} simulate key ALT+TAB TIA Gun
7
by: JV | last post by:
I am running a large Access 2000 application (installed using Access Runtime) that uses many VB SendKeys, primarily to expand combo boxes On Enter. When trying to run it on Vista I get a...
6
by: Dave | last post by:
I want to put the information that the user selects in my combo boxes into a subform that lies on the same form as the combo boxes. Thanks for your help already, Dave
12
by: DAHMB | last post by:
I have a form that calls up a report in the form I have several date fields that have date input masks. I have created a cancel button as: Private Sub btnCancel_Click() On Error GoTo...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.