Older Version Newer Version

StPendl StPendl Jan 2, 2011

**//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: [[code format="lb"]] '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 [[code]] Ok, now that our window is opened, lets declare our two variables; X and Y (yes it’s that simple) [[code format="lb"]] 'set the cursor position variables x = 500 y = 500 wait [[code]] Now, to make our program interesting, we will make a simple Do Loop with a timer to move the cursor slowly (and not instantly). [[code format="lb"]] [push] 'Set the timer do timer 1, [moveCursor] wait [moveCursor] [[code]] We’ve arrived to the fun part. Now, we will make the simple API call (user32) that will change the position of our cursor. [[code format="lb"]] x = x - 1 y = y - 1 calldll #user32, "SetCursorPos", _ x as short,long, _ 'define x position y as long, _ 'define y position result as long [[code]] Finally, lets end the program and the loop. [[code format="lb"]] loop while (x > 250) and (y > 250) timer 0 'CLOSE the Program close #main end [[code]] Here’s our demo: [[code format="lb"]] '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,long, _ 'define x position y as long, _ 'define y position result as long loop while (x > 250) and (y > 250) timer 0 'CLOSE the Program close #main end [[code]]