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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to simulate a mouse click in VFP

API Functions

How to simulate a mouse click in VFP

by  Mike Gagnon  Posted    (Edited  )
Here is an example on how to simulate a left mouse click and recuperating the confirmation of that action.
Code:
#Define MOUSEEVENTF_RESET 1
#Define MOUSEEVENTF_LEFTDOWN  2
#Define MOUSEEVENTF_LEFTUP 4
#Define MOUSEEVENTF_RIGHTDOWN  8
#Define MOUSEEVENTF_RIGHTUP  16
#Define MOUSEEVENTF_MIDDLEDOWN 32
#Define MOUSEEVENTF_MIDDLEUP 64
#Define MOUSEEVENTF_MIDDLEUP_WHEEL_MOVED 128
#Define VK_LBUTTON  1
#Define VK_RBUTTON  2
Declare Integer GetAsyncKeyState In user32 Integer vKey
Declare Integer GetKeyState In user32 Integer vKey
Declare Integer SetKeyboardState In user32 String @lpKeyState
Declare mouse_event In user32.Dll Long,Long,Long,Long,Long
Clear
Local cBuffer, nIndex, lStop
lStop=.F.
* clearing input-state table
cBuffer = Replicate(Chr(0), 256)
= SetKeyboardState(@cBuffer)
DoEvents
Do While Not lStop
* simulating time-consuming activity
	Create Cursor cs (num N(10))
	For nIndex=1 To 1000
		Insert Into cs Values (nIndex)
	Endfor
	?? "."
	lcTest=mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,288,0)
	If GetKeyState(VK_LBUTTON) <> 0
		? "Left button pressed."
		Exit
	Endif
	If GetKeyState(VK_RBUTTON) <> 0
		? "Right button pressed."
		Exit
	Endif
Enddo
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top