473,413 Members | 1,778 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,413 software developers and data experts.

how to find that escape key is pressed while taking the string

hi

how to check escape key is pressed when accepting the string as input.
Because I do not want to receive a string if user presses the ESCAPE
key.. I used ascii code for comparision but I didn't get any fruitful
results. Please help me.

Nov 21 '05 #1
16 3311
In article <11**********************@g43g2000cwa.googlegroups .com>,
sudhir <su*****************@gmail.com> wrote:
how to check escape key is pressed when accepting the string as input.
Because I do not want to receive a string if user presses the ESCAPE
key.. I used ascii code for comparision but I didn't get any fruitful
results. Please help me.


The escape key isn't portable ;-)

If you have an input string that you know to be ASCII (or ISO-8859-*)
then you can test each character against the ASCII escape value, which
you can code in several different ways. One such way would be

#include <string.h>
#define ESCAPE '\027'

.....

if ( strchr( STRING, ESCAPE ) != NULL ) { /* you got an ESCAPE */ }

Note that your operating system or shell might be "eating" the escape
character before sending it on to you. Mechanisms to prevent that
happening are operating-system specific and best explored in a
newsgroup specific to your operating system.

--
"No one has the right to destroy another person's belief by
demanding empirical evidence." -- Ann Landers
Nov 21 '05 #2
"sudhir" <su*****************@gmail.com> writes:
how to check escape key is pressed when accepting the string as input.
Because I do not want to receive a string if user presses the ESCAPE
key.. I used ascii code for comparision but I didn't get any fruitful
results. Please help me.


Please help us to help you. If you'll show us the code you've tried
*and* tell us how it misbehaves, we can help you determine why it
doesn't work.

If you want to terminate the attempt to read a line immediately if the
user presses ESCAPE, there's no portable way to do that; see question
19.1 in the comp.lang.c FAQ, <http://www.eskimo.com/~scs/C-faq/faq.html>.

Walter Roberson's also gave you some excellent advice.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 21 '05 #3
sudhir wrote:
how to check escape key is pressed when accepting the string as input.
Because I do not want to receive a string if user presses the ESCAPE
key.. I used ascii code for comparision but I didn't get any fruitful
results. Please help me.


You will have to use some system specific extension, so I suggest you
ask in a group dedicated to whichever system you are using.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Nov 21 '05 #4

"sudhir" <su*****************@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
hi

how to check escape key is pressed when accepting the string as input.
Because I do not want to receive a string if user presses the ESCAPE
key.. I used ascii code for comparision but I didn't get any fruitful
results. Please help me.


The C language does not see 'keystrokes', it only sees 'streams
of characters' as input. Some character sets, such as ASCII do
define an 'escape' character, but pressing an 'escape' key on
a keyboard might or might not insert such a character into C's
'standard input stream'. Your best bet is to find a platform
specific solution (and ideally isolate it in your code for ease
of porting). Often a compiler targeting a system where it's
appropriate will provide a function for direct hardware (and/or
driver) interface, such as with a keyboard. There also exist
third party libraries for such things, which are portable among
a certain set of platforms. But none of this is standard C,
thus not topical here.

-Mike
Nov 21 '05 #5
In article <_q***************@newsread2.news.pas.earthlink.ne t>,
Mike Wahler <mk******@mkwahler.net> wrote:
"sudhir" <su*****************@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googleg roups.com...
how to check escape key is pressed when accepting the string as input.

The C language does not see 'keystrokes', it only sees 'streams
of characters' as input. Some character sets, such as ASCII do
define an 'escape' character, but pressing an 'escape' key on
a keyboard might or might not insert such a character into C's
'standard input stream'. Your best bet is to find a platform
specific solution (and ideally isolate it in your code for ease
of porting).


Well, since we don't talk much about Unicode or i18n
(internationalization) here, I don't think we are going -too- far
astray to admit that ASCII characters beyond the basic execution set
exist, and if we do not insist that someone must head to another newgroup
if they don't mind the minor portability loss of assuming ASCII
compatability.
I'm not sure I want to see the "portable" equivilent to

