C menu that moves with the arrow keys on the keyboard?

Asked

Viewed 1,765 times

4

I saw once an algorithm in C where the menu selection had a "mini navigation" if I can call it that, where I used the arrow keys to navigate the menu and enter to select the option, I was curious to know how to do that, can anyone show? Grateful!

  • In stackoverflow, we help fix some code error, or cast doubt on topics considered important in the scope of the site. If you have something ready, it would help a lot to help you

  • @Brumazzidb I haven’t, as I said is a curiosity =/ I haven’t found anything on the internet about it, I wonder if I need some library or something like.

  • 2

    Search for a C lib called "ncurses", is the only one I know that does this.

1 answer

5


I found a way, but it only works with two options in the menu =/

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>

#define KEY_UP 72
#define KEY_DOWN 80
#define KEY_ESC 27
#define KEY_ENTER 13

void menu_draw();

int main (int argc, char ** argv)
{
     menu_draw();
     return 0;
}

void menu_draw ()
{
    int key = 0;
    while(1)
{
    system("cls");
    printf("\n   ******** Menu Principal ********\n");
    printf("   *                              *\n");
    printf("   * %s Opcao 1                    *\n", (key == KEY_UP)? "Û": " ");
    printf("   * %s Opcao 2                    *\n", (key == KEY_DOWN)? "Û": " ");
    printf("   *                              *\n");
    printf("   ********************************\n");
    key = getch();

    if (key == KEY_ESC)
        return;
    }
}
  • this is the solution of the question or a new doubt?

  • A solution I found researching.

  • Got it, you can mark as Accept when the system allows. It was looking like a new question in the answer text.

  • Rsrs quiet friend.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.