''' Simple example of a Windows program,
with animation responding to keypresses.
It does *NOT* work inside of Idle, but does work from the command line,
or double-clicked in a folder window.
For a more elaborate approach see:  kbMouseInput.py
'''

import msvcrt, time
from graphics import *

def kdel():
   win = GraphWin("kbtest", 500, 500)
   win.yUp()
   c = Circle(Point(20, 20), 10)
   c .draw(win)

   ok = True
   print("\nPress keys - '/' to quit.")
   while (ok):
       
       if msvcrt.kbhit(): # true if a key was pressed
           ch = msvcrt.getwch() # read first char in keyboard buffer
           if ch in 'à\x00': # two character key sequence starts
               ch += msvcrt.getwch()
           print(repr('|' + ch + '|')) # show sequence bounded by vertical bars
           ok = ch != '/'
           c.move(0, 10)
       c.move(2, 0)
       time.sleep(.2)
           
kdel()
