From 22987c71d47e54ef02257687d36cb61b5ab0acbc Mon Sep 17 00:00:00 2001 From: rswindell <> Date: Sun, 13 Oct 2002 10:24:11 +0000 Subject: [PATCH] Added function: keyhit() to be used in place of kbhit(). --- xtrn/sbj/sbj.c | 6 +++--- xtrn/sdk/xsdk.c | 12 ++++++++++++ xtrn/sdk/xsdk.h | 8 +++++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/xtrn/sbj/sbj.c b/xtrn/sbj/sbj.c index 36966cac71..c15ae6a999 100644 --- a/xtrn/sbj/sbj.c +++ b/xtrn/sbj/sbj.c @@ -303,7 +303,7 @@ int main(int argc, char **argv) putchar(5); /* ctrl-e */ mswait(500); - if(kbhit()) { + if(keyhit()) { #ifdef __16BIT__ while(_bios_keybrd(1)) _bios_keybrd(0); @@ -580,7 +580,7 @@ while(1) { ,ibet<credits/1024L ? ibet : credits/1024L); chat(); mnemonics(str); - if(autoplay && kbhit()) + if(autoplay && keyhit()) autoplay=0; if(autoplay) i=ibet; @@ -783,7 +783,7 @@ while(1) { strcat(str,", or [Stand]: "); chat(); mnemonics(str); - if(autoplay && kbhit()) + if(autoplay && keyhit()) autoplay=0; diff --git a/xtrn/sdk/xsdk.c b/xtrn/sdk/xsdk.c index a5e22380d2..ab1aa333ed 100644 --- a/xtrn/sdk/xsdk.c +++ b/xtrn/sdk/xsdk.c @@ -522,6 +522,18 @@ void mnemonics(char *str) attr(LIGHTGRAY); } +int keyhit() +{ +#ifndef __16BIT__ + int cnt=0; + if(ioctlsocket(client_socket,FIONREAD,&cnt)) + return(0); + return(cnt); +#else + return(kbhit()); +#endif +} + /****************************************************************************/ /* If a key has been pressed, the ASCII code is returned. If not, 0 is */ /* returned. Ctrl-P and Ctrl-U are intercepted here. */ diff --git a/xtrn/sdk/xsdk.h b/xtrn/sdk/xsdk.h index dbdf440b96..7a62756812 100644 --- a/xtrn/sdk/xsdk.h +++ b/xtrn/sdk/xsdk.h @@ -44,10 +44,12 @@ /*********************************************/ #ifndef __unix__ #include <io.h> - #include <dos.h> #include <share.h> #include <conio.h> #endif +#ifdef __16BIT__ + #include <dos.h> +#endif #ifdef _WIN32 #include <windows.h> #endif @@ -145,6 +147,10 @@ char noyes(char *str); - Does not wait for a keystroke */ char inkey(long mode); +/* Key hit? + - Returns non-zero if key hit, 0 otherwise */ +int keyhit(void); + /* Get a Key - Waits for the local or remote user to hit a valid key - See K_* constants in XSDKDEFS.H for possible values of mode */ -- GitLab