473,624 Members | 2,557 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

strange getch+kbhit behaviour

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);
}
Sep 21 '06 #1
45 3332
simnav wrote:
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);
}
getch() probably expects an ASCII character, not just some
keyboard key
Sep 21 '06 #2
jacob navia said:
simnav wrote:
<snip>
>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 ?
<snip>
>
getch() probably expects an ASCII character, not just some
keyboard key
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)
Sep 21 '06 #3
"simnav" <nospamtnxwrite s:
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.
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
Sep 21 '06 #4
On Thu, 21 Sep 2006, Richard Heathfield wrote:
jacob navia said:
>simnav wrote:
<snip>
>>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 ?
<snip>
>>
getch() probably expects an ASCII character, not just some
keyboard key

That incorrect answer is a great example of why you should ask
platform-specific questions on a newsgroup devoted to the appropriate
platform.
How could a sentence with the adverb ``probably'' be
incorrect? :-) FWIW, ``probably'' probably means ``with
likelihood (though not with certainty)'' (OED 1989, 1).

Tak-Shing
Sep 21 '06 #5
Tak-Shing Chan said:
On Thu, 21 Sep 2006, Richard Heathfield wrote:
>jacob navia said:
>>simnav wrote:
<snip>
>>>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 ?
<snip>
>>>
getch() probably expects an ASCII character, not just some
keyboard key

That incorrect answer is a great example of why you should ask
platform-specific questions on a newsgroup devoted to the appropriate
platform.

How could a sentence with the adverb ``probably'' be
incorrect? :-) FWIW, ``probably'' probably means ``with
likelihood (though not with certainty)'' (OED 1989, 1).
The probability is so low as to be not worth considering. To find out why,
ask in a newsgroup where getch() is topical.

--
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)
Sep 21 '06 #6
On Thu, 21 Sep 2006, Richard Heathfield wrote:
Tak-Shing Chan said:
>On Thu, 21 Sep 2006, Richard Heathfield wrote:
>>jacob navia said:

simnav wrote:
<snip>
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 ?
<snip>

getch() probably expects an ASCII character, not just some
keyboard key

That incorrect answer is a great example of why you should ask
platform-specific questions on a newsgroup devoted to the appropriate
platform.

How could a sentence with the adverb ``probably'' be
incorrect? :-) FWIW, ``probably'' probably means ``with
likelihood (though not with certainty)'' (OED 1989, 1).

The probability is so low as to be not worth considering. To find out why,
ask in a newsgroup where getch() is topical.
Given that "conio.h" is not included in the OP's code, it
might very well behave differently from the getch() you know of.

Tak-Shing
Sep 21 '06 #7
Tak-Shing Chan said:
On Thu, 21 Sep 2006, Richard Heathfield wrote:
<snip>
>The probability is so low as to be not worth considering. To find out
why, ask in a newsgroup where getch() is topical.

Given that "conio.h" is not included in the OP's code, it
might very well behave differently from the getch() you know of.
Were it topical so to do, I would ask which one you are referring to, since
I know of several. But since it isn't, I won't. I suggest you take this up
in a newsgroup where it's topical.

--
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)
Sep 21 '06 #8
On Thu, 21 Sep 2006, Richard Heathfield wrote:
Tak-Shing Chan said:
>On Thu, 21 Sep 2006, Richard Heathfield wrote:
<snip>
>>The probability is so low as to be not worth considering. To find out
why, ask in a newsgroup where getch() is topical.

Given that "conio.h" is not included in the OP's code, it
might very well behave differently from the getch() you know of.

Were it topical so to do, I would ask which one you are referring to, since
I know of several. But since it isn't, I won't. I suggest you take this up
in a newsgroup where it's topical.
You have completely missed my point, which is that the OP
could have been using a userland kbhit() and getch(), not the
ones provided by the implementation.

Tak-Shing
Sep 21 '06 #9
Tak-Shing Chan said:

<snip>
You have completely missed my point,
No, I haven't. You just think I have.

--
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)
Sep 21 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1779
by: Phil | last post by:
Hi, I don't understand this strange behaviour: I compile this code : #include <Python.h> #include"Numeric/arrayobject.h" static PyObject *
4
5604
by: Ben | last post by:
Hi all, I'm trying to figure out how how complex map, filter and reduce work based on the following piece of code from http://www-106.ibm.com/developerworks/linux/library/l-prog.html : bigmuls = lambda xs,ys: filter(lambda (x,y):x*y > 25, combine(xs,ys)) combine = lambda xs,ys: map(None, xs*len(ys), dupelms(ys,len(xs))) dupelms = lambda lst,n: reduce(lambda s,t:s+t, map(lambda l,n=n: *n, lst))
20
2312
by: Markus Sandheide | last post by:
Hello! Execute these lines: int x = 1; x = x > 2345678901; You will get: x == 1 with Borland C++ Builder
3
4866
by: Sebastian C. | last post by:
Hello everybody Since I upgraded my Office XP Professional to SP3 I got strange behaviour. Pieces of code which works for 3 years now are suddenly stop to work properly. I have Office XP Developer (SP3 for Office, SP1 for developer, JET40SP8) on Windows XP Home Edition (SP1). The same behaviour occurs on Windows 98 too.
1
1252
by: Ian | last post by:
Hi, I have noticed some strange behaviour when loading my database. I load a menu form on startup; this form contains a linked image to display. If the project is not then signed, the menu form loads normally, briefly displaying a loading picture progress window before the form appears. However, if I digitally sign the VB project, the image loading progress window flashes repeatedly many times before the menu finally loads.
31
2609
by: DeltaOne | last post by:
#include<stdio.h> typedef struct test{ int i; int j; }test; main(){ test var; var.i=10; var.j=20;
4
1455
by: ignw82 | last post by:
Hi all, I have a strange behaviour in dataview, maybe you can help me. the behaviour is like this : First I made a datatable (odt) in data set, and then I created a dataview using this datatable. I added a row to data table by using (let say the dataview created is odv) odv.table.rows.add(odr). When i saw in first datatable (odt), there was no rows and when I saw in odv.table.rows.count there was a row.
8
1675
by: matthewperpick | last post by:
Check out this toy example that demonstrates some "strange" behaviour with keyword arguments and inheritance. ================================= class Parent: def __init__(self, ary = ): self.ary = ary def append(self):
4
2092
by: Gotch | last post by:
Hi, I'm getting a very strange behaviour while running a project I've done.... Let's expose it: I've two projects. Both of them use a Form to do some Gui stuff. Other threads pack up messages this way like: public class UiMsg { public enum MsgType { StatusOk }; public MsgType Type;
8
5297
by: Dox33 | last post by:
I ran into a very strange behaviour of raw_input(). I hope somebody can tell me how to fix this. (Or is this a problem in the python source?) I will explain the problem by using 3 examples. (Sorry, long email) The first two examples are behaving normal, the thirth is strange....... I wrote the following flabbergasting code: #-------------------------------------------------------------
0
8249
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8179
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8348
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8493
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7176
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6112
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4187
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.