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
0
votes
2 answers

Redraw delay when using getch() with timeout() set

I have ncurses program where I need instant response to user input and term resize and 1 sec delay between redraws. By using sleep(1) I got instant redraw on startup and term resize but 1 sec delay on user input. By using timeout(1 * 1000) and…
Ari Malinen
  • 576
  • 2
  • 6
  • 20
0
votes
1 answer

_getch returns smiley faces

I'm trying the function below to get a filename while allowing for 'ESC' press to go back but for some reason _getch() always returns [1 '\x1'] and what is being printed is a smiley face, even for BackSpace (which is nice and all, but absolutely not…
user2962533
  • 397
  • 1
  • 5
  • 18
0
votes
4 answers

Is there a way to replace the kbhit() and getch() functions in Standard C?

I'm trying to get a quick time event type of interaction with the console and I managed to obtain it using the conio library. Sadly the project I'm working on requires the code to be compilable on both Windows and Linux and I can't figure out a way…
user3481786
  • 1
  • 1
  • 1
0
votes
1 answer

Why Screen is not disappears in Linux as compared to Windows?

I'm beginner in C programming. When I programmed in Windows using any Compiler then to hold the screen I used getch(). Without it when I run the program, the screen suddenly disappears. But when I did same thing in Linux, there is no need of…
ranaarjun
  • 245
  • 3
  • 5
  • 12
0
votes
1 answer

C++ Differentiating Key Press vs Key Release

I'm currently listening to keyboard inputs through a getch() while loop and everything is working great. However, if I'm holding left and press up, then the left movement is stopped until I press it again. The only way I can think of solving this…
0
votes
1 answer

Issues with repeated key checking with getch()

I am having issues with repeating key checking using a function that utilizes getch(). Here is a code example: static char g_keybuffer[256]; _Bool IsKeyDown(char c) { char ch; if(kbhit()) ch = getch(); if(ch == -32 || ch ==…
NAME__
  • 625
  • 1
  • 7
  • 17
0
votes
2 answers

+ vs. ?

I want to know what end-users have pressed, so I used getch() . If users pressed Right, I could get 0xE0 0x4D. If users pressed Ctrl+Right, I could get 0xE0 0x47. If users pressed Shift+Right, I could get 0xE0 0x4D. The return of Right and …
Kevin Dong
  • 5,001
  • 9
  • 29
  • 62
0
votes
3 answers

Doesn't complete if statement properly

I want this code to: IF unsaved packets is greater or = 1, then print "There are unsaved packets" "Would you like to saved them?" "Type Y for Yes or N for No" Get user input IF User input = Y then function save ELSE IF User input…
user3103598
  • 185
  • 1
  • 1
  • 10
0
votes
2 answers

If there isn't a keyboard input for a set amount of time skip needing input

I am trying to get a keyboard input, but if it doesn't happen in about half a second I want it to continue to the rest of the loop. I tried using kbhit(); but it won't wait for the input, it just loops with out stopping. This is the loop in…
0
votes
1 answer

c++ tron Player lightcycle move in one direction

I am trying to have the player lightcycle keep moving in one direction without stopping until the player pushes a button to move it in another direction. I am not sure how I could do this with kbhit so please give me some advice! thanks. void…
ssj3goku878
  • 745
  • 3
  • 14
  • 43
0
votes
2 answers

using input function in C on linux, without pressing enter

I wrote a code on windows, using the function getch() from stdio. The thing is I have to use an input function that does not require pressing enter. My code compiles and works perfectly on windows. However, this assignment has to run on linux, and…
Mike
  • 195
  • 2
  • 10
0
votes
2 answers

C - Noob error with simple 3-way comparison

Apologies for the dumb question, I'm a bit of a beginner and am having trouble understanding why the following code will not work correctly. #include #include int main() { int j = ' '; int check = 0; …
Rob Johnson
  • 145
  • 1
  • 1
  • 3
0
votes
1 answer

Ncurses, non-blocking getch misses first character

Im using Linux and ncurses for my application, and i'm using getch as non-blocking using nodelay. The problem is that while looping with getch for the input, it always misses the first character. For example the input "Helloworld" would print up as…
Bennu
  • 3
  • 2
0
votes
2 answers

Random Generator within range

Hi i know that there is already a question for the random generator within range, but I don't understand it. I am a beginner in C, and I only know java. In this program I am trying to create a math tutor in C. The program will randomly generate two…
eLg
  • 519
  • 4
  • 11
  • 25
0
votes
1 answer

Twitter like "characters left" function problems in C: How to prevent it from going to the next line?

Like my last question, this concerns my school project. I have to do a "twitter like" program in C and i'm having a small layout problem. Please, keep in mind that i'm aware that this code is not optimized and i am first "playing around" to get the…
blackjak231
  • 174
  • 1
  • 11