2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -1,3 +1,6 @@
Determine if a key has been pressed and store this in a variable.
If no key has been pressed, the program should continue without waiting.
[[user input::task| ]]
Determine if a key has been pressed and store this in a variable.
If no key has been pressed, the program should continue without waiting.
<br><br>

View file

@ -0,0 +1,23 @@
import java.awt.event.*;
import javax.swing.*;
public class Test extends JFrame {
Test() {
addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
int keyCode = e.getKeyCode();
System.out.println(keyCode);
}
});
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
Test f = new Test();
f.setFocusable(true);
f.setVisible(true);
});
}
}

View file

@ -1,8 +1,11 @@
#!/usr/bin/env python
# this solution will work only in Windows, as msvcrt is a Windows only package
import thread
import __future__
import sys
if sys.version_info.major < 3:
import thread as _thread
else:
import _thread
import time
@ -10,7 +13,7 @@ try:
from msvcrt import getch # try to import Windows version
except ImportError:
def getch(): # define non-Windows version
import sys, tty, termios
import tty, termios
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
@ -26,11 +29,11 @@ def keypress():
global char
char = getch()
thread.start_new_thread(keypress, ())
_thread.start_new_thread(keypress, ())
while True:
if char is not None:
print "Key pressed is " + char
print("Key pressed is " + char.decode('utf-8'))
break
print "Program is running"
print("Program is running")
time.sleep(5)

View file

@ -0,0 +1,7 @@
begin
check = STDIN.read_nonblock(1)
rescue IO::WaitReadable
check = false
end
puts check if check

View file

@ -0,0 +1,3 @@
% ruby keypress_check.rb
% echo -n y | ruby keypress_check.rb
y