Reputation: 1665
I made a small game for Windows which uses GetAsyncKeyState(). Now I want to compile the game for MS DOS, but I cannot find any alternative for this function. getch() and kbhit() are too slow for handling the keystrokes. The main goal is to handle the keystrokes at the speed of light or at least like with the speed of GetAsyncKeyState(). Thanks in advance.
Upvotes: 2
Views: 317
Reputation: 8587
An example code for keyboard handling on Borland c++ MSDOS
that uses conio.h
, kbhit()
and getch()
. This should compile
just fine in the 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)
{
}
}
}
Upvotes: 1