key press and mouse click event

How could i use a key press to do a left mouse button click event for windows programs....?
vbdvlperAsked:
Who is Participating?
 
AzraSoundConnect With a Mentor Commented:
yes i left that out:
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
0
 
hkshijunCommented:
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
 
VoodoomanCommented:
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
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
vbdvlperAuthor Commented:
Thank you.....i was looking to send a mouseclick to Windows in General....although this is an api, can this be done....?  
0
 
vbdvlperAuthor Commented:
Thank you.....i was looking to send a mouseclick to Windows in General....although this is an api, can this be done....?  
0
 
AzraSoundCommented:
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
 
rnshawCommented:
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
 
rnshawCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.