This shows you the differences between two versions of the page.
— |
c:graphics.h:kbhit [2024/02/16 01:05] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ===== kbhit ===== | ||
+ | |||
+ | |||
+ | ====Syntax of kbhit ==== | ||
+ | <code c> | ||
+ | #include "graphics.h" | ||
+ | int kbhit(void); | ||
+ | </code> | ||
+ | |||
+ | |||
+ | ==== Description of kbhit ==== | ||
+ | <code c> | ||
+ | The kbhit function is available in the winbgim implementation of BGI | ||
+ | graphics. You do not need to include conio.h; just include graphics.h. | ||
+ | The function returns true (non-zero) if there is a character in the input | ||
+ | buffer ready to read. Otherwise it returns false. In order to work, the | ||
+ | user must click in the graphics window (i.e., the Windows focus must be | ||
+ | in the graphics window). | ||
+ | </code> | ||
+ | |||
+ | |||
+ | ==== Example of kbhit ==== | ||
+ | <code c> | ||
+ | #include "graphics.h" | ||
+ | #include <stdio.h>// Provides sprintf | ||
+ | |||
+ | void outintxy(int x, int y, int value); | ||
+ | |||
+ | int main( ) | ||
+ | { | ||
+ | int i; | ||
+ | |||
+ | // Initialize the graphics window. | ||
+ | initwindow(400, 300); | ||
+ | |||
+ | // Convert some numbers to strings and draw them in graphics window: | ||
+ | outtextxy(20, 130, "Click in this graphics window,"); | ||
+ | outtextxy(20, 140, "and then press a key to stop."); | ||
+ | outtextxy(10, 10, "Here are some numbers:"); | ||
+ | for (i = 0; !kbhit( ); i++) | ||
+ | { | ||
+ | outintxy(20 + (i/10)*40 , (i % 10)*+10, i); | ||
+ | delay(4000); | ||
+ | } | ||
+ | |||
+ | closegraph( ); | ||
+ | } | ||
+ | |||
+ | void outintxy(int x, int y, int value) | ||
+ | { | ||
+ | char digit_string[20]; | ||
+ | sprintf(digit_string, "%d", value); | ||
+ | outtextxy(x, y, digit_string); | ||
+ | } | ||
+ | </code> | ||
+ | |||
+ | |||
+ | ==== See also ==== | ||
+ | [[getch]] | ||
+ | |||
+ | |||
+ | ===== output of kbhit example ===== | ||
+ | |||
+ | no output of example at the moment | ||
+ | do not hesitate and add it... | ||
+ | |||
+ | |||