Here's an example using mouse_event which is a pre XP function call in USER32.dll. It should still work with XP but you might want to lookup which function has replaced it. Basically, it moves the pointer until it reaches a blue square. Once it reaches the blue square, it sends a left click - it uses DBC's mouseclick() command to check if it has been set to 1 (indicating a left mouse click has occured). You then press ENTER and it will send a leftbutton up - again I check this with DBC's mouseclick() to see that it returns zero. To make sure the mouse functions on it's own regardless of the api commands, I have you right click to restart the demo.
remstart
==============================================================
= Title : Mouse input windows API
= Author : latch
= Date : 07/12/2007
= Update :
= Version:
==============================================================
Comments Example of how to use win api for sending mouse events
without having to actually use the mouse
==============================================================
remend
rem =============================================================
rem = SET UP DISPLAY
rem =============================================================
autocam off
set display mode 800,600,32
sync on
sync rate 60
set window on
maximize window
rem =============================================================
rem = MAIN
rem =============================================================
gosub _dlls
rem set flags for mouse_event
dwFlags=MOUSEEVENTF_MOVE
rem set initial position of mouse
call dll user32,"mouse_event",dwFlags,-400,20,0,0
rem make a box to click on
ink 255,0
box 300,300,400,400
do
rem move mouse pointer around with win api call
while point(mousex(),mousey()) <> 255
dx=10
dy=rnd(5)
call dll user32,"mouse_event",dwFlags,dx,dy,0,0
`wait 10
sync
endwhile
rem indicate that the mouse is left clicking
call dll user32,"mouse_event",dwFlags | MOUSEEVENTF_LEFTDOWN,0,0,0,0
if mouseclick()=1
repeat
text 300,200,"The left button has been automatically clicked!"
text 300,220,"Press ENTER to send release command"
sync
until returnkey()=1
rem release left mouse button
call dll user32,"mouse_event",mouseeventf_leftup,0,0,0,0
wait 100
if mouseclick()=0
repeat
text 300,240,"Left button has been automatically released"
text 300,260,"Right click to run again"
sync
until mouseclick()=2
cls
rem set flags for mouse_event - send mouse movement
dwFlags=MOUSEEVENTF_MOVE
rem set initial position of mouse
call dll user32,"mouse_event",dwFlags,-400,-80,0,0
rem make a box to click on
ink 255,0
box 300,300,400,400
endif
endif
sync
loop
end
rem =============================================================
rem = SUBROUTINES - PROCEDURES
rem =============================================================
_constants:
rem mouse event constants
MOUSEEVENTF_MOVE = 1
MOUSEEVENTF_LEFTDOWN = 2
MOUSEEVENTF_LEFTUP = 4
MOUSEEVENTF_RIGHTDOWN = 8
MOUSEEVENTF_RIGHTUP = 16
MOUSEEVENTF_MIDDLEDOWN = 32
MOUSEEVENTF_MIDDLEUP = 64
MOUSEEVENTF_WHEEL = 2048
MOUSEEVENTF_ABSOLUTE = 32768
return
`----------------------------------------------------------------
_dlls:
user32=1
load dll "user32.dll",user32
remstart
mouse_event function parameters
VOID mouse_event(
DWORD dwFlags,
DWORD dx,
DWORD dy,
DWORD dwData,
ULONG_PTR dwExtraInfo
);
remend
gosub _constants
return
Enjoy your day.