January 1, 2005

WinTask - MousePos

' MousePos - Gives the mouse position on the screen.
' Author: Joe Strazzere

'It calls the Windows API GetCursorPos
'External, structure, allocate, peekinteger, pokeinteger are used.

'When you call Windows API functions, data are often written in
'structures (memory zones). A structure can contain various data (integer,
'string, etc ...). The only way to access those data through WinTask is to use
'System functions Read/Write in memory.

'Windows API GetCursorPos function gives the mouse cursor position on screen. It needs as parameter
'an address within a structure "point". Such a structure is composed of
' 2 integers of 4 bytes each (LONG) with consecutive addresses. At call,
'first one gives X coordinates, second one Y coordinates. Return code
'is 0 if not OK.

'Define memory address
dim addx as unsigned
dim addy as unsigned

'allocate memory address starting at addx (X position address)

'allocate memory address (Y position address)

'Call function through a loop
    'address for structure addx is a parameter for GetCursorPos
    If a <>0 Then
        'Read memory at address addx on 4 bytes (x position)
        'Read memory at addy address on 4 bytes (y position)
        'Display result
        mes$="Cursor X is at : "+str$(pos_x)+" Cursor Y is at : "+str$(pos_y)
        pause 1
Until i=30
'the function is active for 100 seconds