64 lines
1.2 KiB
C
64 lines
1.2 KiB
C
#include "substitutions.h"
|
|
#include <unistd.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <termios.h>
|
|
#include <time.h>
|
|
|
|
/* Use this variable to remember original terminal attributes. */
|
|
|
|
struct termios saved_attributes;
|
|
|
|
void reset_input_mode()
|
|
{
|
|
tcsetattr (STDIN_FILENO, TCSANOW, &saved_attributes);
|
|
}
|
|
|
|
void set_input_mode()
|
|
{
|
|
struct termios tattr;
|
|
char *name;
|
|
|
|
/* Make sure stdin is a terminal. */
|
|
if (!isatty (STDIN_FILENO))
|
|
{
|
|
fprintf (stderr, "Not a terminal.\n");
|
|
exit (EXIT_FAILURE);
|
|
}
|
|
|
|
/* Save the terminal attributes so we can restore them later. */
|
|
tcgetattr (STDIN_FILENO, &saved_attributes);
|
|
atexit (reset_input_mode);
|
|
|
|
/* Set the funny terminal modes. */
|
|
tcgetattr (STDIN_FILENO, &tattr);
|
|
tattr.c_lflag &= ~(ICANON|ECHO); /* Clear ICANON and ECHO. */
|
|
tattr.c_cc[VMIN] = 0;
|
|
tattr.c_cc[VTIME] = 0;
|
|
tcsetattr (STDIN_FILENO, TCSAFLUSH, &tattr);
|
|
}
|
|
|
|
void delay(unsigned int ms)
|
|
{
|
|
usleep(ms * 1000);
|
|
}
|
|
|
|
char isKeyPressed()
|
|
{
|
|
char key_handler = 0;
|
|
read(STDIN_FILENO, &key_handler, 1);
|
|
if (key_handler > 0)
|
|
{
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int main()
|
|
{
|
|
set_input_mode();
|
|
while (isKeyPressed() == 0) {printf("hell\n");}
|
|
printf("ok\n");
|
|
reset_input_mode();
|
|
}
|