49 lines
1.0 KiB
C
49 lines
1.0 KiB
C
|
/**
|
||
|
* Example mouse work
|
||
|
*
|
||
|
* Alexander Popov <iiiypuk@fastmail.fm>
|
||
|
* License: Unlicense
|
||
|
*/
|
||
|
|
||
|
#include <stdio.h>
|
||
|
#include <gdos/gdos.h>
|
||
|
|
||
|
void main() {
|
||
|
int mouse_status;
|
||
|
int mouse_x, mouse_y, mouse_click;
|
||
|
int mouse_x_old = -1, mouse_y_old = -1, mouse_click_old = -1;
|
||
|
|
||
|
mouse_status = gd_detect_mouse();
|
||
|
if (mouse_status != GD_TRUE) {
|
||
|
printf("Mouse support not available.\n");
|
||
|
abort();
|
||
|
}
|
||
|
|
||
|
/* example: TEXT_MODE || VGA_256_COLOR_MODE */
|
||
|
gd_set_mode(VGA_256_COLOR_MODE);
|
||
|
clrscr();
|
||
|
gd_show_mouse();
|
||
|
do {
|
||
|
gd_get_mouse_status(&mouse_x, &mouse_y, &mouse_click);
|
||
|
|
||
|
/* when mouse status change update */
|
||
|
if (mouse_x != mouse_x_old ||
|
||
|
mouse_y != mouse_y_old ||
|
||
|
mouse_click != mouse_click_old)
|
||
|
{
|
||
|
mouse_x_old = mouse_x;
|
||
|
mouse_y_old = mouse_y;
|
||
|
mouse_click_old = mouse_click;
|
||
|
|
||
|
clrscr();
|
||
|
gotoxy(0, 0);
|
||
|
printf("Mouse position: X=%d, Y=%d, CLICK=%d", mouse_x, mouse_y, mouse_click);
|
||
|
gd_show_mouse();
|
||
|
}
|
||
|
} while (!kbhit());
|
||
|
gd_hide_mouse();
|
||
|
getch();
|
||
|
|
||
|
gd_set_mode(TEXT_MODE);
|
||
|
}
|