Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
|
|
@ -0,0 +1,46 @@
|
|||
#include <stdio.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
void set_mode(int want_key)
|
||||
{
|
||||
static struct termios old, new;
|
||||
if (!want_key) {
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &old);
|
||||
return;
|
||||
}
|
||||
|
||||
tcgetattr(STDIN_FILENO, &old);
|
||||
new = old;
|
||||
new.c_lflag &= ~(ICANON | ECHO);
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &new);
|
||||
}
|
||||
|
||||
int get_key()
|
||||
{
|
||||
int c = 0;
|
||||
struct timeval tv;
|
||||
fd_set fs;
|
||||
tv.tv_usec = tv.tv_sec = 0;
|
||||
|
||||
FD_ZERO(&fs);
|
||||
FD_SET(STDIN_FILENO, &fs);
|
||||
select(STDIN_FILENO + 1, &fs, 0, 0, &tv);
|
||||
|
||||
if (FD_ISSET(STDIN_FILENO, &fs)) {
|
||||
c = getchar();
|
||||
set_mode(0);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int c;
|
||||
while(1) {
|
||||
set_mode(1);
|
||||
while (!(c = get_key())) usleep(10000);
|
||||
printf("key %d\n", c);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
(ns keypress.core
|
||||
(:import jline.Terminal)
|
||||
(:gen-class))
|
||||
|
||||
(def keypress (future (.readCharacter (Terminal/getTerminal) System/in)))
|
||||
|
||||
(defn prompt []
|
||||
(println "Awaiting char...\n")
|
||||
(Thread/sleep 2000)
|
||||
(if-not (realized? keypress)
|
||||
(recur)
|
||||
(println "key: " (char @keypress))))
|
||||
|
||||
(defn -main [& args]
|
||||
(prompt)
|
||||
(shutdown-agents))
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
# this solution will work only in Windows, as msvcrt is a Windows only package
|
||||
|
||||
import thread
|
||||
import time
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
:getkey→G
|
||||
:getKey→G
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue