mouse under DOS using BC++4.52

Posted on 1998-10-27
Last Modified: 2010-08-05
I'm trying to figure out how to use a mouse under DOS when programming in BC4.52
The help files are pretty quite about this topic, so I was hoping to find someone who could give me the basic code to query the mouse for x & y coordinates and the buttonstate.
Tnx in advance.
1. I need it both in console and graphical environment.
2. I used to use the INT68 way of doing this, but it seems when switching to a 32bit environment it doesn't work anymore (working in dosboxes under NT)
Question by:tofke
  • 2
LVL 22

Expert Comment

ID: 1176336
Are you programming in DOS?  You say you've switched to a 32 bit environment.  What do you mean by that?  

Note that a win 32 console is not a DOS program.  It is a windows program.  You can use the regular windows API from a win32 console.  Thus you can use GetCursorPosition() to find the mouse cursor position.
LVL 22

Expert Comment

ID: 1176337
Sorry, that should be GetCursorPos()

Also you can use GetKeyState() with VK_LBUTTON, VKMBUTTON, and VK_RBUTTON to get the state of the mouse buttons.  

All this applies only if you are in a win32 console application.  From a DOS application you can use the mouse

Accepted Solution

LucJanssens earned 200 total points
ID: 1176338
It is very easy to use the mouse under Borland C++ 4.52.
You must open a new project, than select as platform : DOS (standard).  (Don't change the other options).  A new project is

You can use the following code: (normally I place the Muis class
in a seperated header file):

You can cut/paste the following code right into you cpp file (generated for your new project), press ctrl f9.  I tested this.
It works.

Good luck

Luc Janssens
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
#define _NAIVE_DOS_REGS  // nodig voor DJGPP compiler (voor int86)

// Mouse.h
#include <dos.h>

#if !defined MOUSE_H
#define MOUSE_H

class Muis
{static union REGS r;
static int aantalknoppen;
// status van een Mouse-object
static int status;

{setbuf(stdout,NULL);  // nodig voor DJGPP compiler (geen schermbuffering)
 // cout is met stdout verbonden
// status=0; = 0;        int86(0x33,&r,&r);
 status =;   aantalknoppen = r.x.bx;
int allesgoed(){return status=-1 || status== 65535;}
void toon(){ = 1; int86(0x33,&r,&r); }
void verberg()  { = 2; int86(0x33,&r,&r); }

void veranderpositie(int xm,int ym )
  { = 4; = xm; r.x.dx = ym; int86(0x33,&r,&r);  }

void positie(int &xm,int &ym)
{ if(!allesgoed()){xm=0;ym=0;return;}
  xm=ym=1; = 3;     int86(0x33,&r,&r);   xm =;ym= r.x.dx ;

void textpositie(int &xm,int &ym){ positie(xm,ym);
                                 xm++;ym++;// nodig omdat muis anders linker
//bovenhoek van rechthoekige muis aanduidt

void setArea( int minX, int maxX, int minY, int maxY )
  { = 7; = minX;r.x.dx = maxX;   int86( 0x33, &r, &r ); = 8; = minY; r.x.dx = maxY;  int86( 0x33, &r, &r );

int ingedrukt( int knop=1/*links*/ )
  { = 5;  r.x.bx = knop; int86(0x33,&r,&r);
      return & knop;  }

int losgelaten( int knop=1/*links*/ )
  { = 6;    r.x.bx = knop;   int86( 0x33, &r, &r );
      return & knop;  }

int links()       { return ingedrukt( 1 ); }
//int midden()    { return ingedrukt( 4 ); }
int rechts()      { return ingedrukt( 2 ); }
int linkslos()    { return losgelaten( 1 ); }
//int middenlos() { return losgelaten( 4 ); }
int rechtslos()   { return losgelaten( 2 ); }
int Muis::status=0;
union REGS Muis::r;
int Muis::aantalknoppen;


#include <iostream.h>                   // nodig voor cout
#include <conio.h>               // nodig voor clrscr,gotoxy,...
#include   <dos.h>

// now an example of use of this class in C++
// links means left, rechts means right,
// textpositie means textposition

#include <iostream.h>                   // nodig voor cout
#include <conio.h>                      // nodig voor clrscr,gotoxy,...
#include   <dos.h>

class klok
{ struct  time t;
  int x, y;
  int uur, minuut, second;
klok(int xx,int yy){x = xx; y = yy;}
void toon()
   // de klok wordt alleen getoond als er iets veranderd, anders
   // flikkert het beeld.
   if ( (int)t.ti_hour != uur || (int)t.ti_min != minuut
                        || (int)t.ti_sec != second)
      {  gotoxy(x, y);
       cout<< (int)t.ti_hour<<":"  << (int)t.ti_min<<":"
           << (int)t.ti_sec<<"    ";
       uur= (int)t.ti_hour; minuut = (int)t.ti_min ;
       second = (int)t.ti_sec;

 { Muis m;
   klok kl(1,1);
   klok kl2(40,25);
   char letter;   int oldx, oldy, x, y;
   letter =' ';   m.toon();   clrscr();
   while( letter != 'x' )
      if (m.links() )
       { // links geklikt
         m.textpositie(oldx, oldy);
          gotoxy(oldx, oldy); cout<<"L";
         while (m.links() )
              {m.textpositie(x, y);
               if ( oldx != x || oldy != y )
                   { // links ingedrukt en beweegt
                     gotoxy(x, y);   cout<<"*"; }
               oldx = x; oldy  = y;
         // links losgelaten
         gotoxy(oldx ,oldy);cout<<"los";
      if (m.rechts() )
       { // rechts geklikt
         m.textpositie(oldx, oldy);
          gotoxy(oldx, oldy); cout<<"R";
         while (m.rechts() )
              {m.textpositie(x, y);
               if ( oldx != x || oldy != y )
                   { // rechts ingedrukt en beweegt
                     gotoxy(x, y);   cout<<"."; }
               oldx = x; oldy = y;
         // rechts losgelaten
         gotoxy(oldx ,oldy);cout<<"rechts";
      if (kbhit() ) {letter =getch();
                 cout<<letter;    }
   return 0;

Author Comment

ID: 1176339
I tested the code both under 95 and NT4 ...
There are still some differences :
In dos-box there is no difference at first sight, but when switching to console-view (Alt+Enter) the stars aren't drawn by the NT version and the 95 version draws the stars inverted, so on a white backround ...
But it works , so now YOUR own problems must be solved TOO :)
one of your students :)
PS Where did you find your solution ? PC Intern 4 ??? :)
PPS What was still wrong before ?

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now