Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //C code that does not work (yet), with syntax highlighting.
- //$ cat getch.c
- #include <stdio.h>
- #include <ncurses.h>
- #include <unistd.h> /* only for sleep() */
- int kbhit(void)
- {
- int ch = getch();
- if (ch != ERR) {
- ungetch(ch);
- return 1;
- } else {
- return 0;
- }
- }
- main()
- {
- int i = 0;
- initscr();
- cbreak();
- noecho();
- nodelay(stdscr, TRUE);
- scrollok(stdscr, TRUE);
- while (1) {
- if (kbhit()) {
- printw("Key pressed! It was: %d\n", getch());
- refresh();
- break;
- } else {
- printf("Numero: %d ",i);
- refresh();
- sleep(1);
- i++;
- }
- printf("%d ", i);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement