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


Python msvcrt.getch方法代码示例

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


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

示例1: interpret_keypress

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getch [as 别名]
def interpret_keypress(other_allowable=""):
    """
    See whether a number was pressed (give terminal bell if so) and return
    value.  Otherwise returns none.  Tries to handle arrows as a single
    press.
    """
    press = getch()
    if press == '\x1b':
        getch()
        getch()
        press = "direction"

    if press.upper() in other_allowable:
        return press.upper()

    if press != "direction" and press != " ":
        try:
            press = int(press)
        except ValueError:
            press = None
    return press 
开发者ID:Pinafore,项目名称:qb,代码行数:23,代码来源:buzzer.py

示例2: _WaitForFinish

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getch [as 别名]
def _WaitForFinish(ob, timeout):
    end = time.time() + timeout
    while 1:
        if msvcrt.kbhit():
            msvcrt.getch()
            break
        pythoncom.PumpWaitingMessages()
        stopEvent.wait(.2)
        if stopEvent.isSet():
            stopEvent.clear()
            break
        try:
            if not ob.Visible:
                # Gone invisible - we need to pretend we timed
                # out, so the app is quit.
                return 0
        except pythoncom.com_error:
            # Excel is busy (eg, editing the cell) - ignore
            pass
        if time.time() > end:
            return 0
    return 1 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:24,代码来源:testMSOfficeEvents.py

示例3: main

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getch [as 别名]
def main():
	while (1==1):
		try:
			take_order()
		except SystemExit:
			import msvcrt
			while msvcrt.kbhit():
				msvcrt.getch()
			print "* Bye..."
			sys.exit(1)
		except KeyboardInterrupt:
			import msvcrt
			while msvcrt.kbhit():
				msvcrt.getch()
			print "* Bye..."
			sys.exit(1)
		except:
			if console:
				print "---\nError, sleeping mode!(", str(sys.exc_info()), ")"
		time.sleep(300)
		main() 
开发者ID:mertsarica,项目名称:hack4career,代码行数:23,代码来源:apt_simulator.py

示例4: win_getpass

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getch [as 别名]
def win_getpass(prompt='Password: ', stream=None):
    """Prompt for password with echo off, using Windows getch()."""
    if sys.stdin is not sys.__stdin__:
        return fallback_getpass(prompt, stream)
    import msvcrt
    for c in prompt:
        msvcrt.putch(c)
    pw = ""
    while 1:
        c = msvcrt.getch()
        if c == '\r' or c == '\n':
            break
        if c == '\003':
            raise KeyboardInterrupt
        if c == '\b':
            pw = pw[:-1]
        else:
            pw = pw + c
    msvcrt.putch('\r')
    msvcrt.putch('\n')
    return pw 
开发者ID:glmcdona,项目名称:meddle,代码行数:23,代码来源:getpass.py

示例5: get_pager_start

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getch [as 别名]
def get_pager_start(pager, start):
    """Return the string for paging files with an offset.

    This is the '+N' argument which less and more (under Unix) accept.
    """

    if pager in ['less','more']:
        if start:
            start_string = '+' + str(start)
        else:
            start_string = ''
    else:
        start_string = ''
    return start_string


# (X)emacs on win32 doesn't like to be bypassed with msvcrt.getch() 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:19,代码来源:page.py

示例6: getarrow

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getch [as 别名]
def getarrow(self):
        ''' 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().
        '''
        
        if os.name == 'nt':
            msvcrt.getch() # skip 0xE0
            c = msvcrt.getch()
            vals = [72, 77, 80, 75]
            
        else:
            c = sys.stdin.read(3)[2]
            vals = [65, 67, 66, 68]
        
        return vals.index(ord(c.decode('utf-8'))) 
开发者ID:sonofeft,项目名称:RocketCEA,代码行数:21,代码来源:keyboard_hit.py

示例7: get_input_interrupted

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getch [as 别名]
def get_input_interrupted(prompt):
    # TODO: refactor to use interruptable prompt from prompt_toolkit in api.py:193 (login: process 2fa error codes).
    #  This method to be removed.
    if os.name == 'nt':
        global win_cancel_getch

        print(prompt)
        win_cancel_getch = False
        result = b''
        while not win_cancel_getch:
            if msvcrt.kbhit():
                ch = msvcrt.getch()
                if ch in [b'\r', b'\n']:
                    break
                result += ch
            else:
                time.sleep(0.1)
        if win_cancel_getch:
            raise KeyboardInterrupt()
        return result.decode()
    else:
        return input(prompt) 
