StPendl StPendl Jan 2, 2011 - "simplified page"


Changing the cursor's position

By Daniel49

You can add a little more help for the user by setting the cursor’s position at will in a Liberty Basic program. This function can be used in tutorials and guides. Now, you’re probably wondering how the heck you can do this! Well, it is pretty simple.

First, open the window:

'This example demonstrates how to use user32 to set the ‘cursor at a given position
'It is a function that may come in useful in tutorial and ‘guided tours
'Use at will
 
'Open the window
button #main.exit, "Push Me!", [push], UL, 10, 10
open "An Example" for window as #main

Ok, now that our window is opened, lets declare our two variables; X and Y (yes it’s that simple)

'set the cursor position variables
x = 500
y = 500
wait

Now, to make our program interesting, we will make a simple Do Loop with a timer to move the cursor slowly (and not instantly).

[push]
'Set the timer
do
timer 1, [moveCursor]
wait
[moveCursor]

We’ve arrived to the fun part. Now, we will make the simple API call (user32) that will change the position of our cursor.

x = x - 1
y = y - 1
calldll #user32, "SetCursorPos", _
x as short, _ 'define x position
y as long, _ 'define y position
result as long

Finally, lets end the program and the loop.

loop while (x > 250) and (y > 250)
timer 0
 
'CLOSE the Program
close #main
end



Here’s our demo:

'This example demonstrates how to use user32 to set the ‘cursor at a given position
'It is a function that may come in useful in tutorial and ‘guided tours
'Use at will
 
'Open the window
button #main.exit, "Push Me!", [push], UL, 10, 10
open "An Example" for window as #main
 
'set the cursor position variables
x = 500
y = 500
wait
[push]
'Set the timer
do
timer 1, [moveCursor]
wait
[moveCursor]
x = x - 1
y = y - 1
calldll #user32, "SetCursorPos", _
x as short, _ 'define x position
y as long, _ 'define y position
result as Boolean
loop while (x > 250) and (y > 250)
timer 0
 
'CLOSE the Program
close #main
end