Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 283
  • Last Modified:

Trapping Keyboard keys.

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
begin
Asked:
begin
  • 2
  • 2
1 Solution
 
hongjunCommented:
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
 
beginAuthor Commented:
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
 
hongjunCommented:
I think enter should be 10

hongjun
0
 
beginAuthor Commented:
what is the difference between newline and carriage return.
--begin
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now