问题描述
在下面的代码中发生了一些奇怪的事情!如果我按下任何
的ALT +箭头键,它们会从缓冲区中提取两次然后getch
似乎停止了;如果我发布并再次按下ALT +箭头没有任何变化:
退出这个条件的唯一方法是按下另一个键一个
时间。
似乎发生的事情是kbhit说缓冲区中存在一些密钥
但是getch看不到任何数据并且等待密钥。为什么会这样?
如果我删除延迟,一切正常。我已经插入一个延迟
来重现我在另一个更大的项目中发现的问题
其中循环延迟是155ms。
最后一件事:我已经在新主板上验证了这个问题!
请帮助我!!
谢谢。
西蒙娜
#include< stdio.h>
#include< dpmi.h>
int句柄( )
{
int vv;
int lo,hi;
__dpmi_regs reg;
reg.x.ax = 0x10<< 8; / *将10h移入AH * /
__dpmi_int(0x16,& reg);
vv = reg.x.ax;
lo = vv& 0X00FF;
hi =(vv& 0XFF00)> 8;
vv =(((= = 0)|(lo == 224))?hi +256:lo);
返回vv;
} //句柄
int main(void)
{
int i;
do
{
i = 0;
while(kbhit())
{
fprintf(stdout," i =%d \ n",i ++ );
fprintf(stdout,"%c\ n",getch());
}
fprintf (stdout,"%d \ nn",Handle());
延迟(155);
} while(1);
}
In the following code something strange happens ! If I keep pressed any
of ALT+Arrow, keys, they are extracted two times from buffer then getch
seems to stop; if I release and press again ALT+arrow nothing changes:
the only way to exit from this condition is press another key a single
time.
What seems to happen is that kbhit say some keys are present in buffer
but for getch don''t see any data and waits for a key. Why this happen ?
If I remove the delay all is working correctly. I''ve inserted a delay
to reproduce thi problem that I''ve found on another bigger project
where loop delay is 155ms.
Last thing: I''ve verified this problem only on newer motherboards !
Please help me !!
Thank you.
Simone
#include <stdio.h>
#include <dpmi.h>
int Handle()
{
int vv;
int lo, hi;
__dpmi_regs reg;
reg.x.ax = 0x10 << 8; /* shift 10h into AH */
__dpmi_int( 0x16, ®);
vv= reg.x.ax ;
lo = vv & 0X00FF;
hi= ( vv & 0XFF00) >8;
vv=( ((lo == 0)|(lo == 224)) ? hi+256 : lo);
return vv;
} // Handle
int main(void)
{
int i;
do
{
i=0;
while(kbhit())
{
fprintf(stdout,"i=%d\n",i++);
fprintf(stdout,"%c\n",getch());
}
fprintf(stdout,"%d\n",Handle());
delay(155);
} while(1);
}
推荐答案
getch()可能需要一个ASCII字符,而不仅仅是一些
键盘键
getch() probably expects an ASCII character, not just some
keyboard key
< snip>
<snip>
< snip>
<snip>
这个错误的答案就是一个很好的例子,说明为什么你应该在一个致力于相应的新闻组上询问
特定于平台的问题
平台。
-
Richard Heathfield
Usenet是一个奇怪的地方 - dmr 29/7/1999
电子邮件:rjh在上面的域名(但显然放弃了www)
That incorrect answer is a great example of why you should ask
platform-specific questions on a newsgroup devoted to the appropriate
platform.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
你的文章在你发布它的前三次是偏离主题的。
它仍然是偏离主题的。请把它带到讨论
getch和kbhit的小组。我怀疑你想要一个MS-DOS编程
新闻组。
-
你称之为* C *问题?你到底在吸什么? --Kaz
Your article was off-topic the first three times you posted it.
It is still off-topic. Please take it to a group that discusses
getch and kbhit. I suspect you want an MS-DOS programming
newsgroup.
--
"You call this a *C* question? What the hell are you smoking?" --Kaz
这篇关于奇怪的getch + kbhit行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!