Solved

Escape sequence for 'N' key

Posted on 2003-10-26
5
333 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
5 Comments
 
LVL 23

Accepted Solution

by:
brettmjohnson earned 20 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 45

Expert Comment

by:Kdo
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now