kbhit()究竟如何工作? [英] How, exactly, does kbhit( ) work?

查看:67
本文介绍了kbhit()究竟如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

2004年6月28日

我有兴趣找到测试键盘缓冲区的方法

for MT / Not MT。在系统中尝试了kbhit()但它没有做到我认为从阅读文献中得到的结果。

样本:编译器文档说,

"检测按键是否可供阅读。


Herbert Schildt说,

"如果用户按下了键,此函数返回

true(非0),但不读取字符。

如果没有键击未决,则kbhit()返回false(0)。


这是测试代码。 kbhit()在两个

getchar()调用之间执行。

#include< stdio.h>

#include< system.h> ;

void main(){

int ig1 = 0,ig2 = 0,ik = -1;

ig1 = getchar();

ik = kbhit();

ig2 = getchar();

getchar();

printf( ig1 =%d,ik =%d,ig2 =%d,ig1,ik,ig2);

返回;

}


在运行时,我按下aAEnter,这样当执行kbhit()时,''A''和''\ n''

在缓冲区中,但ik返回

为0.

其他地方的按键是等待或者可用

除了缓冲区?如果kbhit()没有查看

缓冲区,它会看到什么?

June 28, 2004
I''m interested in finding a way to test the keyboard buffer
for MT/Not MT. Tried kbhit() in system.h but it didn''t do
what I thought it would from reading the literature.
Samples: Compiler Docs said,
"Detects whether a keypress is available for reading."

Herbert Schildt said,
"If the user has pressed a key, this function returns
true(non-0), but does not read the character.
If no keystroke is pending, kbhit() returns false (0)."

Here is the test code. kbhit() executes between two
getchar() calls.
#include <stdio.h>
#include <system.h>
void main() {
int ig1=0, ig2=0, ik=-1;
ig1 = getchar();
ik = kbhit();
ig2 = getchar();
getchar();
printf("ig1=%d, ik=%d, ig2=%d", ig1,ik,ig2);
return;
}

At runtime, I pressed aAEnter, so that ''A'' and ''\n''
were in buffer when kbhit() executed, yet ik returned
as 0.
Where else would a keystroke be "waiting" or "available"
except in the buffer? If kbhit() does not look at the
buffer, what does it look at?

推荐答案

hugo27< ob ****@yahoo.com>潦草地写道:
hugo27 <ob****@yahoo.com> scribbled the following:
2004年6月28日
我很想找到一种方法来测试MT / Not MT的键盘缓冲区。在system.h中尝试了kbhit(),但它没有做到我认为从阅读文献中得到的东西。
示例:编译器文档说,
检测是否按键是可供阅读。
Herbert Schildt说,
如果用户按了一个键,此函数返回
true(非0),但不读取该字符。
如果没有按键正在等待,kbhit()返回false(0)。"
June 28, 2004
I''m interested in finding a way to test the keyboard buffer
for MT/Not MT. Tried kbhit() in system.h but it didn''t do
what I thought it would from reading the literature.
Samples: Compiler Docs said,
"Detects whether a keypress is available for reading." Herbert Schildt said,
"If the user has pressed a key, this function returns
true(non-0), but does not read the character.
If no keystroke is pending, kbhit() returns false (0)."




ISO标准C中没有kbhit()函数。请在
中询问
comp.os.ms-windows.programmer.misc或合适的微软新闻组。


-

/ - Joona Palaste(pa * ****@cc.helsinki.fi)-------------芬兰-------- \

\-- http://www.helsinki.fi/~palaste -------- -------------规则! -------- /

To doo bee doo bee doo。

- Frank Sinatra



There is no kbhit() function in ISO standard C. Please ask in
comp.os.ms-windows.programmer.misc or a suitable Microsoft newsgroup.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"To doo bee doo bee doo."
- Frank Sinatra



" hugo27" < OB **** @ yahoo.com>在消息中写道

"hugo27" <ob****@yahoo.com> wrote in message

其他地方的按键是等待或可用
除了在缓冲区?如果kbhit()没有查看
缓冲区,它会看到什么?

Where else would a keystroke be "waiting" or "available"
except in the buffer? If kbhit() does not look at the
buffer, what does it look at?



stdin将键盘视为一个提供源源不断的设备

个字符,当用户输入时,它会变成程序的用户。

这不是对待键盘的唯一方法。例如,如果你是写一个太空入侵者游戏,你想知道在你进行测试的那一刻,是否按下了

。这就是像kbhit()

(不是ANSI函数)这样的函数。实现方式各不相同,但可能会看到键盘驱动程序的内部结构 - 命令上的字符

行显然存储在某处,即使它们尚未输入

stdin缓冲区。


stdin treats the keyboard as a device that provides a steady stream of
characters, which become avialble to the program when the user types enter.
This isn''t the only way to treat the keyboard. For instance if you are
writing a game of space invaders you want to know if the key is pressed at
the very instant you make the test. This is where functions like kbhit()
(not an ANSI function) come in useful. Implementation varies, but probably
it looks at the internals of the keyboard driver - characters on the command
line are obviously stored somewhere, even though they are not yet entered to
the stdin buffer.


hugo27写道:
hugo27 wrote:
2004年6月28日
我有兴趣为MT / Not MT找到测试键盘缓冲区的方法。


标准C库中不支持此类内容。您将需要特定于实现的功能。
将需要特定于实现的功能。你需要,然后用b $ b来检查你的

实现的新闻组,邮件列表或技术支持。

在系统中尝试了kbhit()。 h但它没有做


C中没有kbhit()也没有< system.h> ;.

我是什么认为它可以通过阅读文献。
样本:编译器文档说,
检测按键是否可用于阅读。

赫伯特·希尔特说,如果用户按下了某个键,则此函数返回
true(非0),但不读取该字符。
如果没有等待键击,则kbhit()返回false(0) 。
June 28, 2004
I''m interested in finding a way to test the keyboard buffer
for MT/Not MT.
There is no support for such things in the standard C libraries. You
will need implementation-specific functionality for this. You need,
then, to check newsgroups, mailing lists, or tech support for your
implementation.
Tried kbhit() in system.h but it didn''t do
There is no kbhit() in C. Nor is there a <system.h>.
what I thought it would from reading the literature.
Samples: Compiler Docs said,
"Detects whether a keypress is available for reading."

Herbert Schildt said,
"If the user has pressed a key, this function returns
true(non-0), but does not read the character.
If no keystroke is pending, kbhit() returns false (0)."




Herbert Schildt是C上错误信息的主要提供者之一。

忽略他,除非他为你的具体文字撰写文件

实施。



Herbert Schildt is one of the primary providers on misinformation on C.
Ignore him unless he is writing documentation for your specific
implementation.


这篇关于kbhit()究竟如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