#include <stdio.h>
int main(void) { puts("That's my $0.02 worth!"); return 0; }
--
"No one has the right to destroy another person's belief by
demanding empirical evidence." -- Ann Landers
Nov 21 '05 #6
Walter Roberson wrote:
In article <_q***************@newsread2.news.pas.earthlink.ne t>,
Mike Wahler <mk******@mkwahler.net> wrote:

"sudhir" <su*****************@gmail.com> wrote in message
news:11**********************@g43g2000cwa.google groups.com...
how to check escape key is pressed when accepting the string as input.


The C language does not see 'keystrokes', it only sees 'streams
of characters' as input. Some character sets, such as ASCII do
define an 'escape' character, but pressing an 'escape' key on
a keyboard might or might not insert such a character into C's
'standard input stream'. Your best bet is to find a platform
specific solution (and ideally isolate it in your code for ease
of porting).

Well, since we don't talk much about Unicode or i18n
(internationalization) here, I don't think we are going -too- far
astray to admit that ASCII characters beyond the basic execution set
exist, and if we do not insist that someone must head to another newgroup
if they don't mind the minor portability loss of assuming ASCII
compatability.

We don't talk about Unicode or i18n at all. There are no ASCII
characters beyond the basic execution set (0..127). There is no 8-bit
ASCII character. Not One.
I'm not sure I want to see the "portable" equivilent to

#include <stdio.h>
int main(void) { puts("That's my $0.02 worth!"); return 0; }


I don't see anything obviously wrong. What's the problem?
--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Nov 23 '05 #7
Joe Wright <jw*****@comcast.net> writes:
Walter Roberson wrote:

[...]
I'm not sure I want to see the "portable" equivilent to
#include <stdio.h>
int main(void) { puts("That's my $0.02 worth!"); return 0; }


I don't see anything obviously wrong. What's the problem?


'$' is not guaranteed to be a member of the execution character set.
(Though if it isn't, I don't think there's even a non-portable way to
do the same thing, unless you allow replacing '$' by 'USD'.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 23 '05 #8

"Walter Roberson" <ro******@ibd.nrc-cnrc.gc.ca> wrote in message
news:dl**********@canopus.cc.umanitoba.ca...
In article <_q***************@newsread2.news.pas.earthlink.ne t>,
Mike Wahler <mk******@mkwahler.net> wrote:
"sudhir" <su*****************@gmail.com> wrote in message
news:11**********************@g43g2000cwa.google groups.com...
how to check escape key is pressed when accepting the string as input.

The C language does not see 'keystrokes', it only sees 'streams
of characters' as input. Some character sets, such as ASCII do
define an 'escape' character, but pressing an 'escape' key on
a keyboard might or might not insert such a character into C's
'standard input stream'. Your best bet is to find a platform
specific solution (and ideally isolate it in your code for ease
of porting).


Well, since we don't talk much about Unicode or i18n
(internationalization) here, I don't think we are going -too- far
astray to admit that ASCII characters beyond the basic execution set
exist,


I never denied that they do.
and if we do not insist that someone must head to another newgroup
if they don't mind the minor portability loss of assuming ASCII
compatability.
But an implementation can be fully 'ASCII compatible', without
necessitating platform-specific behavior, such as keyboard
interfaces. After all, the ASCII standard makes no requirements
pertaining to keyboards.

Or have I somehow misunderstood whatever point you're
trying to make?


I'm not sure I want to see the "portable" equivilent to

#include <stdio.h>
int main(void) { puts("That's my $0.02 worth!"); return 0; }


The portable equivalent isn't that bad:
Insert #include <locale.h> and one call to 'setlocale()'.

(That is, unless you demand the
current exchange rate taken into account). :-)

-Mike
Nov 23 '05 #9

"Mike Wahler" <mk******@mkwahler.net> wrote in message
news:gT*****************@newsread3.news.pas.earthl ink.net...

"Walter Roberson" <ro******@ibd.nrc-cnrc.gc.ca> wrote in message
news:dl**********@canopus.cc.umanitoba.ca...
I'm not sure I want to see the "portable" equivilent to

