Questions tagged [kbhit]

kbhit is a C/C++ function used to determine if a key has been pressed or not

Prototype: int kbhit(void);
Header File: conio.h

If a key has been pressed then it returns a non zero value otherwise returns zero.

Declaration : int kbhit();

How to use:

#include <stdio.h>
#include <conio.h>

main()
{
   while (!kbhit())
      printf("You haven't pressed a key.\n");

   return 0;
}
51 questions
0
votes
1 answer

Waiting maximum of X time for input, then proceeding with the program?

Hello I'm creating a game in C. I want there to be a frame printed every 0.1 seconds. During that time, the user may or may not input using getch(). How do I write such a program? Heres what I can offer you guys to work with. do{ usleep(100000); //…
user3371097
  • 1
  • 1
  • 1
  • 1
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
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
3 answers

C++ kbhit with if statement lag

I have a strange lag reaction in the game I am making when I use kbhit with if statements. However I do not see this same lag problem occur when I am using a switch statement. Here are both my codes in IF and switch. This code below causes lag when…
ssj3goku878
  • 745
  • 3
  • 14
  • 43
0
votes
1 answer

Using multiple _kbhit() in a loop

I have a Spaceship object that has 2 methods. First method is move() char touche; if(_kbhit() != 0) { touche = _getch(); if(touche == 'k' || touche == 'l') { modifyPosition(touche); } } Second method is shoot() char…
user1834464
-5
votes
3 answers

make gives me a error I don't understand with TurboC

I am trying to learn C, for fun. I am using a Linux distro. I am trying to compile a program which uses kbhit(). I found a way to this with TurboC (http://www.sandroid.org/TurboC/#Download). I followed the instructions but make gives me…
Fabien
  • 3
  • 2
1 2 3
4