当前位置: 首页>>代码示例>>Python>>正文


Python msvcrt.getche方法代码示例

本文整理汇总了Python中msvcrt.getche方法的典型用法代码示例。如果您正苦于以下问题:Python msvcrt.getche方法的具体用法?Python msvcrt.getche怎么用?Python msvcrt.getche使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在msvcrt的用法示例。


在下文中一共展示了msvcrt.getche方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: grab

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getche [as 别名]
def grab(self, prompt, **kwargs):
        # Takes a prompt, a default, and a timeout and shows it with that timeout
        # returning the result
        timeout = kwargs.get("timeout", 0)
        default = kwargs.get("default", None)
        # If we don't have a timeout - then skip the timed sections
        if timeout <= 0:
            if sys.version_info >= (3, 0):
                return input(prompt)
            else:
                return str(raw_input(prompt))
        # Write our prompt
        sys.stdout.write(prompt)
        sys.stdout.flush()
        if os.name == "nt":
            start_time = time.time()
            i = ''
            while True:
                if msvcrt.kbhit():
                    c = msvcrt.getche()
                    if ord(c) == 13: # enter_key
                        break
                    elif ord(c) >= 32: #space_char
                        i += c
                if len(i) == 0 and (time.time() - start_time) > timeout:
                    break
        else:
            i, o, e = select.select( [sys.stdin], [], [], timeout )
            if i:
                i = sys.stdin.readline().strip()
        print('')  # needed to move to next line
        if len(i) > 0:
            return i
        else:
            return default 
开发者ID:corpnewt,项目名称:USBMap,代码行数:37,代码来源:utils.py

示例2: _wait_for_exit_on_windows

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getche [as 别名]
def _wait_for_exit_on_windows(please_stop):
    import msvcrt

    line = ""
    while not please_stop:
        if msvcrt.kbhit():
            chr = msvcrt.getche()
            if ord(chr) == 13:
                if line == "exit":
                    Log.alert("'exit' Detected!  Stopping...")
                    return
            elif ord(chr) > 32:
                line += chr
        else:
            sleep(1) 
开发者ID:mozilla,项目名称:jx-sqlite,代码行数:17,代码来源:threads.py

示例3: input_with_timeout

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getche [as 别名]
def input_with_timeout(timeout):
    if platform.system() == 'Windows':
        start_time = time()
        s = ''
        while True:
            while msvcrt.kbhit():
                c = msvcrt.getche()
                if ord(c) == 13: # enter_key
                    break
                elif ord(c) >= 32: #space_char
                    s += c.decode('utf-8')
            if time() - start_time > timeout:
                return None

        return s
    else:
        while True:
            try:
                rlist, _, _ = select.select([sys.stdin], [], [], timeout)
                break
            except (OSError, select.error) as e:
                if e.args[0] != errno.EINTR:
                    raise e
        if rlist:
            return sys.stdin.readline()
        else:
            return None 
开发者ID:bkerler,项目名称:android_universal,代码行数:29,代码来源:application.py


注:本文中的msvcrt.getche方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。