mouse programming

Views:
 
Category: Education
     
 

Presentation Description

you can easily learn mouse programming with this ppt in few Hours

Comments

Presentation Transcript

Mouse Programming With “C” or “C++”:

Mouse Programming With “C” or “C++” Submitted to :- Submitted By :- Mahesh Soni Mrs. Sonal Agrrawal Medi-Caps Institute of Technology and Management

Fundamental knowledge:-:

Fundamental knowledge:- You know how to tell a mouse do anything. Each device has a unique port which is a hexadecimal value and value is designed to be machine independent . Mouse has port attached to it 0X33 . We also make use of address registers. These are basically Union of type REGS defined in dos.h . Just remember we use two register to communicate to a device driver using two registers one for input and one for output .

Slide 3:

AX Register:- We can access various mouse functions using different values of AX input Register and passing those values to mouse port using a interrupt . The Functions are listed below - Here AX, BX, CX and DX are members of Union REGS .

Slide 4:

Input Function Performed Returns AX=0 Get Mouse Status Output AX Value = FFFFh if mouse support is available. Output AX Value = 0 if mouse support is not available. AX=1 Show Mouse Pointer Nothing AX=2 Hide Mouse Pointer Nothing AX=3 Mouse Position CX = Mouse X Coordinate DX = Mouse Y Coordinate AX=3 Mouse Button Press BX = 0 No Key Is Pressed ,BX = 1 Left Button is Pressed, BX = 2 Right Button is Pressed ,BX = 3 Centre Button is Pressed

Slide 5:

Ax =7 Set Horizontal Limit Nothing Ax =8 Set Vertical Limit Nothing

Slide 6:

#include <dos.h> //Header file for mouse detecting union REGS in, out; //REGS is union void detectmouse ( ) //function for mouse detection { in.x.ax = 0; int86 (0X33,&in,&out); //invoke interrupt if (out.x.ax == 0) cout<<"\nMouse Fail To Initialize"; else cout<<"\nMouse Succesfully Initialize"; } void main ( ) { detectmouse (); //function calling getch (); } DETECT MOUSE :-

Slide 7:

Now first we show mouse on screen . Mouse works both in text mode and graphic mode. In text mode it looks like a square while in graphics mode it looks like a pointer. Here is a screen shot for Text Mode & Graphics Mode. Showing Mouse:-

Slide 8:

#include <dos.h> union REGS in, out; void detectmouse () { in.x.ax = 0; int86 (0X33,&in,&out); if (out.x.ax == 0) cout<<"\nMouse Fail To Initialize"; else cout<<"\nMouse Succesfully Initialize"; } void showmousetext () { in.x.ax = 1; //Input int86 (0X33,&in,&out); //Invoke intrrupt } void main () { detectmouse (); showmouse (); getch (); } Showing Mouse Pointer text mode :-

Slide 9:

#include <dos.h> union REGS in, out; void detectmouse () { in.x.ax = 0; int86 (0X33,&in,&out); if (out.x.ax == 0) cout<<"\nMouse Fail To Initialize"; else cout<<"\nMouse Succesfully Initialize"; } void showmousegraphic () { int gdriver = DETECT, gmode; initgraph(&gdriver, &gmode, "c:\\tc\\bgi"); in.x.ax = 1; //Input int86 (0X33,&in,&out); //Invoke intrrupt } void main () { detectmouse (); showmousegraphic (); getch (); } Showing Mouse in Graphics mode:-

Slide 10:

Mouse Hiding :- void hidemouse ( ) { in.x.ax = 2; int86 (0X33,&in,&out); }

Slide 11:

void detect () { while ( !kbhit () ) { in.x.ax = 3; int86 (0X33,&in,&out); if (out.x.bx == 1) cout<<"Left"; if (out.x.bx == 2) cout<<"Right"; delay (200); } } /* Otherwise due to quick computer response 100s of words will get print */ Detect Mouse Key:-

Slide 12:

Detecting coordinate :- void detect () { while (!kbhit () ) { int x, y; in.x.ax = 3; int86 (0X33,&in,&out); x = out.x.cx; y = out.x.dx; if (out.x.bx == 1) { cout<<"\n Left \n"; } if (out.x.bx == 2) { cout<<"\n Right \n”; } cout<<“X= "<<x<<"\n Y= "<<y; delay (200); } }

Slide 13:

void restrict (int x1 ,int y1 ,int x2 , int y2) { in.x.ax = 7; in.x.cx = x1; in.x.dx = x2; int86 (0X33,&in,&out); in.x.ax = 8; in.x.cx = y1; in.x.dx = y2; int86 (0X33,&in,&out); } Mouse Restrict :-