• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 344
  • Last Modified:

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?
1 Solution
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'

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,

No comment has been added lately and this question is therefore classified abandoned.

If asker wishes to close the question, then refer to

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.


EE Cleanup Volunteer

Featured Post

Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now