2

我有一个将当前鼠标光标位置打印到控制台的程序。

我想创建鼠标可以移动的范围。(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,&reg);
    x=reg.r_cx/8;
    y=reg.r_dx/8;
}

int main()
{
    clrscr();
    _setcursortype(_NOCURSOR);
    reg.r_ax=0x01;
    intr(0x33,&reg);

    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() ?

4

1 回答 1

1

你这样做的方式与你在 getMouse() 中所做的一样:

void setMousePosition(int x, int y)
{
  reg.r_ax=0x04;
  reg.r_cx = x;
  reg.r_dx = y;
  intr(0x33,&reg);
}

或者,您可以使用范围限制器:

void setMouseHorizontalRange(int min, int max)
{
  reg.r_ax=0x07;
  reg.r_cx = min;
  reg.r_dx = max;
  intr(0x33,&reg);
}

void setMouseVerticalRange(int min, int max)
{
  reg.r_ax=0x08;
  reg.r_cx = min;
  reg.r_dx = max;
  intr(0x33,&reg);
}
于 2019-05-01T06:18:38.560 回答