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
85
votes
6 answers

What is the equivalent to getch() & getche() in Linux?

I am not able to find the equivalent header file for conio.h in Linux. Is there any option for getch() & getche() function in Linux? I want to make a switch case base menu where the user will give his option just by pressing one key & process should…
Jeegar Patel
  • 26,264
  • 51
  • 149
  • 222
53
votes
11 answers

getch and arrow codes

I'm writing a programm that's using getch() to scan for arrow keys. My code so far is: switch(getch()) { case 65: // key up break; case 66: // key down break; case 67: // key right break; case 68: …
qwertz
  • 14,614
  • 10
  • 34
  • 46
46
votes
6 answers

How to get a single character without pressing enter?

How can I get a single keyboard character from the terminal with Ruby without pressing enter? I tried Curses::getch, but that didn't really work for me.
Nino
  • 5,261
  • 4
  • 22
  • 15
45
votes
7 answers

Python method for reading keypress?

I'm new to Python, and I just made a game and a menu in Python. Question is, that using (raw_)input() requires me to press enter after every keypress, I'd like to make it so that pressing down-arrow will instantly select the next menu item, or move…
user1632861
29
votes
3 answers

Non-blocking getch(), ncurses

I'm having some problems getting ncurses' getch() to block. Default operation seems to be non-blocking (or have I missed some initialization)? I would like it to work like getch() in Windows. I have tried various versions…
Jonas Byström
  • 25,316
  • 23
  • 100
  • 147
26
votes
12 answers

How to implement getch() function of C in Linux?

In TurboC++, I can use the getch() function from conio.h. But in Linux, gcc doesn't provide conio.h. How can I get the functionality of getch()?
Hits
  • 261
  • 1
  • 3
  • 3
19
votes
3 answers

PyCharm: msvcrt.kbhit() and msvcrt.getch() not working?

I've tried to read one char from the console in PyCharm (without pressing enter), but to no avail. The functions msvcrt.getch() stops the code, but does not react to key presses (even enter), and msvcrt.kbhit() always returns 0. For example this…
user4953886
  • 191
  • 1
  • 1
  • 3
17
votes
5 answers

Using kbhit() and getch() on Linux

On Windows, I have the following code to look for input without interrupting the loop: #include #include #include int main() { while (true) { if (_kbhit()) { if (_getch() == 'g') …
Boxiom
  • 2,245
  • 6
  • 40
  • 51
13
votes
5 answers

Equivalent to Windows getch() for Mac/Linux crashes

I am using getch() and my app crashes instantly. Including when doing: int main() { getch(); } I can't find the link but supposedly the problem is that it needs to turn off buffering or something strange along those lines, and I still want cout…
user34537
10
votes
2 answers

Why getch() returns before press any key?

int main(int argc, char *argv[], char *env[]) { printf("Press any key to exit.\n"); getch(); return 0; } According to the man page, getch should wait until any key is pressed ...but in fact it returns directly before press any key.…
new_perl
  • 7,345
  • 11
  • 42
  • 72
10
votes
4 answers

C exit from infinite loop on keypress

How can I exit from an infinite loop, when a key is pressed? Currently I'm using getch, but it will start blocking my loop as soon, as there is no more input to read.
user196106
10
votes
2 answers

Non blocking getch()

I'm trying to make Tetris game in standard console. I need non-blocking getch(), so the blocks can fall without pressing any key. It would be nice to have function that returns -1 if no key pressed, otherwise the key code.
noisy cat
  • 2,865
  • 5
  • 33
  • 51
9
votes
3 answers

curses library: why does getch() clear my screen?

I'm trying to learn the curses library (pdcurses, as I'm in Windows OS), with C++. I have a program that displays 3 windows, then a while loop to do some processing based in key presses captured by getch(). The loop gets exited when the F1 key is…
user2948911
  • 113
  • 1
  • 4
8
votes
2 answers

Python input single character without enter

What I am trying to do is make a simple pi memorization game in Python. What I need is a way to get input from the user without having to press 'enter' after every character. It sounds like I need something like getch, but I can't get it to work. …
ArgoLake
  • 81
  • 1
  • 1
  • 3
8
votes
7 answers

Equivalent function to C's "_getch()" in Java?

I use Google Wave, and I want to emulate the ability to send messages before you actually hit the enter key. Is there a Java equivalent to the C function _getch()?
Pandemic21
  • 81
  • 2
  • 2
  • 4
1
2 3
19 20