Akhir-akhir ini saya suka bermain game Dragons of Altantis di Facebook. Awalnya hanya iseng, tetapi lama-kelamaan menjadi senang. Akan tetapi ada hal yang menyebalkan dari game ini, yaitu bahwa kita harus membuang waktu yang lama hanya untuk bermain game ini.
Kita hanya bisa melakukan sebuah pekerjaan dalam sekali waktu. Dan pekerjaan itu terkadang memakan waktu yang begitu lama sampai berjam-jam. Sayangnya, jika kita meninggalkan komputer terlalu lama, maka game ini akan meminta perhatian dari kita. Jadi, game ini benar-benar game yang dirancang untuk membuang waktu kita dengan sia-sia.
Sebagai seorang programmer, saya berpikir mungkin ada cara untuk membohongi game ini, sehingga game ini mengira bahwa kita masih memainkan game ini, tetapi sebenarnya program yang kita jalankan yang memainkannya. Sedangkan kita sebenarnya pergi meninggalkan komputer untuk melakukan hal lain.
Gagasan yang pertama muncul adalah membuat program yang akan menggerakkan pointer mouse. Saya merencanakan untuk membuat software yang menggerakkan mouse dengan berputar. Pertama bergerak ke kanan, kemudian turun, kemudian ke kiri, dan terakhir naik lagi menuju posisi awal. Dengan demikian, pointer mouse akan terus bergerak tanpa akhir sampai kita menghentikan aksi dari software ini.
Untuk bisa menggerakkan mouse, pertama kita harus mengetahui posisi pointer mouse. Fungsi untuk mengetahui posisi pointer mouse adalah
GetCursorPos(pt);
pt adalah variabel bertipe TPoint.
Setelah kita mendapat posisi pointer, maka kita bisa menggerakkan pointer dengan cara sebagai berikut:
- Untuk menggerakkan ke kanan, maka kita tambah nilai X
- Untuk menggerakkan ke bawah, maka kita tambah nilai Y
- Untuk menggerakkan ke kiri, maka kita kurangi nilai X
- Untuk menggerakkan ke atas, maka kita kurangi nilai Y
Langkah terakhir adalah menempatkan posisi pointer pada posisi yang telah kita modifikasi dengan cara di atas. Fungsi untuk menempatkan posisi pointer mouse adalah
SetCursorPos(pt.x,pt.y);
Agar pointer mouse bergerak sesuai dengan rencana di atas, maka saya membuat sebuah variabel yang saya gunakan untuk menentukan kemana arah gerakan mouse. Variabel tersebut saya beri nama PosX. Kemudian saya juga harus menentukan seberapa besar pergerakan tersebut. Untuk menyederhanakan rancangan, saya menentukan bahwa gerakan vertikal maupun horisontal ukurannya sama. Ukuran ini saya tentukan dengan variabel bernama SQSize.
Dari dua variabel tersebut, kita bisa menentukan kemana arah gerakan dengan membagi PosX dengan SQSize. Jika hasilnya 0, maka gerakan yang dilakukan adalah ke kanan, jika 1 ke bawah, jika 2, ke kiri, jika 3 ke atas, dan jika 4, maka hal ini menunjukkan bahwa satu periode gerakan terlah terlampaui. Oleh karena itu, jika hasilnya 4, selain kita menggerakkan pointer mouse ke kanan, kita juga mengembalikan nilai PosX ke posisi awal lagi.
Keseluruhan proses di atas bisa kita laksanakan dengan sebuah prosedur seperti berikut:
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;
Prosedur MoveMousePointer ini kemudian dipanggil setiap interval tertentu menggunakan timer.
Cara ini tentu saja bukan satu-satunya trik. Akan tetapi setidaknya kita bisa menggunakan masalah yang kita hadapi sebagai media untuk belajar.
Jika Anda hanya ingin menggunakan software ini, Anda bisa mendownload software yang saya namai MoveMouse.exe yang saya kompilasi menggunakan Lazarus. Sedangkan jika Anda juga tertarik untuk mempelajari bagaimana software ini dibentuk, Anda bisa mendownload source yang bisa Anda kompilasi menggunakan Delphi maupun Lazarus.
Saya menyukai software dengan ukuran yang kecil. Oleh karena itu, software ini saya bentuk tanpa menggunakan VCL (Delphi) atau LCL (Lazarus), melainkan saya susun menggunakan Windows API.
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:
- 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
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.

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.