September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -1 +1,5 @@
|
|||
K = PEEK(-16384) : IF K > 127 THEN POKE -16368,0 : K$ = CHR$(K)
|
||||
PRINT "Press <escape> to exit now..."
|
||||
key = GETKEY
|
||||
IF key = 27 THEN
|
||||
END
|
||||
END IF
|
||||
|
|
|
|||
|
|
@ -1,2 +1 @@
|
|||
10 REM k$ will be empty, if no key has been pressed
|
||||
20 LET k$ = INKEY$
|
||||
K = PEEK(-16384) : IF K > 127 THEN POKE -16368,0 : K$ = CHR$(K)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
10 REM k$ will be empty, if no key has been pressed
|
||||
20 LET k$ = INKEY$
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
#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);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
#include <stdio.h>
|
||||
|
||||
void main()
|
||||
{
|
||||
char chr = getchar();
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
Public Sub Form_KeyPress()
|
||||
|
||||
'Requires a TextBox or similar on the Form to work
|
||||
Print Key.Text;
|
||||
|
||||
End
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
// version 1.1
|
||||
|
||||
import java.awt.event.KeyAdapter
|
||||
import java.awt.event.KeyEvent
|
||||
import javax.swing.JFrame
|
||||
import javax.swing.SwingUtilities
|
||||
|
||||
class Test : JFrame() {
|
||||
init {
|
||||
println("Press any key to see its code or 'enter' to quit\n")
|
||||
addKeyListener(object : KeyAdapter() {
|
||||
override fun keyPressed(e: KeyEvent) {
|
||||
if (e.keyCode == KeyEvent.VK_ENTER) {
|
||||
isVisible = false
|
||||
dispose()
|
||||
System.exit(0)
|
||||
}
|
||||
else
|
||||
println(e.keyCode)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
SwingUtilities.invokeLater {
|
||||
val f = Test()
|
||||
f.isFocusable = true
|
||||
f.isVisible = true
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import, division, unicode_literals, print_function
|
||||
|
||||
import __future__
|
||||
import tty, termios
|
||||
import sys
|
||||
if sys.version_info.major < 3:
|
||||
import thread as _thread
|
||||
|
|
@ -13,7 +15,6 @@ try:
|
|||
from msvcrt import getch # try to import Windows version
|
||||
except ImportError:
|
||||
def getch(): # define non-Windows version
|
||||
import tty, termios
|
||||
fd = sys.stdin.fileno()
|
||||
old_settings = termios.tcgetattr(fd)
|
||||
try:
|
||||
|
|
@ -23,17 +24,28 @@ except ImportError:
|
|||
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
|
||||
return ch
|
||||
|
||||
char = None
|
||||
|
||||
def keypress():
|
||||
global char
|
||||
char = getch()
|
||||
|
||||
_thread.start_new_thread(keypress, ())
|
||||
def main():
|
||||
global char
|
||||
char = None
|
||||
_thread.start_new_thread(keypress, ())
|
||||
|
||||
while True:
|
||||
if char is not None:
|
||||
print("Key pressed is " + char.decode('utf-8'))
|
||||
break
|
||||
print("Program is running")
|
||||
time.sleep(5)
|
||||
while True:
|
||||
if char is not None:
|
||||
try:
|
||||
print("Key pressed is " + char.decode('utf-8'))
|
||||
except UnicodeDecodeError:
|
||||
print("character can not be decoded, sorry!")
|
||||
char = None
|
||||
_thread.start_new_thread(keypress, ())
|
||||
if char == 'q' or char == '\x1b': # x1b is ESC
|
||||
exit()
|
||||
char = None
|
||||
print("Program is running")
|
||||
time.sleep(1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue