Solved

key press and mouse click event

Posted on 2000-03-17
8
347 Views
Last Modified: 2010-05-02
How could i use a key press to do a left mouse button click event for windows programs....?
0
Comment
Question by:vbdvlper
  • 2
  • 2
  • 2
  • +2
8 Comments
 

Expert Comment

by:hkshijun
ID: 2628869
The system cannot distinguish left or right button clicked, just click event.
Just call Command1_Click in sub of Command1_KeyPress may be OK for you.
0
 
LVL 5

Expert Comment

by:Voodooman
ID: 2628870
if you want to send a mouse click to a VB Program Call the MouseDown event of the Control you want to click on

Call F_MyForm_MouseDown 1,0,0,0

You can leave out Call if you want

F_Myform is the name of the form.

F_Myform_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)


if you want to send a mouse click to Windows in General - another program use the API - worth a lot more than 20 points to show you how

Good Luck


Voodooman

0
 

Author Comment

by:vbdvlper
ID: 2628932
Thank you.....i was looking to send a mouseclick to Windows in General....although this is an api, can this be done....?  
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:vbdvlper
ID: 2629077
Thank you.....i was looking to send a mouseclick to Windows in General....although this is an api, can this be done....?  
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2629276
Put this in your module:
Declare Sub mouse_event Lib "user32.dll" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)

These are all constants that can be used:
Const MOUSEEVENTF_ABSOLUTE = &H8000
Const MOUSEEVENTF_LEFTDOWN = &H2
Const MOUSEEVENTF_LEFTUP = &H4
Const MOUSEEVENTF_MIDDLEDOWN = &H20
Const MOUSEEVENTF_MIDDLEUP = &H40
Const MOUSEEVENTF_MOVE = &H1
Const MOUSEEVENTF_RIGHTDOWN = &H8
Const MOUSEEVENTF_RIGHTUP = &H10
Const MOUSEEVENTF_WHEEL = &H80
Const MOUSEEVENTF_XDOWN = &H100
Const MOUSEEVENTF_XUP = &H200
Const WHEEL_DELTA = 120
Const XBUTTON1 = &H1
Const XBUTTON2 = &H2


If you just want to do a left mouse button press then put this code in your keypress event that will trigger it:

mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0

or just use the defined number constant:
mouse_event &H2, 0, 0, 0, 0
0
 

Expert Comment

by:rnshaw
ID: 2629385
Was just gonna send you the url to MS site... but AzraSound already did all the work for you, better give him/her the points :) But here is some more info

http://msdn.microsoft.com/library/psdk/winui/mousinpt_1d2s.htm

note that this is now obsolete, use SendInput instead, but its your call, this one still works :)

HTH

Ryan

0
 

Expert Comment

by:rnshaw
ID: 2629445
BTW....
you need to do a MouseDown and a MouseUp event to get what is a mouse "Click", it holds the mouse down if you only call MouseDown ( enables drag :)  )
0
 
LVL 28

Accepted Solution

by:
AzraSound earned 20 total points
ID: 2629464
yes i left that out:
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB 6 error 5 in windows 10 but not in XP 7 67
Excel Automation VBA 19 104
transition to visual .net from vb6 5 64
Assign a value in Excel V-Basic 3 30
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question