aboutsummaryrefslogtreecommitdiffhomepage
path: root/libslang/demo/keypad.c
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2011-10-14 04:55:05 +0200
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2011-10-14 04:55:05 +0200
commit6aa0e0017d7d0cddc006da885946934b06949a91 (patch)
tree66b688ec32e2f91266db760b1762f2a50cc52036 /libslang/demo/keypad.c
parenta966db5b71328f6adf9dd767e64b322a3bd7ed9c (diff)
downloaderlang-slang-fork-6aa0e0017d7d0cddc006da885946934b06949a91.tar.gz
include libslang-1.4.9 and automatically build it and link erlang-slang against it
few (erlang) people will still have libslang-1.4.9 installed or spend time to get it to link against the driver
Diffstat (limited to 'libslang/demo/keypad.c')
-rw-r--r--libslang/demo/keypad.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/libslang/demo/keypad.c b/libslang/demo/keypad.c
new file mode 100644
index 0000000..ac2a736
--- /dev/null
+++ b/libslang/demo/keypad.c
@@ -0,0 +1,52 @@
+/* This routine illustrates the keypad interface. To implement
+ * detection of a single escape character, allow for timeout.
+ */
+
+#include <stdio.h>
+#include <slang.h>
+
+#include "demolib.c"
+
+#define TIMEOUT 2 /* 2/10 of a second */
+
+static int getch (void)
+{
+ int ch;
+
+ while (0 == SLang_input_pending (1000))
+ continue;
+
+ ch = SLang_getkey ();
+
+ if (ch == 033) /* escape */
+ {
+ if (0 == SLang_input_pending (TIMEOUT))
+ return 033;
+ }
+
+ SLang_ungetkey (ch);
+
+ return SLkp_getkey ();
+}
+
+
+int main (int argc, char **argv)
+{
+ int ch;
+
+ (void) argc; (void) argv;
+
+ if (-1 == demolib_init_terminal (1, 0))
+ return 1;
+
+ fprintf (stderr, "This program illustrates the slkeypad facility.\n");
+ fprintf (stderr, "Press any key ('q' quits).\n");
+ while ('q' != (ch = getch ()))
+ {
+ fprintf (stderr, "Keysym: %d\r\n", ch);
+ }
+
+ demolib_exit (0);
+
+ return 0;
+}