user13747623
user13747623

Reputation:

how to write mouse program in linux

I have tried to write a program which will detect the mouse movement. But it is showing error while running in linux environment. i also want to implement the program where if user move the mouse in x axis for different distance like 2cm, 4 cm then it will print some statement. how can i initialize the mouse in linux and get the cursur point coordinate(x,y) while user move mouse.

    #include <dos.h>
    #include <graphics.h>
    union REGS in, out;
    
    void detect_mouse ()
    {
        in.x.ax = 0;
        int86 (0X33,&in,&out);   //invoke interrupt
        if (out.x.ax == 0)
            printf ("\nMouse Failed To Initialize");
        else
            printf ("\nMouse was Succesfully Initialized");
    }
    
    void showmouse_graphics ()
    {
        int gdriver = DETECT, gmode, errorcode;
        initgraph(&gdriver, &gmode, "c:\\tc\\bgi");
        in.x.ax = 1;
        int86 (0X33,&in,&out);
        getch ();
        closegraph ();
    }
    void detect ()
    {
        int button;
        while (!kbhit () )
        {
            in.x.ax = 3;
            int86 (0X33,&in,&out);
            button=out.x.bx&7
            switch(button)
            {
                case 1:
                    print(“left button pressed\n”);
                break;
                case 2:
                    print(“right button pressed\n”);
                break;
                case 4:
                    print(“middle button pressed\n”);
                break;
                case 3:
                    print(“left and right button pressed\n”);
                break;
                case 5:
                    print(“left and middle button pressed\n”);
                break;
                case 6:
                    print(“right and middle button pressed\n”);
                break;
                case 7:
                    print(“all the three buttons pressed\n”);
                break;
                default:
                    print(“No button pressed\n”);
            }
            delay (200); // Otherwise due to quick computer response 100s of words will get print
        }
    }
    void hide_mouse ()
    {
        in.x.ax = 2;
        int86 (0X33,&in,&out);
    }
    
    int main ()
    {
        detect_mouse ();
        showmouse_graphics ();
        detect ();
        hide_mouse ();
        return 0;
    }

Upvotes: 0

Views: 97

Answers (1)

Krackout
Krackout

Reputation: 282

You are using dos.h which is a header available for MS/PC-DOS, not available in Linux. It's my strong belief that it doesn't even compile under gcc in Linux.

Upvotes: 3

Related Questions