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
2
votes
1 answer

How to run a side task while also waiting for getch?

So I have this small program (using Linux): import getch while True: print("Hello World!") key = getch.getch() if key == 'q': break So all it does is wait for the user to hit a key, and they displays "Hello World!" to the console.…
Alex
  • 462
  • 1
  • 7
  • 19
2
votes
2 answers

Reading and printing one char at a time - getche() and backspace in Python

I want to create typing training program. I need a function which immediately both reads and prints each character user hits - something like getche() I have tried using getche from this module but it doesn't deal well with backspaces. When I hit…
user3565923
  • 153
  • 2
  • 12
2
votes
0 answers

OverflowError: character argument not in range(0x110000) using getch in python 3.5

I get overflow error using getch in ubuntu. This is the code: import getch print("Inserisci 8 caratteri esadecimali: ") allowedChar = '0123456789abcdefABCDEF' contatore = 0 uuid = "" while contatore < 8: char = getch.getch() # User input, but…
2
votes
1 answer

How to avoid pressing enter in a portable context to empty the input buffer?

The Problem I usually use fgets() or getchar(), but now I need to use getch(), because I don't want to press enter to send a char to the input buffer. What I tried When I used fgets() and getchar() I also used: int c; while ((r = getchar()) != '\n'…
2
votes
1 answer

msvcrt.getch() detects space every time

Im writting a simple python code that should detect the my keystrokes but for some reason in detects space after everysingle keystroke. The code: import msvcrt print("press 'escape' to quit...") text="" while 1: char = msvcrt.getch() …
2
votes
1 answer

Non blocking reads with Julia

I would like to read an user input without blocking the main thread, much like the getch() function from conio.h. Is it possible in Julia? I tried with @async but it looked like my input wasn't being read although the main thread wasn't blocked.
2
votes
1 answer

C: ncurses, initscr() changes behaviour of getchar()?

I am just playing around with ncurses and so, and I discovered a really weird behaviour. When i use initscr() from the ncurses lib, and afterwards i use a normal getchar(), then the program terminates after pressing the first key. The normal…
Reppiz
  • 23
  • 5
2
votes
1 answer

python curses nodelay getch not responsive

This code runs for 1 million iterations (about a few seconds on my machine), yet when I hold down a button, the # iterations where I hold down does not increase substantially. import curses stdscr =…
2
votes
2 answers

getch() does display most recently typed character and skips every other character entered

Working on an assignment for class and have been battling ncurses for a while now (it's new to me). Creating a program that is able to communicate with another instance of the same program across a network. Part of the program is to interactively…
J Moonham
  • 35
  • 5
2
votes
3 answers

Why doesn't getch() read the last character entered?

I am writing a snake game in C using the ncurses library, where the screen updates itself every second. As those who have played the game will know, if the user enters various keys or holds down a key for long, there should be no 'buffered' key…
sigma
  • 188
  • 1
  • 11
2
votes
2 answers

Why printf("\n") doesn't go to the next line?

I'm trying to write a short program that puts each word on a new line. The new line can be confirmed by tabulator, space or enter. The end of program is putting "#" in console. I have the problem that when I put "enter" to the console it writes…
shurrok
  • 795
  • 2
  • 13
  • 43
2
votes
4 answers

How do I use pointers in combination with getc?

I have a function getNum(), which gets a number from file and returns it. When I go back into getNum() I have lost the pointer and it starts at the begging of the file again. I'm wondering How do I get the location of where getc is and then go back…
John
  • 41
  • 1
  • 1
  • 3
2
votes
4 answers

a simple getch() and strcmp problem

I have this simple problem that gets an input from the user using a function then checks if the input is 'equal' to the "password". However, strcmp would never return my desired value, and the culprit is somewhere in my loop that uses getch() to…
arscariosus
  • 1,326
  • 2
  • 13
  • 19
2
votes
1 answer

portable alternative to kbhit() and getch() and system("cls")

I need a way to use kbhit and getch functionality in a portable way. I'm currently developing a simple ascii game and I need to detect if a key is pressed. If it is I need to read it and if it isn't I need to continue without waiting for input. I…
2
votes
4 answers

Go back to the beginning of switch (getch() ) in the default ? (c)

I am currently coding in C and using switch & getch, like this : c=getch(); switch(c) { case 17: //something break; case 19: //something else break; …
Acajou
  • 21
  • 1
  • 2