473,320 Members | 1,862 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,320 software developers and data experts.

Using SendMessage to simulate the ENTER key press

I have an app that keeps popping up a windows with a 'Yes' or 'OK' button
on it. I am trying to write a little app that automates hitting the enter
key so I don't have to do it myself.

I used the FindWindow method to get a handle of the window and then issued:
SendMessage(hwnd, 273, 0, IntPtr.Zero)

to send an ENTER key to it but it didn't work.

If I need to get the handle of the 'OK' button, how do I do it? (How do you
loop through the buttons and find the handle you need?) If I just need to
send an ENTER key to the window, is the method above correct. hwnd is the
handle of the popup window and 273 is the decimal value for ENTER (0x111).

Thanks.

John Dalberg
Sep 26 '06 #1
3 29756
John,

You should not use SendMessage to simulate user input. Rather, take a
look at the SendInput API function to simulate user input (key presses,
mouse input, etc, etc).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"John Dalberg" <no****@nospam.ssswrote in message
news:20*******************@newsreader.com...
>I have an app that keeps popping up a windows with a 'Yes' or 'OK' button
on it. I am trying to write a little app that automates hitting the enter
key so I don't have to do it myself.

I used the FindWindow method to get a handle of the window and then
issued:
SendMessage(hwnd, 273, 0, IntPtr.Zero)

to send an ENTER key to it but it didn't work.

If I need to get the handle of the 'OK' button, how do I do it? (How do
you
loop through the buttons and find the handle you need?) If I just need to
send an ENTER key to the window, is the method above correct. hwnd is the
handle of the popup window and 273 is the decimal value for ENTER (0x111).

Thanks.

John Dalberg

Sep 26 '06 #2
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote:
John,

You should not use SendMessage to simulate user input. Rather, take
a look at the SendInput API function to simulate user input (key presses,
mouse input, etc, etc).

Why shouldn't I use SendMessage?

>
Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"John Dalberg" <no****@nospam.ssswrote in message
news:20*******************@newsreader.com...
I have an app that keeps popping up a windows with a 'Yes' or 'OK'
button
on it. I am trying to write a little app that automates hitting the
enter key so I don't have to do it myself.

I used the FindWindow method to get a handle of the window and then
issued:
SendMessage(hwnd, 273, 0, IntPtr.Zero)

to send an ENTER key to it but it didn't work.

If I need to get the handle of the 'OK' button, how do I do it? (How do
you
loop through the buttons and find the handle you need?) If I just need
to send an ENTER key to the window, is the method above correct. hwnd
is the handle of the popup window and 273 is the decimal value for
ENTER (0x111).

Thanks.

John Dalberg
Sep 26 '06 #3
John,

When you click a key on the keyboard, it sends a key down, a key press,
and a key up message. You are only sending one message and it doesn't look
right to the code that is trying to interpret it.

If you use SendInput, it will send all the appropriate windows messages
associated with a key click.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"John Dalberg" <no****@nospam.ssswrote in message
news:20*******************@newsreader.com...
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote:
>John,

You should not use SendMessage to simulate user input. Rather, take
a look at the SendInput API function to simulate user input (key presses,
mouse input, etc, etc).


Why shouldn't I use SendMessage?

>>
Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"John Dalberg" <no****@nospam.ssswrote in message
news:20*******************@newsreader.com...
>I have an app that keeps popping up a windows with a 'Yes' or 'OK'
button
on it. I am trying to write a little app that automates hitting the
enter key so I don't have to do it myself.

I used the FindWindow method to get a handle of the window and then
issued:
SendMessage(hwnd, 273, 0, IntPtr.Zero)

to send an ENTER key to it but it didn't work.

If I need to get the handle of the 'OK' button, how do I do it? (How do
you
loop through the buttons and find the handle you need?) If I just need
to send an ENTER key to the window, is the method above correct. hwnd
is the handle of the popup window and 273 is the decimal value for
ENTER (0x111).

Thanks.

John Dalberg

Sep 26 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: bill ramsay | last post by:
Dear all. I am using an existing hodge-podge of an application that runs on top of an Access database. This application dials up customer equipment, handshakes then downloads/uploads various...
5
by: Mark Overstreet | last post by:
I am trying to click a button in another window and I have it's hWnd value so I was trying to use Send message. Here is my code but it doesn't work as expected... response =...
1
by: Laszlo Henning | last post by:
I would like to make it possible to jump from a field to another field (the next one in the tab index) using enter also and not only tab. How can this be done either without onkeydown or with it. ...
3
by: Rob | last post by:
Hi all, I am having trouble converting the code below (found on http://vbnet.mvps.org/index.html?code/core/sendmessage.htm) into a format that will work using vb .NET. Can anyone have a look...
18
by: Lars Netzel | last post by:
Hello! Thanx to this newgroup I have finally, with the help of you guys, gotten this to work halfway.. but the final action is still not working, clicking the "Button2" thru SendMessage(). ...
0
by: neonspark | last post by:
I'm buidling some simple macro functionality for my app so the users can record a sequence of keyboard inputs and replay them reliably via some menu. Originally, I used: protected override bool...
2
by: jonathan184 | last post by:
Hi I am try to create a script to login EMS admin tool *JMS* Now the admin account has a blank password. so if i login normal usually i type this: i press enter username(ADMIN) prompt - i...
3
by: =?Utf-8?B?SmFrb2IgTGl0aG5lcg==?= | last post by:
I have two sets of search criteria on my page. They are placed inside two DIV tags made visible/hidden by a client script. In each DIV tag I have a LinkButton that performs the search from each...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.