PDCurses getch does not work

910 views Asked by At

I'm using CodeBlocks and just starting out on PDCurses. I was just trying out some stuff and I came to this problem.

#include <iostream>
#include <curses.h>
using namespace std;

int main()
{
    int ch;
    initscr();
    cbreak();
    keypad(stdscr, TRUE);
    noecho();

    ch = getch();
    printw("The key pressed is %d\n", ch);
    refresh();

    return 0;
}

getch() doesn't work. It won't wait for an input, it just goes straight in the print. It just outputs "The key pressed is -1".

1

There are 1 answers

0
William McBrine On

Although it should already be the default behavior, you could try explicitly setting delay mode via nodelay(stdscr, FALSE).