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 Me!", [push],UL,UL, 10, 10,10
open"An Example""An Example" for windowasas #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 variablesx=
x = 500y=
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
dotimer1,
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 - 1y=y
y = y - 1
calldll #user32,"SetCursorPos", _xasshort, _"SetCursorPos", _
x as short, _ 'define x positionyas
y as long, _ 'define y position
result as long, _'define y positionresultasBoolean
Finally, lets end the program and the loop.
loop while(x(x >250)and(y250) and (y >250)timer250)
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 Me!", [push],UL,UL, 10, 10,10
open"An Example""An Example" for windowasas #main
'set the cursor position variablesx=
x = 500y=
y = 500
wait
[push]
'Set the timer
dotimer
timer 1, [moveCursor]
wait
[moveCursor]
x = x - 1, [moveCursor]wait[moveCursor]x=x
y = y - 1y=y-1
calldll #user32,"SetCursorPos", _xasshort, _"SetCursorPos", _
x as short, _ 'define x positionyaslong, _
y as long, _ 'define y position
resultasas Boolean
loop while(x(x >250)and(y250) and (y >250)timer250)
timer 0
'CLOSE the Program
close #main
end