Mouse Move Simulation

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

GetCursorPos(pt);

pt is a variable of TPoint type.

After we got the pointer position, then we can move the pointer in the following way:

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

SetCursorPos(pt.x,pt.y);

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.

MoveMouse.exe

MoveMouse.exe

Source

Source

Did you enjoy this post? Why not leave a comment below and continue the conversation, or subscribe to my feed and get articles like this delivered automatically to your feed reader.
Please notice that comment or question submitted should match the topic. Otherwise, we will delete that comment or question :!:

3 Comments
  1. Wah, mantab kodenya. Pengen sekali bisa mahir Windows API…

  2. 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 :D sudah dibenerin. Terimakasih infonya.

Leave a comment

Before making a comment, make sure you have read the previous comments. Do not make the questions have been asked. Note also the links in the article. Take a look at those links before you create the questions, as it may be an explanation of your questions have been answered in that link.

Comments that do not follow these rules will be deleted!

(required)

(required)



7 − = five

Notify me of followup comments via e-mail. You can also subscribe without commenting.