Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -1,2 +1,3 @@
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.
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| ]]

View file

@ -0,0 +1,41 @@
package main
import (
"log"
"time"
gc "code.google.com/p/goncurses"
)
func main() {
s, err := gc.Init()
if err != nil {
log.Fatal("init:", err)
}
defer gc.End()
gc.Cursor(0)
s.Move(20, 0)
s.Print("Key check in ")
for i := 3; i >= 1; i-- {
s.MovePrint(20, 13, i)
s.Refresh()
time.Sleep(500 * time.Millisecond)
}
s.Println()
gc.Echo(false)
// task requirement next two lines
s.Timeout(0)
k := s.GetChar()
if k == 0 {
s.Println("No key pressed")
} else {
s.Println("You pressed", gc.KeyString(k))
}
s.Refresh()
s.Timeout(-1)
gc.FlushInput()
gc.Cursor(1)
s.GetChar()
}

View file

@ -5,9 +5,9 @@ import time
try:
from msvcrt import getch
from msvcrt import getch # try to import Windows version
except ImportError:
def getch():
def getch(): # define non-Windows version
import sys, tty, termios
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)