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
1
vote
0 answers

C not reading second getch()

My C program does not let me read the second getch() value. Does anyone know what's wrong with it?? #include #include #include #include #include struct user{ char…
NevinTroy
  • 13
  • 5
1
vote
1 answer

Why does _getch() still wait for enter instead of directly registering the user input?

I would like to use arrow keys user input without the user having to press enter every time after clicking the arrow. Therefore, I decided to use _getch(), which allegedly does exactly that. It is part of the conio.h library, which I imported.…
HeroCODE
  • 13
  • 4
1
vote
1 answer

python using ord() with getch() to get unicode

i am learning python at the moment and i tried to get keyboard input, without the need to press the enter key with getch() and ord() in order to work with the (at least for me) gibberish that returns from getch(). in my understanding getch() returns…
077479
  • 13
  • 3
1
vote
1 answer

How to run a function (in Python) when user presses a specific key?

I tried this from msvcrt import getch while True: key = ord(getch()) if key == 27: #ESC print("You pressed ESC") elif key == 13: #Enter print("You pressed key ENTER") but it works only in terminal, i want to run a…
Himanshu Kawale
  • 389
  • 2
  • 11
1
vote
1 answer

Arrows keys for getch in python

I want to capture arrow keys in python linux: import getch as gh ch = '' while ch != 'q': print(ch) ch = gh.getch() k = ord(ch) print(k) # my question is: if k or ch = ??? …
Ahmad
  • 8,811
  • 11
  • 76
  • 141
1
vote
1 answer

How to concatenate a string at the end of another string after using getch

For this code: #include #include #include int main() { std::string a; char c{}; while (c != '\r') { c = getch(); a += c; } a += "xyz"; std::cout << a; } Input: 12345, then…
anonymous38653
  • 393
  • 4
  • 16
1
vote
2 answers

getch() like function in dart

In the c/c++ languages, there is a function in the conio.h header file called getch() which lets you input only 1 character and doesn't echo it on the screen and once that character has been typed, it automatically goes to the next line of code…
Mr No Name
  • 46
  • 3
1
vote
0 answers

Why pressing on some keyboard keys is considered as two presses?

#include #include #pragma warning(disable : 4996) int main() { while (true) std::cout << "-----\n" << getch() << "\n-----\n"; } That's what I get If I press the space key: ----- 32 ----- If I press the del key…
StackExchange123
  • 1,871
  • 9
  • 24
1
vote
1 answer

C Masking Password with getch() using ncurses Library

I have this simple Program and i have achieved hiding password with *. printf("Password: "); initscr(); noecho(); char passwd[MAX_PASS] int p=0; do{ passwd[p]=getch(); if(passwd[p]!='\n'){ printw("*"); …
Panagiss
  • 3,154
  • 2
  • 20
  • 34
1
vote
1 answer

I'm writing a C program and I can't figure out how to insert "Press any key to continue..." and have it continue after any key and not just enter

I'm writing a menu driven program with a switch statement and while loop. My prof wants us to include "Press any key to continue..." and says to use getchar() for this. He says we will lose points if it requires us to press enter, which is what…
1
vote
1 answer

getch() equivalent in Swift: read a single character from stdin without a newline

I'm looking for a Swift function like getch() from C to read a single character from terminal input without requiring the user to press the return key. getchar() and readLine() are not sufficient, as they both require return. There's a getch()…
1
vote
1 answer

why does following code give different output in C , Python?

I want to implement the input taking process of $cat in Unix. Inside an infinite loop, whenever I'll press any key, the corresponding letter will be printed on the screen. If I press ctrl+d, loop will get terminated. This TurboC code does exactly…
Debtanu Gupta
  • 65
  • 1
  • 6
1
vote
1 answer

most of the code doesn't show up only the welcome message and "enter pin"?

Assignment: When you enter an incorrect number of digits( 3 or 5 digits pin number) a message should display “You have entered the incorrect pin number!!...you must enter a four digits pin number.” By showing the message that was display previously…
Alex_
  • 47
  • 4
1
vote
1 answer

How can I make msvcrt.getch() behave the same way in mintty as in cmd?

I'm trying to invoke functions on key press in python. When the script is run in Windows command line (cmd.exe), everything works as expected. But usually when I'm on Windows, I use mintty. In mintty, the application behaves different. The getch()…
birgersp
  • 3,909
  • 8
  • 39
  • 79
1
vote
2 answers

Ncurses flickers when using pipes or redirection

Ncurses flickers when using "unix pipes" and "redirection" for input. That is, it draws fine if I input myself but doesn't when using '|' or '<'. I thought this might be due to getch() delay modes(no delay, half delay and infinite delay). So I…