1

I'm having trouble to make a programming that just simply detect mouse input programm in C programming. I tried to search some source codes, but everyone is using C++. Also even they use C language, they use <dos.h> and <graphics.h> which I cannot use. Also they are using Union REGS in and out, but I cant use thoese header file, so that I cant use them. Is there any other way I can make a programm that detect mouse input?? such as, if I just plug the mouse, then programm will just print mouse is detected, or mouse is connected well. Im using visual studio code. Thank you

#include <conio.h>
#include <direct.h>
#include <dos.h> // when I use this, complier said use direct.h
#include <graphics.h> // I've tried to add graphics.h files from  winbGlm and paste it to Mingw lib but still not working. 
#include <stdio.h>

union REGS in, out;
 
// Function to implement the functionality
// of detecting Mouse
void detectMouse()
{
           in.x.ax = 0;
 
          // Invoke interrupt (in86 method
          // description mentioned above)
          int86(0X33, &in, &out);
 
         if (out.x.ax == 0)
                 printf("\nMouse Failed To Initialize");
         else
                 printf("\nMouse was Successfully Initialized");
}
Oka
  • 23,367
  • 6
  • 42
  • 53
JY Chang
  • 21
  • 1
  • 2
    DON'T USE CONIO.H, GRAPHICS.H OR DOS.H! Use a contemporary C or C++ compiler like GCC. If you want direct terminal control, consider using a cross-platform library like curses: https://stackoverflow.com/a/54309830/421195 – paulsm4 Nov 14 '22 at 04:25
  • Thank you for the reply. Im using minGW gcc compiler. What do you mean by using cross platform libaray ? Do I need to download curses?? – JY Chang Nov 14 '22 at 16:54
  • As you probably know, conio.h, graphics.h, etc. all came with the old, long out-of-date Borland C++ compiler. They all assume a 16-bit DOS platform. minGW gcc is a perfectly acceptable alternative to Borland C++. As you probably also know, there's no "standard C library" for graphical UIs (like Windows or XLib) or raw terminal I/O. You need to choose one. [curses](https://tldp.org/HOWTO/NCURSES-Programming-HOWTO/) is often an good choice. Curses is cross-platform (it runs on *nix, MacOS and Windows), and cross-language (there are curses bindings for C, Java, C#, Python, etc. etc.) – paulsm4 Nov 14 '22 at 19:58
  • Thank you so much!! I will take a look about curses. – JY Chang Nov 15 '22 at 18:01

0 Answers0