Mesran

Hanya ingin berbagi kebaikan dan mendapatkan kebaikan yang lain.

Tips : Mendeteksi Mouse pada C/C++

😀 Searching searching dapat nih program, lumayan keren juga nih saya ambil sumbernya dari sini nih.

Interrupt Service Purpose
51 0 Reset mouse and get status

Call with AX = 0

Returns:  AX = FFFFh If mouse support is available

Ax = 0 If mouse support is not available

51 1 Show mouse pointer

Call with AX = 1

Returns: Nothing

51 2 Hide mouse pointer

Call with AX = 2

Returns: Nothing

51 3 Get mouse position and button status

Call with AX = 3

Returns: BX = mouse button status

Bit   Significance

0     button not pressed

1     left button is pressed

2     right button is pressed

3     center button is pressed

CX = x coordinate

DX = y coordinate

51 4 Set mouse pointer position

Call with AX = 4

CX = x coordinate

DX = y coordinate

Returns: Nothing

51 7 Set horizontal limits for pointer

Call with AX = 7

CX = minimum x coordinate

DX = maximum x coordinate

Returns: Nothing

51 8 Set vertical limits for pointer

Call with AX = 8

CX = minimum y coordinate

DX = maximum y coordinate

Returns: Nothing

Nih program lengkapnya :

#include<graphics.h>
#include<stdio.h>
#include<conio.h>
#include<dos.h>
union REGS in,out;

int callmouse(){

in.x.ax=1;
int86(51,&in,&out);
return 1;

}
void mouseposi(int &xpos,int &ypos,int &click){

in.x.ax=3;
int86(51,&in,&out);
click=out.x.bx;
xpos=out.x.cx;
ypos=out.x.dx;

}
int mousehide(){

in.x.ax=2;
int86(51,&in,&out);
return 1;

}
void setposi(int &xpos,int &ypos){

in.x.ax=4;
in.x.cx=xpos;
in.x.dx=ypos;
int86(51,&in,&out);

}
int main(){

int x,y,cl,a,b;
clrscr();
int g=DETECT,m;
initgraph(&g,&m,”c:\tc\bgi”);
a=100;
b=400;
setposi(a,b);
callmouse();
do {
mouseposi(x,y,cl);
gotoxy(10,9);
printf(“\n\tMouse Position is: %d,%d”,x,y);
printf(“\n\tClick: %d”,cl);
printf(“\n\tPress any key to hide the mouse”);
}while(!kbhit());
getch();
mousehide();
printf(“\n\n\tPress any key to Exit”);
getch();
closegraph() ;
return(0);

}

Nih hasilnya :

 

 

 

 

 

 

 

Bagaimana? Bisa!

Advertisements

Filed under: C/C++ Tips,

2 Responses

  1. laurentinus says:

    pak…
    program yang bapak kasih termasuk dalam materi pelajaran ari ni pak……??

Terima kasih telah memberikan komentar anda.

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Archives Per Tahun

%d bloggers like this: