Source Code File 14-02_mspy

14-02_mspy.c

#include <ncurses.h>

int main()
{
    MEVENT mort;
    int ch;
    
    initscr();
    noecho();
    keypad(stdscr,TRUE);
        
    mousemask(ALL_MOUSE_EVENTS,NULL);
	addstr("Click the mouse around the screen\n");
	addstr("Press Enter to stop");
	while(1)
    {
        ch = getch();
        if( ch == KEY_MOUSE )
        {
            getmouse(&mort);
            move(0,0);
            clrtoeol();
            printw("y=%2d\tx=%2d",mort.y,mort.x);
            refresh();
            continue;
        }
        if( ch == '\n' )
            break;
    }

    endwin();
    return 0;
}

Output Screenshot

Notes

* Variable mort is short for Mortimer, which was Mickey Mouse's original first name.

* The noecho() function at Line 9 ensures that any text typed doesn't appear on the screen.

* The clrtoeol() function at Line 20 erases the previous coordinate pair. Otherwise the numbers can be misread.