我有一个程序,它将当前鼠标光标位置打印到控制台。
我想创建鼠标可以去的边界。 (10,10)和(20,20)
所以这是我的代码到目前为止:
#include <stdio.h>
#include <dos.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
int x,y;
struct REGPACK reg;
void getmousepos()
{
reg.r_ax=0x03;
intr(0x33,®);
x=reg.r_cx/8;
y=reg.r_dx/8;
}
int main()
{
clrscr();
_setcursortype(_NOCURSOR);
reg.r_ax=0x01;
intr(0x33,®);
do
{
getmousepos();
printf(" ");
printf(" ");
window(1,1,79,24);
printf("Current position : %3d, %3d",x,y);
if(x < 10)
//set the x cursor possition to 10
if(x > 20)
//set the x cursor possition to 20
if(y < 10)
//set the y cursor to 10
if(y > 20)
//set the y cursor to 20
}while(!kbhit());
return 1;
}
有没有办法设置reg.r_cx和reg.r_dx寄存器与我想要的坐标,然后用适当的中断调用intr()?
您这样做的方式与在getMouse()中完成的方式相同:
void setMousePosition(int x, int y)
{
reg.r_ax=0x04;
reg.r_cx = x;
reg.r_dx = y;
intr(0x33,®);
}
您也可以使用范围限制器:
void setMouseHorizontalRange(int min, int max)
{
reg.r_ax=0x07;
reg.r_cx = min;
reg.r_dx = max;
intr(0x33,®);
}
void setMouseVerticalRange(int min, int max)
{
reg.r_ax=0x08;
reg.r_cx = min;
reg.r_dx = max;
intr(0x33,®);
}