Trapping Keyboard keys.

Posted on 2000-03-13
Last Modified: 2008-02-26
I am running gcc under solaris.  I need to trap keyboard keys. Say if the user hits "enter" key, i need to trigger some action based on it. I came to know that the ascii value of "enter"(for ex.) is 13 (hope this is right). Please help me how to check the keys.

Question by:begin
  • 2
  • 2
LVL 33

Accepted Solution

hongjun earned 20 total points
ID: 2615198
You may want to accept the keyboard input into a char variable and then use a case statement to check the value of the variable.

switch (variable)
case 13: <do something>;
case 65: <do something>;

13 = enter
65 = 'A'

This is a guideline for you.


Author Comment

ID: 2618246
Thanks, but i dont' get for the enter key, i think the value 13 is incorrect. But in the man page for ascii, decimal value 13 is for CR.
then why is that i dont get.
LVL 33

Expert Comment

ID: 2618470
I think enter should be 10


Author Comment

ID: 2618514
what is the difference between newline and carriage return.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

910 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

18 Experts available now in Live!

Get 1:1 Help Now