ó
x½Ì\c           @   så   d  Z  d d l Z e j d k r0 d d l Z n4 d d l Z d d l Z d d l Z d d l m Z d d
 d „  ƒ  YZ e	 d k rá e ƒ  Z
 d GHx@ e rÓ e
 j ƒ  r” e
 j ƒ  Z e e ƒ d	 k rÈ Pn  e GHq” q” We
 j ƒ  n  d S(   s‡  
A Python class implementing KBHIT, the standard keyboard-interrupt poller.
Works transparently on Windows and Posix (Linux, Mac OS X).  Doesn't work
with IDLE.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as 
published by the Free Software Foundation, either version 3 of the 
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

iÿÿÿÿNt   nt(   t   selectt   KBHitc           B   s5   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   s¢   t  j d k r nŒ t j j ƒ  |  _ t j |  j ƒ |  _ t j |  j ƒ |  _	 |  j d t j
 @t j @|  j d <t j |  j t j |  j ƒ t j |  j ƒ d S(   sP   Creates a KBHit object that you can call to do various keyboard things.
        R    i   N(   t   ost   namet   syst   stdint   filenot   fdt   termiost	   tcgetattrt   new_termt   old_termt   ICANONt   ECHOt	   tcsetattrt	   TCSAFLUSHt   atexitt   registert   set_normal_term(   t   self(    (    s-   /cygdrive/t/henthorn/EyeRISUDPServer/kbhit.pyt   __init__#   s    $c         C   s2   t  j d k r n t j |  j t j |  j ƒ d S(   sA    Resets to normal terminal.  On Windows this is a no-op.
        R    N(   R   R   R	   R   R   R   R   (   R   (    (    s-   /cygdrive/t/henthorn/EyeRISUDPServer/kbhit.pyR   9   s    c         C   s<   d } t  j d k r( t j ƒ  j d ƒ St j j d ƒ Sd S(   s‰    Returns a keyboard character after kbhit() has been called.
            Should not be called in the same program as getarrow().
        t    R    s   utf-8i   N(   R   R   t   msvcrtt   getcht   decodeR   R   t   read(   R   t   s(    (    s-   /cygdrive/t/henthorn/EyeRISUDPServer/kbhit.pyR   D   s    c         C   s~   t  j d k r: t j ƒ  t j ƒ  } d d d d g } n( t j j d ƒ d } d d	 d
 d g } | j t | j	 d ƒ ƒ ƒ S(   sÌ    Returns an arrow-key code after kbhit() has been called. Codes are
        0 : up
        1 : right
        2 : down
        3 : left
        Should not be called in the same program as getch().
        R    iH   iM   iP   iK   i   i   iA   iC   iB   iD   s   utf-8(
   R   R   R   R   R   R   R   t   indext   ordR   (   R   t   ct   vals(    (    s-   /cygdrive/t/henthorn/EyeRISUDPServer/kbhit.pyt   getarrowR   s    	
c         C   sK   t  j d k r t j ƒ  St t j g g  g  d ƒ \ } } } | g  k Sd S(   sF    Returns True if keyboard character was hit, False otherwise.
        R    i    N(   R   R   R   t   kbhitR   R   R   (   R   t   drt   dwt   de(    (    s-   /cygdrive/t/henthorn/EyeRISUDPServer/kbhit.pyR!   g   s    
$(   t   __name__t
   __module__R   R   R   R    R!   (    (    (    s-   /cygdrive/t/henthorn/EyeRISUDPServer/kbhit.pyR   !   s
   				t   __main__s   Hit any key, or ESC to exiti   (    (   t   __doc__R   R   R   R   R	   R   R   R   R%   t   kbt   TrueR!   R   R   R   R   (    (    (    s-   /cygdrive/t/henthorn/EyeRISUDPServer/kbhit.pyt   <module>   s$   R		