[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Escape sequence for 'N' key

Posted on 2003-10-26
5
Medium Priority
?
342 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
3 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
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 opening and writing to files in the C programming language.
Suggested Courses

834 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