Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Emulating Mouse Events 1

Status
Not open for further replies.

BrianJH

Programmer
May 26, 2003
26
US
Hello,

I have a program at work that runs fullscreen. It requires a lot of repetitive mouseclicks, some 6 clicks in a row on different message boxes on the screen for one particular function(sending invoice). These clicks are all in a row and allways in the same spot. I figured out how to move the cursor using:

cursor.position = new point(myX, myY)

6 times, waiting for a second at each click to give the OS time to respond to my would-be mouse clicks.

The only thing that stands in my way is how to emulate a mouse click. I have a feeling one should use the

message.Create(...)

function, but in order to do so I apparently need the handle of the window that the work program is running in. How can I get this handle, or, how can I send a message to windows in general, saying that the mouse has been clicked.

Thank you for your time.

Brian
 
I see my question was overlooked. Is there anything I can add...any more information that I can give to make it easier to answer?
 
I am doing some research to see if there is a way to do what you asked. I happen to have use for the same thing, but so far have had no luck. Just wanted you to know you are not being completely ignored.


Becca

Somtimes, the easy answer is the hardest to find. :)

Still under construction ...
 
Can you tell me why they need to click on 6 different places to send an invoice?

Is it the same everytime?

If not in what way does it vary?

DotNetDoc
M.C.S.D.
---------------------------------------

Tell me and I forget. Show me and I remember. Involve me and I understand.
- Anonymous Chinese Proverb
-----------------------------------
If you can't explain it simply, you don't understand it well enough.
- A. Einstein
 
Hehe, yeah the program isn't very efficient.

1. you press OK after you enter in the appropriate
information.
2. confirm that you are finished with this invoice
3. double-check the address is correct
4. Invoice saved and sent, click OK to send another invoice
5. Choose invoice type: (I allways choose the same type)
6. (here I click on the first text box, but I want the
program to do that

it never varies...it is allways the same and I do 50 or so in a row.

thank you for your replies...hope to figure out a solution.
 
This type of thing can be done but I must ask :

If you are changing the program so that no humnan interaction is necesary for your 6 different questions they why do you still want them to come up. Why dont you just make all of that happen on one click.

It seems you are trying to program around bad design instead of correcting the design.



DotNetDoc
M.C.S.D.
---------------------------------------

Tell me and I forget. Show me and I remember. Involve me and I understand.
- Anonymous Chinese Proverb
-----------------------------------
If you can't explain it simply, you don't understand it well enough.
- A. Einstein
 
The program was not built by ME or by my company...it was contracted out and built by a company that builds these kinds of programs. Since I have to sway and the company will not pay to have it altered, I must make do with what I have...The layout of the boxes is also not designed well so you have to click all over the screen, not in the same area for each box.

So I am trying to program around a bad design, but I cannot edit the design, sorry. I want to build a DIFFERENT program, that runs seperately and moves and clicks the mouse for me.

Furthermore, it isn't a question of WHY I want to do it...it is a question of how. These forums are designed to bring up and solve programming issues, are they not? The entire point of these tech-forum communities is to find solutions to technical problems related to the forum subject (this one being VB.net). It is by sharing knowledge that we gain a better understanding as a whole of these topics. Otherwise, we will find ourselves drowned out and powerless against those large organizations who would choose to exploit us and our lack of ability to understand and manipulate those things which drive our society (as we have done with politics).

My original question still stands. Hopefully I now have given as much information as is needed to get it answered, or find a path or clue to the answer at least.
 
It seems by your tone that I might have offended you with my last post. That was not my intention. If it was taken that way then I apologize. My intention was to steer you towards a correct programming solution instead of having you waste your time. (Time is valuable. Yours as well as mine) Again. If I offended you I apologize.

To acomplish your task you will need to use the windows API

Every form and button have a handle. You would need to be able to get these handles and manipulate the messages sent by the windows API to have it do what you are asking.

This is not an easy task. Which is why I asked the questions above.

I just read and article that shows you how to put a wrapper around the Windows API in VB.Net to intercept messages sent out by windows. Let me look for that article. It might help in this situation. Otherwise let me look into a API function that would acomplish this.

DotNetDoc
M.C.S.D.
---------------------------------------

Tell me and I forget. Show me and I remember. Involve me and I understand.
- Anonymous Chinese Proverb
-----------------------------------
If you can't explain it simply, you don't understand it well enough.
- A. Einstein
 
DotNetDoc ..

Isn't there some way he could creat a macro type program that would 'simulate' the repeditive tasks he otherwise has to perform?

Brian ..

Have you checked to see if there might be a macro program that can help you out?


Becca

Somtimes, the easy answer is the hardest to find. :)

Still under construction ...
 
I ended up downloading a macro program off that site, but the programs aren't very good. To be honest I would still like to know how this can be done...
 
If you want to take the API Approach I would suggest this book.

.Net Framework Solutions
In search of the Lost Win32 API
ISBN 0-7821-4134-x Sybex is the publisher

It goes through using the Win32 API in the .Net Framework.

There are of course others that do the same like Dan Applemans API book for VB6 but this one addresses the .Net Framework.

DotNetDoc
M.C.S.D.
---------------------------------------

Tell me and I forget. Show me and I remember. Involve me and I understand.
- Anonymous Chinese Proverb
-----------------------------------
If you can't explain it simply, you don't understand it well enough.
- A. Einstein
 
I took your hint about the windows API before and have been doing some research. It is actually quite easy to use API functions in your aps and it is very powerful. The best site I found, which also had a new version of the windows API viewer is here:


I will also include how my code looked so people can see it:

Private Declare Function GetKeyboardState Lib "user32.dll" (ByVal lpKeyState() As Byte) As Long
Private Declare Sub keybd_event Lib "user32.dll" ( _
ByVal bVk As Byte, _
ByVal bScan As Byte, _
ByVal dwFlags As Long, _
ByVal dwExtraInfo As Long)

'USE IT LIKE THIS:
public sub useit()
Dim key(255) As Byte
Call GetKeyboardState(key)
'using this code you can see the status of any key, 0-255
Call keybd_event(13, 0, 0, 0)
Call keybd_event(13, 0, KEYEVENTF_KEYUP, 0)
'this should emulate the enter key (you may have to change the 13 into byte, but I think it works this way)
end sub


the great thing about this is it works on truly global scope, and by that I mean with these two functions(for example) you can see what button is being pressed, even if your program is not the focus, and you could press enter in the same way. It is actually very exciting.

I've created a program so my friend and I can code over the internet with each other. I can move his mouse and type in his vb.net envoronment, and I can release control. It is a lot like the windows remote help application, but a lot faster.
 
I am glad it helped. The API is a great tool to learn. You will find many uses for it. :)

DotNetDoc
M.C.S.D.
---------------------------------------

Tell me and I forget. Show me and I remember. Involve me and I understand.
- Anonymous Chinese Proverb
-----------------------------------
If you can't explain it simply, you don't understand it well enough.
- A. Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top