Blog Archive

Thursday, May 6, 2010

How to use mouse in turbo c program.

This is very interesting to know how to use mouse in your turbo c program. In windows programs mouse support is inbuilt to program. But Turbo c is a 16 bit dos environment ide. So how can you do so in a dos application. We know that Turbo c is itself a dos based program. And it uses mouse,
so it is possible to use mouse in dos application.
You can use mouse in your turbo c program through issue a interrupt 0x33 which is mouse interrupt number in x86 architecture.
int86() function defined in dos.h is used to raise interrupts. But we also need to access and modify CPU registers like ax,bx etc. So there is a union called REGS in dos.h by which we can access CPU registers.
So by the use of this function int86() and union REGS you can write program to use mouse.

Following is an example of turbo c using mouse.

Try this and use mouse in your application. good luck!!!

#define INTIALIZE 1
#define BUTTON_PRESS 5

//unions to acces cpu registers
union REGS output,input;
void main()
//Setting value to intialize mouse device.;
//int86 function function used to raise a interrupt.
//0x33 is mouse interrupt number.
printf("Press left mouse button to exit...");
//loop untile left mouse button is pressed
while(output.x.bx != BUTTON_PRESSED)
//setting register value to check for button press;
//setting register value to check for left mouse button press
//raising interrupt to check for mouse button press


1 comment:

  1. It's amazing...... Thanks a lot.......