473,385 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Getche - Enter key

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.?
Sep 24 '08 #1
10 5851
weaknessforcats
9,208 Expert Mod 8TB
Look in the ASCII table for the values of these keys.

Or, assign c to an int and display the int.
Sep 24 '08 #2
donbock
2,426 Expert 2GB
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.
Sep 24 '08 #3
weaknessforcats
9,208 Expert Mod 8TB
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.
Sep 24 '08 #4
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.
Sep 24 '08 #5
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.
Sep 24 '08 #6
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.
Sep 24 '08 #7
donbock
2,426 Expert 2GB
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
Sep 24 '08 #8
weaknessforcats
9,208 Expert Mod 8TB
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.
Sep 24 '08 #9
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.
Sep 25 '08 #10
donbock
2,426 Expert 2GB
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.
Sep 25 '08 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Justine | last post by:
Hi All, Which is function equivalent to getch/getche of C++. Thanz in Advance, Justine
28
by: srikanth | last post by:
help me out with the subject
4
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...
5
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???
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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...
0
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,...
0
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...
0
Oralloy
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,...
0
jinu1996
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 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.