Lately I love to play the Dragons of Altantis game on Facebook. Firstly I play just for a whim, but gradually become excited. But there are things that sucks from this game, that we should wasting time just to play this game.
We can only do a job in once upon a time. And the job sometimes takes so long until many hours. Unfortunately, if we leave the computer for too long, then this game will require attention from us. So, this game is actually designed to waste our time in vain.
As a programmer, I think there might be a way to trick this game, so the game was thought that we still play this game, but it is actually a program that we run that play it. While we actually are leaving our computer to do other things.
The first idea that appears is to make a program to move the mouse pointer. I plan to make software that moves the mouse in circle. First moves to the right, then down, then to the left, and the last is upwards back to the starting position. Thus, the mouse pointer will continue moving without end until we stop the action of this software.
To be able to move the mouse, first we need to know the position of the mouse pointer. Function to find the position of the mouse pointer is
pt is a variable of TPoint type.
After we got the pointer position, then we can move the pointer in the following way:
- To move to the right, then we add the value of X
- To move down, then we add the value of Y
- To move to the left, then we subtract the value of X
- To move to the top, then we subtract the value of Y
The last step is putting the position of the pointer to the position that we modify in a manner above. Function to place the position of the mouse pointer is
In order to make the mouse pointer moves in accordance with the above plan, then I create a variable that I use to determine the direction of motion of the mouse. I named this variable PosX. Then I must also determine how large the movement. To simplify the design, I determined that the horizontal and vertical movement size are equal. I determine this size using variable named SQSize.
Using these two variables, we can determine the direction of motion by dividing PosX with SQSize. If the result is 0, then the movement is to the right, if 1 is downward, if 2is to the left, if 3 is upward, and if it is 4, then this shows that one period of the movement have been exceeded. Therefore, if the result is 4, beside we move the mouse pointer to the right, we also returns to the value of PosX to the starting position again.
The entire process above can be conducted with a procedure such as the following:
procedure MoveMousePointer; var pt:TPoint; begin GetCursorPos(pt); case(PosX div SQSize)of 0:begin inc(pt.x); inc(PosX) end; 1:begin inc(pt.y); inc(PosX) end; 2:begin dec(pt.x); inc(PosX) end; 3:begin dec(pt.y); inc(PosX) end; 4:begin inc(pt.x); PosX:=1; end; end; SetCursorPos(pt.x,pt.y); end;
The procedure MoveMousePointer then called every certain interval using the timer.
This way is of course not the only trick. But we can at least use the problems we face as a medium for learning.
If you just want to use this software, you can download software that I name it MoveMouse.exe which is compiled using Lazarus. Whereas if you are also interested to learn how the software is set up, you can download source that you can compile it using Delphi or Lazarus.
I love the small size software. Therefore, I form this software without VCL (Delphi) or LCL (Lazarus), but only using Windows API.
Wah, mantab kodenya. Pengen sekali bisa mahir Windows API…
Posting yang menarik mas Sulhan. Lama tidak menyentuh Delphi lagi. Masih ingat saya kan? ^_^
Oya, link untuk .EXE broken.
Tentu masih ingat lah. Apakabar? Oia, maaf, ternyata nama filenya salah 😀 sudah dibenerin. Terimakasih infonya.