国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > Python > 正文

Python可跨平臺(tái)實(shí)現(xiàn)獲取按鍵的方法

2020-02-23 00:17:28
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

本文實(shí)例講述了Python可跨平臺(tái)實(shí)現(xiàn)獲取按鍵的方法。分享給大家供大家參考。具體如下:

代碼如下:class _Getch: 
    """Gets a single character from standard input.  Does not echo to the screen."""
    def __init__(self): 
        try: 
            self.impl = _GetchWindows() 
        except ImportError: 
            try: 
                self.impl = _GetchMacCarbon() 
            except AttributeError: 
                self.impl = _GetchUnix() 
    def __call__(self): return self.impl() 
class _GetchUnix: 
    def __init__(self): 
        import tty, sys, termios # import termios now or else you'll get the Unix version on the Mac 
    def __call__(self): 
        import sys, tty, termios 
        fd = sys.stdin.fileno() 
        old_settings = termios.tcgetattr(fd) 
        try: 
            tty.setraw(sys.stdin.fileno()) 
            ch = sys.stdin.read(1) 
        finally: 
            termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) 
        return ch 
class _GetchWindows: 
    def __init__(self): 
        import msvcrt 
    def __call__(self): 
        import msvcrt 
        return msvcrt.getch() 
class _GetchMacCarbon: 
    """ 
    A function which returns the current ASCII key that is down; 
    if no ASCII key is down, the null string is returned.  The 
    page http://www.mactech.com/macintosh-c/chap02-1.html was 
    very helpful in figuring out how to do this. 
    """
    def __init__(self): 
        import Carbon 

發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 长春市| 宁武县| 都安| 荔浦县| 连城县| 霸州市| 麻栗坡县| 阿拉善盟| 长汀县| 惠安县| 金溪县| 丹东市| 基隆市| 芒康县| 新建县| 阿坝县| 象山县| 合阳县| 奉化市| 乐安县| 湘潭市| 芦山县| 密云县| 昌邑市| 老河口市| 华宁县| 淮北市| 林州市| 册亨县| 吉隆县| 吉木萨尔县| 民县| 莲花县| 沙河市| 通化县| 高雄市| 武城县| 疏附县| 西和县| 通河县| 龙里县|