?
Solved

Escape sequence for 'N' key

Posted on 2003-10-26
5
Medium Priority
?
339 Views
Last Modified: 2010-04-15
I am programming a game. By pressing the 'up arrow' key, I cursor is move upwards. The escape sequence for pressing 'up arrow' key is ESC [ A. My problem is I want to start a new game when the 'N' key is pressed. What is the escape sequence for the 'N' key?

Can anyone help me out?
Martyn
0
Comment
Question by:Binkru
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 23

Accepted Solution

by:
brettmjohnson earned 80 total points
ID: 9624892
I'm not sure what you are asking.  The 'N' key does not produce an escape sequence.
It produces 'n', assuming no modifier keys (shift, alt, control) are pressed.

I would check for 'n' or 'N'

0
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 9626998
Hi Binkru,

Keyboard input has a few oddities that can vary from o/s to o/s.  You probably need to be aware of at least a few of them.

The displayable ASCII characters (those on the keyboard that echo exactly what you see on the key) have a value that is equal to the quoted character.  Testing for an 'N' being pressed on the keyboard is a simple if statement:

if (Key == 'N')

Testing for 'N' without regard to case can be done several ways.  All of these work equally well:

if (Key == 'N' || Key == 'n')

if (toupper (Key) == 'N')

if (tolower (Key) == 'n')


Testing for keypresses other than "normal" characters has a few pitfalls.

Some keys map to a single character.  ESC (0x1B), TAB (0x09), Carriage Return (0x0A), Line Feed (0x0D), etc.

Other keys require several characters.  The function keys (F1, F2, etc) may be represented by an Escaped sequence (F6 = ESC [ 1 6 ~   without spaces!).  Depending on the keyboard and O/S, function keys are sometimes represented by a simple two character combination where the first character is 0.  The Escaped form can be immitated by pressing the correct keys in the correct order.  The second form can not.

For the most part, assume that if the character is shown as a single character on the keycap then C will recognize the quoted character as exactly what you'd expect.  If the keycap contains arrows or words (like HOME, ENTER, etc) then an escaped sequence is what you'll need to test for.  And some keys like Ctrl, Alt, and Shift don't return a value directly to your application.  These keys simply modify the value returned from the keyboard.  (Actually, you can test for any of these keys being pressed, but you need to get to a lower level than gets() or read().)


Good Luck,
Kent



Good
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9886692
No comment has been added lately and this question is therefore classified abandoned.

If asker wishes to close the question, then refer to
http://www.experts-exchange.com/help/closing.jsp

Otherwise, I will leave a recommendation in the Cleanup topic area that this question is:
PAQed with A grade to  brettmjohnson

Please leave any comments here within the next seven days. It is assumed that any participant not responding to this request is no longer interested in its final disposition.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Sunny
EE Cleanup Volunteer
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Suggested Courses
Course of the Month9 days, 16 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question