Home > Language Reference > System Functions > PeekInteger

PeekInteger

The PeekInteger function retrieves a value of integer type from memory.

Usage

Used in conjunction with External function.

Syntax

var = PeekInteger(<address>,<number_bytes>)

Parameters

<address>. unsigned variable only, address to start reading from. The unsigned variable must be declared at the beginning of the script using Dim function.

<number_bytes>. integer, constant. It can be 1, 2 or 4 (1 byte to read, 2 bytes to read or 4 bytes to read).

Return value

var, 32-bit integer or UNSIGNED for a pointer. If the function fails, script execution stops and no error handling is possible.

See also

PokeInteger
PeekString$
PokeString

Examples

DIM ahandle as UNSIGNED
...
handle=PeekInteger(ahandle,2)


'Script returning the mouse coordinates with the use of PeekInteger and External
'Define memory address
dim addx as unsigned
dim addy as unsigned

'allocate memory starting at addx for the coordinates
'addx will contain the X coordinate
addx=allocate(8)

'addy will contain the Y coordinate
addy=addx+4

'Call the 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 4 bytes from memory at address addx (x position)
pos_x=PeekInteger(addx,4)
'Read 4 bytes from memory at address addy (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 loops for 100 seconds