I know that the following instructions:
char c;
c=getche();
...read a character. If I type, for example, 'g', then c=='g'. But what is equally c with if I press an arrow, the Enter key, the Del key etc.?
10 5856
Look in the ASCII table for the values of these keys.
Or, assign c to an int and display the int.
Look in the ASCII table for the values of these keys.
Or, assign c to an int and display the int.
Better to investigate this yourself by printing out the value of c for various keypresses. That's because:
1. ASCII encoding may be ubiquitous, but there is no law (or Standard) that requires your system to use ASCII.
2. Some keys are expressed as escape sequences, where a single keypress generates a stream of characters. To detect this, you want to loop continuously on getche, printing out whatever you get as hexadecimal text.
1. ASCII encoding may be ubiquitous, but there is no law (or Standard) that requires your system to use ASCII.
2. Some keys are expressed as escape sequences, where a single keypress generates a stream of characters. To detect this, you want to loop continuously on getche, printing out whatever you get as hexadecimal text.
Yes, ASCII is not required by the standard but I have yet to see a version of C running on Unix/Linux or Windows that doesn't use it. Not to say there isn't a C lurking somewhere with a 5-bit char.
What is an example of one keypress generating a stream of characters? And I don't mean autorepeat by leaning on the key. Autorepeat is just a fast typist.
Banfa 9,065
Expert Mod 8TB
Yes, ASCII is not required by the standard but I have yet to see a version of C running on Unix/Linux or Windows that doesn't use it. Not to say there isn't a C lurking somewhere with a 5-bit char.
Mobile phones and particularly text messages would be 1 recent example of a platform that may well use a character coding other than ASCII ( GSM 03.38)
However I suspect that as mobile phones transform into computer like PDAs this will be less true.
Banfa 9,065
Expert Mod 8TB
What is an example of one keypress generating a stream of characters? And I don't mean autorepeat by leaning on the key. Autorepeat is just a fast typist.
Any arrow key I think or any other extended keyboard keys that do not directly convert to an ASCII character.
I wrote the following test program:
#include<iostream.h>
#include<conio.h>
void main()
{ char c;
c=getch();
cout<<endl<<c;
getche(); }
Here are some results:
Left Arrow - K
Right Arrow - M
Up Arrow - H
Down Arrow - P
Delete Key - S
At <Enter> and <Space> pushing there was no any letter in cout, maybe a space. Why was that?
PS: I want to do a short instruction like:
if (c==enter) {...}
Thanks a lot! G.P.
What is an example of one keypress generating a stream of characters? And I don't mean autorepeat by leaning on the key. Autorepeat is just a fast typist.
A list of the standard ANSI escape sequences can be found at http://en.wikipedia.org/wiki/ANSI_escape_code
A list of the standard ANSI escape sequences can be found at
http://en.wikipedia.org/wiki/ANSI_escape_code
Thank you. I will have a look.
Banfa 9,065
Expert Mod 8TB
At <Enter> and <Space> pushing there was no any letter in cout, maybe a space. Why was that?
Erm you pressed the <Space> key and you got a space ' ' would you really have wanted a letter instead?
Look carefully when you press <Enter> you get an enter (there is an extra blank line on screen).
Rather than outputting the character(s) you read to understand what is happening I suggest you output the value(s) (decimal or hexidecimal) of what you read from the keyboard.
Also see Dons link.
The multi-byte escape sequences can be sent to a terminal to provoke some special action. My recollection from the VT100 days was that the arrow keys on the terminal sent the corresponding cursor-move escape sequences to the computer. I don't know if today's PCs send multi-byte escape sequences or non-ASCII (>= 0x80) single characters.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Justine |
last post by:
Hi All,
Which is function equivalent to getch/getche of C++.
Thanz in Advance,
Justine
|
by: srikanth |
last post by:
help me out with the subject
|
by: zeroDontYouSpamMateytype |
last post by:
Hi,
Does anyone know if it's possible to write either a getch()
(preferably Borland-style) or getche() function in C++ (I've posted
the C equivalent of this question to CLC) without it being...
|
by: aman |
last post by:
I need to implement getche() but as I am working on Linux and that I
cant use conio.h, is there any equivalent???
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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...
|
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...
|
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,...
| |