Questions tagged [getch]

Questions relating to the use of the DOS getch() function

getch() is defined in <conio.h>, a header file used mostly by MS-DOS compilers to provide console input/output.

This function is provided on Microsoft platforms, but is not in the C standard library, nor in POSIX.

It is similar to the standard library getchar(), but disables terminal echo of the character that is returned.

299 questions
4
votes
1 answer

ncurses: why doesn't getch wait until I press a key?

From the ncurses(3) linux man page: The nodelay option causes getch to be a non-blocking call. If no input is ready, getch returns ERR. If disabled (bf is FALSE), getch waits until a key is pressed. Why doesn't in my example getch wait until I…
sid_com
  • 24,137
  • 26
  • 96
  • 187
4
votes
3 answers

getch not working without initscr

I gone through the Documentation of NCURSES. I am not getting that if I use getch without initscr then why this program is not working. Is there any other approach to get arrow keys input without clearing screen (that initscr do). #include…
piyush-balwani
  • 524
  • 3
  • 15
4
votes
2 answers

Python Windows `msvcrt.getch()` only detects every 3rd keypress?

My code is below: import msvcrt while True: if msvcrt.getch() == 'q': print "Q was pressed" elif msvcrt.getch() == 'x': sys.exit() else: print "Key Pressed:" + str(msvcrt.getch() This code is based on this…
evamvid
  • 831
  • 6
  • 18
  • 40
4
votes
1 answer

(Python Beginner's Help) getch?

I am making a game. I want people to run main.py then they come across a little menu with options. Atm I am getting an error. So here are the 3 files: ascii.py: #------------------------------------------------------------------------------- #…
gogobebe2
  • 324
  • 2
  • 4
  • 18
4
votes
2 answers

Ncurses reading numpad keys and escaping

I am trying to use ESC to escape from a program using getch(). I created a small program to demonstrate my problem. #include int main(void) { int key = 0; initscr(); noecho(); keypad(stdscr, TRUE); do { …
Ambiguities
  • 415
  • 6
  • 18
4
votes
2 answers

getch() waits for Enter key?

Possible Duplicate: C/C++: Capture characters from standard input without waiting for enter to be pressed I'm using C-Free 4 Standard on windows 7 and I writing a C program. I'm using getch() as a function to pause the program, however, the…
Raam Kumar
  • 127
  • 2
  • 11
4
votes
5 answers

What exactly getch() does in C?

I thought (upto now) that the function of getch() reads a character from input buffer (or keyboard, to be simple). But i had to argue with my lab instructor. They say that the only work of getch() is to hold the program execution. I know that…
cipher
  • 2,414
  • 4
  • 30
  • 54
4
votes
2 answers

getch expects extra character

Hello I am new to programming and I am writing a program in C. In my header file I have this macro: #define yesno(c) (c==ENTER || c==' ' || c=='\t') ? ENTER : ESC In my program I have this code char keypressed() { char c; c =getch(); return…
Geo Man
  • 43
  • 3
4
votes
2 answers

Reading a single character (getch style) in Python is not working in Unix

Any time I use the recipe at http://code.activestate.com/recipes/134892/ I can't seem to get it working. It always throws the following error: Traceback (most recent call last): ... old_settings = termios.tcgetattr(fd) termios.error: (22,…
Evan Fosmark
  • 98,895
  • 36
  • 105
  • 117
3
votes
1 answer

ncurses app in C - reading standard input

I'm writing a simplified version of Linux standard less command for OS academic classes, and I'm allowed to use ncurses to make it easier. "Simplified" means that the user should be able to scroll the view with arrows, PgUp, PgDown, and also use g…
PiotrK
  • 1,502
  • 1
  • 15
  • 33
3
votes
2 answers

Is it possible to use getch() to obtain inputs of varying length?

I've taken up the adventure of creating a relatively small command-line RPG to flex my newfound Python muscles, but I've already run into a conundrum. I'm using this implementation of getch(): def getch(): fd = sys.stdin.fileno() …
Hexagon Theory
  • 43,627
  • 5
  • 26
  • 30
3
votes
1 answer

Is there an equivalent of getch() function in Mac?

I am not able to find the equivalent header file for conio.h (for C programs) in Mac. I was wondering if there is any option for getch() function in Mac? I want to use it such that user can give options and program will go forward without pressing…
3
votes
1 answer

How to print with getch() in one line?

I have a problem in python3 .I want to print the "#" in only one line when I push "a" button in keyboard ,but with this code when I push for example 10 times the "a" ,doesn't appear the "#" ,but when I push the "q" button ,all "#" appears. Why is…
3
votes
2 answers

after getch() the program ignores the if even after putting 1-6.

I have a problem with my code. It always ignoring the if(userDigit<=6 && userDigit>=1).. Can someone tell me what is wrong here? for(i=0; i<4; i++) { userDigit=getch(); putch(userDigit); …
linoiushi
  • 47
  • 6
3
votes
1 answer

Can't seem to get .getch() to work (Python 2.7)

I'm trying to detect a key press to determine whether the user wants to play again, but msvcrt.getch() is just not working for me. This is my code: import msvcrt #the game here print "Do you want to continue? Y/N" if msvcrt.getch() == 'Y' or…
sOfekS
  • 85
  • 6
1 2
3
19 20