Solved

Trapping Keyboard keys.

Posted on 2000-03-13
4
274 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
Comment Utility
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
Comment Utility
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
Comment Utility
I think enter should be 10

hongjun
0
 

Author Comment

by:begin
Comment Utility
what is the difference between newline and carriage return.
--begin
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

772 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

10 Experts available now in Live!

Get 1:1 Help Now