Untitled
unknown
plain_text
9 months ago
2.2 kB
5
Indexable
#include <dos.h>
#include <stdio.h>
#include <conio.h>
void show_mouse();
void hide_mouse();
void get_mouse_position(int *x, int *y, int *buttons);
void update_status(int x, int y, int buttons);
int main() {
union REGS in, out;
int x, y, buttons;
// Инициализиране на мишката
in.x.ax = 0x0000;
int86(0x33, &in, &out);
if (out.x.ax == 0) {
printf("Mouse driver is not installed.\n");
return 1;
}
// Показване на курсора на мишката
show_mouse();
// Основен цикъл
while (!kbhit()) {
// Получаване на позицията на мишката и състоянието на бутоните
get_mouse_position(&x, &y, &buttons);
// Актуализиране на статуса на екрана
update_status(x, y, buttons);
// Забавяне за намаляване на трептенето
delay(100);
}
// Скриване на курсора на мишката
hide_mouse();
return 0;
}
void show_mouse() {
union REGS in;
in.x.ax = 0x0001;
int86(0x33, &in, &in);
}
void hide_mouse() {
union REGS in;
in.x.ax = 0x0002;
int86(0x33, &in, &in);
}
void get_mouse_position(int *x, int *y, int *buttons) {
union REGS in, out;
in.x.ax = 0x0003;
int86(0x33, &in, &out);
*x = out.x.cx / 8; // Преобразуване на пиксели в колони
*y = out.x.dx / 8; // Преобразуване на пиксели в редове
*buttons = out.x.bx; // Състояние на бутоните
}
void update_status(int x, int y, int buttons) {
// Преместване на курсора на екрана на позиция (0, 0)
gotoxy(1, 1);
// Изчистване на първия ред
clreol();
// Извеждане на текущата позиция и състояние на бутоните
printf("Position: (%d, %d) Buttons: %s%s%s",
x, y,
(buttons & 1) ? "Left " : "",
(buttons & 2) ? "Right " : "",
(buttons & 4) ? "Middle " : "");
}
Editor is loading...
Leave a Comment