2014-04-28 26 views
1

我爲使用GetAsyncKeyState()的Windows製作了一個小遊戲。現在我想爲MS DOS編譯遊戲,但是我找不到這個函數的其他選擇。 getch()和kbhit()對於處理擊鍵來說太慢了。 主要目標是以光速或至少像GetAsyncKeyState()的速度處理鍵擊。 在此先感謝。MS DOS的GetAsyncKeyState()

+2

http://www8.cs.umu.se/~isak/snippets/keywatch.c –

+0

感謝您的回答!它看起來非常有幫助,但borland C++,當我嘗試編譯這個程序時,說 ** cpp 130 at signal(SIGINT,SIG_IGN):無法將'void(*)()'轉換爲void(*)(int) '** 請問您能否給我一些指導我應該怎樣做這個程序?我想這是針對C的,這就是爲什麼我不能編譯它。我該怎麼辦?再次感謝您的回答! – user3496846

+0

你實際上是以MS DOS爲目標的,還是你指的是控制檯子系統,作爲Windows的一部分? – IInspectable

回答

1

用於Borland C++ MSDOS 上的鍵盤處理的示例代碼,其使用conio.h,kbhit()getch()。這應該在MSDOS Borland C++中編譯 就好了。

#include <stdio.h> 
#include <string.h> 
#include <fcntl.h> 
#include <dos.h> 

#define TRUE 1 
#define FALSE (!TRUE) 
#define TEXTSCREEN 0xB800 


#define esc 27 
#define tab 9 
#define up  72 
#define down 80 
#define left 75 
#define right 77 
#define home 71 
#define cend 79 
#define pgup 73 
#define pgdn 81 
#define ins 82 
#define del 83 
#define plus 43 
#define subt 45 
#define mult 42 
#define devi 47 
#define spc 32 
#define f1  59 
#define f2  60 
#define f3  61 
#define f4  62 
#define f5  63 
#define f6  64 
#define f7  65 
#define f8  66 
#define f9  67 
#define f10 68 
#define ap  53 
#define bksp 8 
#define enter 13 
#define crum 245 


void key2(void); 

int main(void) 
{ 

    ch=0; 
    while(ch!=esc) 
    { 

     key2(); 

    } 

    return 0; 
} 


void key2(void) 
{ 
    if (kbhit()) 
    { 
    ch=getch(); 

    if (ch==f1) 
    { 

    } 
    if (ch==f2) 
    { 

    } 
    if (ch==f3) 
    { 

    } 
    if (ch==f4) 
    { 


    } 
    if (ch==f5) 
    { 


    } 
    if (ch==f6) 
    { 


    } 
    if (ch==f7) 
    { 


    } 
    if (ch==f8) 
    { 


    } 
    if (ch==f9) 
    { 

    } 
    if (ch==f10) 
    { 


    } 


    if (ch==tab) 
    { 

    } 

    if (ch==ins) 
    { 

    } 

    if (ch==del) 
    { 
    } 

    if (ch==bksp) 
    { 



    } 

    if (ch==enter) 
    { 


    } 

    if (ch==spc) 
    { 

    } 
    if (ch==49) 
    { 



    } 
    if (ch==50) 
    { 



    } 

    if (ch==up) 
    { 


    } 

    if (ch==down) 
    { 


    } 
    if (ch==home) 
    { 



    } 
    if (ch==cend) 
    { 



    } 
    if (ch==pgup) 
    { 



    } 
    if (ch==pgdn) 
    { 



    } 
    } 
}