Solved

Trapping Keyboard keys.

Posted on 2000-03-13
4
278 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

830 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