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 993263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:23:42+00:00 2026-05-16T06:23:42+00:00

Basically, I have key detection for my console application, for some reason it’s not

  • 0

Basically, I have key detection for my console application, for some reason it’s not detecting function keys.

Here is my code, I’m using GNU compiler on linux. Any help or ideas would be greatly appreciated.

        refresh();
        key = getch();
        switch(key) {
            case KEY_HOME:      key = HOME;   break;
            case KEY_END:       key = END;    break;
            case KEY_UP:        key = UP;     break;
            case KEY_DOWN:      key = DOWN;   break;
            case KEY_LEFT:      key = LEFT;   break;
            case KEY_RIGHT:     key = RIGHT;  break;
            case KEY_NPAGE:     key = PGDN;   break;
            case KEY_PPAGE:     key = PGUP;   break;
            case KEY_DC:        key = DEL;    break;
            case KEY_IC:        key = INSERT; break;
            case KEY_F(1):      key = F(1);   break;
            case KEY_F(2):      key = F(2);   break;
            case KEY_F(3):      key = F(3);   break;
            case KEY_F(4):      key = F(4);   break;
            case KEY_F(5):      key = F(5);   break;
            case KEY_F(6):      key = F(6);   break;
            case KEY_F(7):      key = F(7);   break;
            case KEY_F(8):      key = F(8);   break;
            case KEY_F(9):      key = F(9);   break;
            case KEY_F(10):     key = F(10);  break;
            case KEY_F(11):     key = F(11);  break;
            case KEY_F(12):     key = F(12);  break;
            case KEY_ENTER:     key = ENTER;  break;
            case KEY_BACKSPACE: key = BACKSPACE; break;
            default:
                //key = F(2); //For any function keypress, it jumps to default
                if (NON_ASCII(key) != 0)
                    key = UNKNOWN;
        }    
  • 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-16T06:23:43+00:00Added an answer on May 16, 2026 at 6:23 am

    I’m not a curses expert, but a bit of reading man pages netted me this program:

    #include <curses.h>
    
    int main()
    {
        int key;
    
        initscr(); cbreak(); noecho();
    
        while (1)
        {
    
            key = getch();
            printw ("%u\n", key);
        }
    
        return 0;
    }
    

    When I press an F key, I get a 3-character sequence: 27, 79, (80 + N-1) where N is the number of the F key. I think your switch will have to recognize that the key is an escape sequence and handle it specially.

    Edit: That pattern holds only for F1-F4. F5 changes it up. You’ll probably want to incorporate the F(n) macros from curses.

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

Sidebar

Related Questions

Basically I have some code that keeps seg faulting. The reason is because the
I basically have a unix process running and it is doing some heavy processing
Basically I have a table with two-field primary key column (memberid, messageid) and I
I have defined a ConfigurationProperty class, which is basicly a key-value pair (with key
I basically have a program that filters records from one excel file to another
I basically have three tables, posts, images and postimages (this simply contains the ids
I basically have a server set up and I'm accepting new clients(UNIX) and i'm
I basically have the following string in the format: A,B,C:D,E,F What I am trying
I basically have 7 select statements that I need to have the results output
I basically have to do a update of a record. I have a set

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.