當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。