Solved

Trapping Keyboard keys.

Posted on 2000-03-13
4
277 Views
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.

--begin
0
Comment
Question by:begin
  • 2
  • 2
4 Comments
 
LVL 33

Accepted Solution

by:
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>;
         break;
case 65: <do something>;
         break;
}

13 = enter
65 = 'A'

This is a guideline for you.

hongjun
0
 

Author Comment

by:begin
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.
--begin
0
 
LVL 33

Expert Comment

by:hongjun
ID: 2618470
I think enter should be 10

hongjun
0
 

Author Comment

by:begin
ID: 2618514
what is the difference between newline and carriage return.
--begin
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

831 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