treesummaryrefslogcommitdiff
diff options
context:
space:
mode:
-rw-r--r--main2.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/main2.c b/main2.c
index e462674..d58a5bc 100644
--- a/main2.c
+++ b/main2.c
@@ -1,5 +1,40 @@
#include <stdio.h>
+
+#ifdef _WIN32
#include <conio.h>
+#else
+#include <termios.h>
+#include <unistd.h>
+#include <stdio.h>
+
+/* reads from keypress, doesn't echo */
+int getch(void)
+{
+ struct termios oldattr, newattr;
+ int ch;
+ tcgetattr( STDIN_FILENO, &oldattr );
+ newattr = oldattr;
+ newattr.c_lflag &= ~( ICANON | ECHO );
+ tcsetattr( STDIN_FILENO, TCSANOW, &newattr );
+ ch = getchar();
+ tcsetattr( STDIN_FILENO, TCSANOW, &oldattr );
+ return ch;
+}
+
+/* reads from keypress, echoes */
+int getche(void)
+{
+ struct termios oldattr, newattr;
+ int ch;
+ tcgetattr( STDIN_FILENO, &oldattr );
+ newattr = oldattr;
+ newattr.c_lflag &= ~( ICANON );
+ tcsetattr( STDIN_FILENO, TCSANOW, &newattr );
+ ch = getchar();
+ tcsetattr( STDIN_FILENO, TCSANOW, &oldattr );
+ return ch;
+}
+#endif
#define ASCII_ESC 27