Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 785665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:54:57+00:00 2026-05-14T20:54:57+00:00

I am writing an application involving user input from the keyboard. For doing it

  • 0

I am writing an application involving user input from the keyboard. For doing it I use this way of reading the input:

#include <stdio.h>
#include <termios.h>
#include <unistd.h>

int mygetch( ) {
  struct termios oldt,
                 newt;
  int            ch;
  tcgetattr( STDIN_FILENO, &oldt );
  newt = oldt;
  newt.c_lflag &= ~( ICANON | ECHO );
  tcsetattr( STDIN_FILENO, TCSANOW, &newt );
  ch = getchar();
  tcsetattr( STDIN_FILENO, TCSANOW, &oldt );
  return ch;
}

int main(void)
{
  int c;
  do{
    c = mygetch();
    printf("%d\n",c);
  }while(c!='q');
  return 0;
}

Everyting works fine for letters digits,tabs but when hiting DEL, LEFT, CTRL+LEFT, F8 (and others) I receive not one but 3,4,5 or even 6 keycodes.

The question is: Is is possible to make a separation of these keycodes (to actually know that I only hit one key or key combination).

What I would like is to have a function to return a single integer value for any type of input (letter, digit, F1-F12, DEl, PGUP, PGDOWN, CTRL+A, CTRL+ALT+A, ALT+LEFT, etc). Is this possible?

I’m interested in an idea to to this, the language doesn’t matter much, though I’d prefer perl or c.

Thanks,

Iulian

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T20:54:58+00:00Added an answer on May 14, 2026 at 8:54 pm

    You’ll want to look into the curses or ncurses libraries (or possibly slang).

    Terminals, terminal windows, and the console are all modeled after actual terminals (a screen and a keyboard connected to the computer via a serial cable), and terminals are modeled after a teletype device (tty — which is a keyboard and a simple printer).

    Different terminals (real terminals, psudoterminals, and console) can have different representations for special characters, such as function and arrow keys. They do this because there are potentially more than 256 things that someone might send from between a terminal and a computer.

    One of the many things curses does is takes the input that different terminal gives you and using the terminal type produces an integer which represents that key. It also provides macro constants for these values so KEY_DOWN can be compared to the result from curses’ getch to determine if the down arrow was pressed.

    Check out or , or you can google for curses and get lots of information.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing an application that if the user hits back, it may resend
When writing application code, it's generally accepted that premature micro -optimization is evil, and
im writing an application that downloads and installs addons for programs which needs to
I am writing an application that downloads large files in the background. All clients
I'm writing an application that on some stage performs low-level disk operations in Linux
I am writing an application that needs to bring window of an external app
I'm writing an application that is basically just a preferences dialog, much like the
I'm writing an application to start and monitor other applications in C#. I'm using
I'm writing an application which reads large arrays of floats and performs some simple
I am current writing an application that will require multiple inserts, updates and deletes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.