国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 山东| 陆良县| 商都县| 尼玛县| 平江县| 图木舒克市| 惠安县| 多伦县| 宁陕县| 额敏县| 同仁县| 禹城市| 河北省| 丹江口市| 泊头市| 彭阳县| 珠海市| 千阳县| 景东| 内丘县| 赞皇县| 大化| 富蕴县| 平果县| 东莞市| 金川县| 仙桃市| 南昌市| 馆陶县| 沂水县| 嘉义市| 金寨县| 辉南县| 个旧市| 阿拉善左旗| 泸水县| 信丰县| 中西区| 左权县| 高青县| 徐汇区|