开发者ID:Keeper-Security,项目名称:Commander,代码行数:24,代码来源:yubikey.py

示例8: getarrow

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getch [as 别名]
def getarrow(self):
        ''' 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().
        '''

        if os.name == 'nt':
            msvcrt.getch()  # skip 0xE0
            c = msvcrt.getch()
            vals = [72, 77, 80, 75]

        else:
            c = sys.stdin.read(3)[2]
            vals = [65, 67, 66, 68]

        return vals.index(ord(c.decode('utf-8'))) 
开发者ID:fandoghpaas,项目名称:fandogh-cli,代码行数:21,代码来源:utils.py

示例9: wait_key

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getch [as 别名]
def wait_key():
    ''' Wait for a key press on the console and return it. '''
    result = None
    if os.name == 'nt':
        import msvcrt
        result = msvcrt.getch()
    else:
        import termios
        fd = sys.stdin.fileno()

        oldterm = termios.tcgetattr(fd)
        newattr = termios.tcgetattr(fd)
        newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO
        termios.tcsetattr(fd, termios.TCSANOW, newattr)

        try:
            result = sys.stdin.read(1)
        except IOError:
            pass
        finally:
            termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)

    return result 
开发者ID:bensauer,项目名称:saywizard,代码行数:25,代码来源:wizardofoz.py

示例10: _find_getch

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getch [as 别名]
def _find_getch():
    try:
        import termios
    except ImportError:
        # Non-POSIX. Return msvcrt's (Windows') getch.
        import msvcrt
        return msvcrt.getch

    # POSIX system. Create and return a getch that manipulates the tty.
    import sys, tty
    def _getch():
        fd = sys.stdin.fileno()
        old_settings = termios.tcgetattr(fd)
        try:
            tty.setraw(fd)
            ch = sys.stdin.read(1)
        finally:
            termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
        return ch

    return _getch 
开发者ID:tobykurien,项目名称:pi-tracking-telescope,代码行数:23,代码来源:control.py

示例11: __call__

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getch [as 别名]
def __call__(self):
        import msvcrt
        return msvcrt.getch() 
开发者ID:EarToEarOak,项目名称:RF-Monitor,代码行数:5,代码来源:utils_cli.py

示例12: getchar

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getch [as 别名]
def getchar():
        return msvcrt.getch() 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:4,代码来源:logtest.py

示例13: _find_getch

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getch [as 别名]
def _find_getch():
    try:
        import termios
    except ImportError:
        # Non-POSIX. Return msvcrt's (Windows') getch.
        import msvcrt
        return msvcrt.getch

    # POSIX system. Create and return a getch that manipulates the tty.
    import sys, tty
    def _getch():
        fd = sys.stdin.fileno()
        old_settings = None
        try:
            old_settings = termios.tcgetattr(fd)
            tty.setraw(fd)
        except termios.error:
            pass
        try:
            ch = sys.stdin.read(1)
        finally:
            if old_settings is not None:
                termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
        return ch

    return _getch 
开发者ID:aaronjanse,项目名称:asciidots,代码行数:28,代码来源:getchar.py

示例14: test_main

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getch [as 别名]
def test_main(external_interpreters):
    print('Default JSEngine is %r' % jsengine.JSEngine)
    print('Default external_interpreter is %r' % jsengine.external_interpreter)

    for JSEngine in (ChakraJSEngine, QuickJSEngine):
        test_engine(JSEngine)

    for external_interpreter in external_interpreters:
        if set_external_interpreter(external_interpreter):
            test_engine(ExternalJSEngine)

    if platform.system() == 'Windows':
        import msvcrt
        print('Press any key to continue ...')
        msvcrt.getch() 
开发者ID:ForgQi,项目名称:bilibiliupload,代码行数:17,代码来源:jsengine_test.py

示例15: getch

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getch [as 别名]
def getch():
        """
        Gets a single character from STDIO.
        """
        import sys
        import tty
        import termios
        fd = sys.stdin.fileno()
        old = termios.tcgetattr(fd)
        try:
            tty.setraw(fd)
            return sys.stdin.read(1)
        finally:
            termios.tcsetattr(fd, termios.TCSADRAIN, old) 
开发者ID:alessandrodd,项目名称:apk_api_key_extractor,代码行数:16,代码来源:getch.py


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