strrange getch+keybhit behaviour

S

simnav

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, &reg);

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);
}
 
C

CBFalconer

simnav said:
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 !

#include <stdio.h>
#include <dpmi.h>

Non standard include. Meaningless here.
int Handle()
{
int vv;

int lo, hi;

__dpmi_regs reg;

Illegal name, in implementation reserved namespace.
reg.x.ax = 0x10 << 8; /* shift 10h into AH */
__dpmi_int( 0x16, &reg);

Undefined call.
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())

Undefined function.
{
fprintf(stdout,"i=%d\n",i++);
fprintf(stdout,"%c\n",getch());
}

fprintf(stdout,"%d\n",Handle());
delay(155);

Undefined function.
} while(1);

Can never reach here, where there should be a return value.

Anything can happen when you invoke undefined behaviour. So
nothing strange happened.

--
Some informative links:
http://www.geocities.com/nnqweb/
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.caliburn.nl/topposting.html
http://www.netmeister.org/news/learn2quote.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top