2010-08-01 100 views
0

我試圖實現鼠標interfecing,但有些輸入函數錯誤。它應該告訴我,wheater我做了左鍵單擊或右鍵單擊,但它不打印任何東西。看看:鼠標沒有輸入

#include<graphics.h> 
#include<dos.h> 
union REGS in,out; 
void Graphics(void); 
void DetectMouse(void); 
void ShowMouse(void); 
void HideMouse(void); 
void InputMouse(void); 
int main() 
{ 
    Graphics(); 
    DetectMouse(); 
    ShowMouse(); 
     // HideMouse(); 
    InputMouse(); 
    getch(); 
    closegraph(); 
    return 0; 
} 
void Graphics(void) 
{ 
    int driver=DETECT,mode; 
    initgraph(&driver,&mode,"C:\\TC\\bgi"); 
    outtextxy(1,1,"Graphics mode activated!"); 
} 
void DetectMouse(void) 
{ 
    int result; 
    in.x.ax=0; 
    result=int86(0x33,&in,&out); 
    if(result) 
    { 
     outtextxy(10,10,"Driver succesfully detected"); 
    } 
    else 
    { 
     outtextxy(10,10,"Driver not detected"); 
    } 
} 
void ShowMouse(void) 
{ 
    in.x.ax=1; 
    int86(0x33,&in,&out); 
} 
void HideMouse(void) 
{ 
    in.x.ax=2; 
    int86(0x33,&in,&out); 


} 
void InputMouse(void) 
{ 
    for(;kbhit();) 
    { 
    int x,y; 
    in.x.ax=3; 
    int86(0x33,&in,&out); 
    if(out.x.bx==1) 
     outtextxy(30,30,"Left click"); 
    if(out.x.bx==2) 
     outtextxy(40,40,"Right click"); 
    if(out.x.bx==3) 
     outtextxy(50,50,"Middle click"); 
    delay(100); 
    } 
} 

回答

1

嘗試if((out.x.bx & 1) != 0) ... - 即只檢查第0位 - 我注意到INT33 AX = 3的許多標誌是'未使用' - 是否這保證它們爲零或不是任何人的猜測。

0

你可能想要一個主循環。 INT 33 AX = 0003不會阻止等待鼠標輸入。