• C

Escape sequence for 'N' key

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
BinkruAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

brettmjohnsonCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Kent OlsenData Warehouse Architect / DBACommented:
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
sunnycoderCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.