Display the mouse coordinates
This script displays the mouse coordinates while you move the mouse.
You can find the corresponding script file under Script_Examples, sub-directory of scripts.
' Gives the mouse position on the screen.
'It calls the Windows API GetCursorPos
'External, structure, allocate, peekinteger, pokeinteger are used.
'When you call Windows API functions, data is often written in
'structures (memory zones). A structure can contain various data (integer,
'string, etc ...). The only way to access this data with WinTask is to use
'System functions which Read/Write in memory.
'The Windows API GetCursorPos function gives the mouse cursor position.
'It takes a structure parameter containing an address.
'The structure is composed of 2 integers of 4 bytes each (LONG)
'with consecutive addresses.
'The first address is the X coordinate, the second address is the Y coordinate.
'The Return code is 0 if the call is not successful.
'Define memory address
dim addx as unsigned
dim addy as unsigned
'allocate memory address starting at addx (X position address)
addx=allocate(8)
'allocate memory address (Y position address)
addy=addx+4
'Call function in a loop
repeat
'address for structure addx is a parameter for GetCursorPos
a=External("user32.dll","GetCursorPos",addx)
if a <>0 then
'Read memory at address addx on 4 bytes (x position)
pos_x=PeekInteger(addx,4)
'Read memory at addy address on 4 bytes (y position)
pos_y=PeekInteger(addy,4)
'Display result
mes$="Cursor X is at : "+str$(pos_x)+"\n\Cursor Y is at : "+str$(pos_y)
msgframe(mes$,1)
pause 1
endif
until i=100
'the function is active for 100 seconds