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"forwindowas #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 timer1, [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", _ xasshort, _ 'define x position yaslong, _ 'define y position result asBoolean Finally, lets end the program and the loop. loop while (x > 250) and (y > 250) timer0 '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"forwindowas #main 'set the cursor position variables x = 500 y = 500 wait [push] 'Set the timer do timer1, [moveCursor] wait [moveCursor] x = x - 1 y = y - 1 calldll #user32, "SetCursorPos", _ xasshort, _ 'define x position yaslong, _ 'define y position result asBoolean loop while (x > 250) and (y > 250) timer0 'CLOSE the Program close #main end
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 Boolean
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