#include <stdio.h>
int main(void) { puts("That's my $0.02 worth!"); return 0; }


The portable equivalent isn't that bad:
Insert #include <locale.h> and one call to 'setlocale()'.


and 'localeconv()' (which of course means using 'printf()'
instead of 'puts()'
-Mike
Nov 23 '05 #10
On 2005-11-21, Joe Wright <jw*****@comcast.net> wrote:
We don't talk about Unicode or i18n at all. There are no ASCII
characters beyond the basic execution set (0..127).


The basic execution character set only contains 96 characters:

NUL TAB LF VT SP
! " # % & ' ( ) * + , - . / : ; < = >
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _
a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~

ASCII contains, according to you, 0..127, including 32 that are not in
the basic execution set:

SOH STX ETX EOT ENQ ACK BEL BS FF CR SO SI
DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US
$ @ ` DEL
Nov 23 '05 #11
In article <eq********************@comcast.com>,
Joe Wright <jw*****@comcast.net> wrote:
[I wrote]
Well, since we don't talk much about Unicode or i18n
(internationalization) here, I don't think we are going -too- far
astray to admit that ASCII characters beyond the basic execution set
exist,
We don't talk about Unicode or i18n at all. There are no ASCII
characters beyond the basic execution set (0..127). There is no 8-bit
ASCII character. Not One.
All that C guarantees about the basic execution set is that it
includes the basic source set together with alert, backspace, carriage
return, and newline. No promises are made about the values that
any of the 91 mandated printable characters will assume upon execution,
other than that 0 thru 9 shall be consequative.
There are no ASCII
characters beyond the basic execution set (0..127).
But the basic execution set is *not* 0..127: it is the 91 printables,
and a handful of whitespace and control characters, no matter -what-
values those assume internally. Executing in EBCDIC is perfectly legal
in C.
I'm not sure I want to see the "portable" equivilent to #include <stdio.h>
int main(void) { puts("That's my $0.02 worth!"); return 0; }

I don't see anything obviously wrong. What's the problem?
You have assumed the existance of characters beyond the basic
execution set -- in this case, the existance of the dollar sign.
And by your comments, you have assumed ASCII.

In C, any use of information such as 'A' == 65 or 'A' + 1 == 'B'
is non-portable. Any use of @, $, or ` is non-portable.
Any assumption of the existance of escape or any control other than
\a \b \t \n \r \t \v is not portable.

We don't talk about Unicode or i18n at all.


Quite -- and yet we also do not wag our fingers every time someone
uses $ or build in an assumption about character values into their
programs. To be consistant, every time someone uses $ or @ or `
we should be telling them to go find another newsgroup because
they have used a system-specific feature... but we don't.

This suggests to me that in clc, the presumption of ASCII is
-generally- acceptable, except in contexts where it is obviously
inappropriate, such as for programs that are inherently multilingual.
--
I was very young in those days, but I was also rather dim.
-- Christopher Priest
Nov 23 '05 #12
Walter Roberson wrote:

I'm not sure I want to see the "portable" equivilent to

#include <stdio.h>
int main(void) { puts("That's my $0.02 worth!"); return 0; }


#include <stdio.h>
int main(void) { puts("That's my 2c worth!"); return 0; }

Nov 23 '05 #13
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Old Wolf wrote:
Walter Roberson wrote:

I'm not sure I want to see the "portable" equivilent to

#include <stdio.h>
int main(void) { puts("That's my $0.02 worth!"); return 0; }

#include <stdio.h>
int main(void) { puts("That's my 2c worth!"); return 0; }


#include <stdio.h>
int main(void) { puts("That's my 2c\b| worth!"); return 0; }
- --
Lew Pitcher

Master Codewright & JOAT-in-training | GPG public key available on request
Registered Linux User #112576 (http://counter.li.org/)
Slackware - Because I know what I'm doing.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.7 (GNU/Linux)

iD4DBQFDgpA0agVFX4UWr64RAjGbAJY56Noq7sXDzIBIyEKFt2 A9y8qMAKCv2S+D
B2eDeeGfp2ynosenroWT3Q==
=TQn4
-----END PGP SIGNATURE-----
Nov 23 '05 #14
Jordan Abel wrote:
On 2005-11-21, Joe Wright <jw*****@comcast.net> wrote:
We don't talk about Unicode or i18n at all. There are no ASCII
characters beyond the basic execution set (0..127).

The basic execution character set only contains 96 characters:

NUL TAB LF VT SP
! " # % & ' ( ) * + , - . / : ; < = >
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _
a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~

ASCII contains, according to you, 0..127, including 32 that are not in
the basic execution set:

SOH STX ETX EOT ENQ ACK BEL BS FF CR SO SI
DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US
$ @ ` DEL


I wonder how I've missed that? Thank you.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Nov 23 '05 #15
In article <sl********************@random.yi.org>,
Jordan Abel <jm****@purdue.edu> wrote:
The basic execution character set only contains 96 characters: NUL TAB LF VT SP
! " # % & ' ( ) * + , - . / : ; < = >
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _
a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~
That is the basic source set, not the basic execution set, except that
LF is not part of the basic source set.
ASCII contains, according to you, 0..127, including 32 that are not in
the basic execution set: SOH STX ETX EOT ENQ ACK BEL BS FF CR SO SI
DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US
$ @ ` DEL


The basic execution set includes alert and backspace and carriage return
and linefeed (translated to BEL BS CR LF in ASCII), as well as the
basic source set.
--
Prototypes are supertypes of their clones. -- maplesoft
Nov 23 '05 #16
On Mon, 21 Nov 2005 18:39:48 +0000 (UTC), ro******@ibd.nrc-cnrc.gc.ca
(Walter Roberson) wrote:
<snip>
The escape key isn't portable ;-)

If you have an input string that you know to be ASCII (or ISO-8859-*)
or 646.* or 10646/Unicode, while we're at it
then you can test each character against the ASCII escape value, which
you can code in several different ways. One such way would be

#include <string.h>
#define ESCAPE '\027'

<ahem> \033 </>

For those who remember back to bit-paired keyboards like Teletypes,
'[' & ~ '@' might be clearer. Or, maybe not. :-)

ObCLC: macro-names beginning with E are reserved if you use <errno.h>,
which wasn't in your example but might be in a real program.

- David.Thompson1 at worldnet.att.net
Dec 5 '05 #17

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

Similar topics

2
by: Binny V A | last post by:
Hello Everyone, I am new to python and I am trying to get a program to close a application when the Escape Key is pressed. This is the code that I used ---------------------------------...
18
by: Steve Litvack | last post by:
Hello, I have built an XMLDocument object instance and I get the following string when I examine the InnerXml property: <?xml version=\"1.0\"?><ROOT><UserData UserID=\"2282\"><Tag1...
0
by: YiFai | last post by:
Hello, I'm currently writing a directx program with C++, but it takes a while to load the files necessary for the directx. When the directx window loads, it can quit the program with the...
12
by: Jeff S | last post by:
In a VB.NET code behind module, I build a string for a link that points to a JavaScript function. The two lines of code below show what is relevant. PopupLink = "javascript:PopUpWindow(" &...
0
by: Asif Mohammed | last post by:
Hello, I have a datagridview bound to a database table with 2 columns. One is an ID column "NameID" which is hidden, the other is called "Name". The schema picture is here :...
0
by: Asif Mohammed | last post by:
Hello, I have a datagridview bound to a database table with 2 columns. One is an ID column "NameID" which is hidden, the other is called "Name". The schema picture is here :...
2
by: Richard Lewis Haggard | last post by:
How does one specify the Escape key as an accelerator? My client has specified that the Escape key be used as an accelerator for a particular menu item. In VS05's designer mode, this particular...
6
by: ARC | last post by:
I know this should be simple, but in a sub-routine that's printing a large batch of reports, how do you code the routine to look for an escape key to allow the user to break out? Thanks! Andy
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
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...
0
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...
0
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...

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.