3
ý¾ka«  ã               @   s    d Z ddlZejdkr ddlZn$ddlZddlZddlZddlmZ G dd„ dƒZe	dkrœeƒ Z
edƒ x*e
jƒ rje
jƒ Zeeƒd	krˆP eeƒ qjW e
jƒ  dS )
aÑ  
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.

Copied from: https://simondlevy.academic.wlu.edu/files/software/kbhit.py

é    NÚnt)Úselectc               @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )ÚKBHitc             C   sx   t jdkrnht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 )zPCreates a KBHit object that you can call to do various keyboard things.
        r   é   N)ÚosÚnameÚsysÚstdinÚfilenoÚfdÚtermiosÚ	tcgetattrZnew_termÚold_termÚICANONÚECHOÚ	tcsetattrÚ	TCSAFLUSHÚatexitÚregisterÚset_normal_term)Úself© r   ú5/home/eyeris-user/software/control-interface/kbhit.pyÚ__init__%   s    
 zKBHit.__init__c             C   s$   t jdkrntj| jtj| jƒ dS )zA Resets to normal terminal.  On Windows this is a no-op.
        r   N)r   r   r   r   r   r   r   )r   r   r   r   r   ;   s    
zKBHit.set_normal_termc             C   s,   d}t jdkrtjƒ jdƒS tjjdƒS dS )z‰ Returns a keyboard character after kbhit() has been called.
            Should not be called in the same program as getarrow().
        Ú r   zutf-8é   N)r   r   ÚmsvcrtÚgetchÚdecoder   r	   Úread)r   Úsr   r   r   r   F   s    
zKBHit.getchc             C   sX   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 )zÌ 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   éH   éM   éP   éK   r   é   éA   éC   éB   éD   zutf-8)
r   r   r   r   r   r	   r   ÚindexÚordr   )r   ÚcÚvalsr   r   r   ÚgetarrowT   s    	
zKBHit.getarrowc             C   s6   t jdkrtjƒ S ttjgg g dƒ\}}}|g kS dS )zF Returns True if keyboard character was hit, False otherwise.
        r   r   N)r   r   r   Úkbhitr   r   r	   )r   ZdrZdwZder   r   r   r/   i   s    
zKBHit.kbhitN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r.   r/   r   r   r   r   r   #   s
   r   Ú__main__zHit any key, or ESC to exité   )Ú__doc__r   r   r   r   r   r   r   r   r0   ÚkbÚprintr/   r   r,   r+   r   r   r   r   r   Ú<module>   s$   

R