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


Python msvcrt.getwch方法代码示例

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


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

示例1: getkey

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getwch [as 别名]
def getkey(self):
                while True:
                    z = msvcrt.getwch()
                    if z == unichr(13):
                        return unichr(10)
                    elif z is unichr(0) or z is unichr(0xE0):
                        try:
                            code = msvcrt.getwch()
                            if z is unichr(0):
                                return self.fncodes[code]
                            else:
                                return self.navcodes[code]
                        except KeyError:
                            pass
                    else:
                        return z 
开发者ID:wendlers,项目名称:mpfshell,代码行数:18,代码来源:term.py

示例2: getkey

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getwch [as 别名]
def getkey(self) -> str:
        while True:
            z = msvcrt.getwch()
            if z == chr(13):
                return chr(10)
            elif z is chr(0) or z is chr(0xe0):
                try:
                    code = msvcrt.getwch()
                    if z is chr(0):
                        return self.fncodes[code]
                    else:
                        return self.navcodes[code]
                except KeyError:
                    pass
            else:
                return z 
开发者ID:vlasovskikh,项目名称:intellij-micropython,代码行数:18,代码来源:microrepl.py

示例3: win_getpass

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getwch [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)

    for c in prompt:
        msvcrt.putwch(c)
    pw = ""
    while 1:
        c = msvcrt.getwch()
        if c == '\r' or c == '\n':
            break
        if c == '\003':
            raise KeyboardInterrupt
        if c == '\b':
            pw = pw[:-1]
        else:
            pw = pw + c
    msvcrt.putwch('\r')
    msvcrt.putwch('\n')
    return pw 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:23,代码来源:getpass.py

示例4: win_getpass

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getwch [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.putwch(c)
    pw = ""
    while 1:
        c = msvcrt.getwch()
        if c == '\r' or c == '\n':
            break
        if c == '\003':
            raise KeyboardInterrupt
        if c == '\b':
            pw = pw[:-1]
        else:
            pw = pw + c
    msvcrt.putwch('\r')
    msvcrt.putwch('\n')
    return pw 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:23,代码来源:getpass.py

示例5: __ichr

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getwch [as 别名]
def __ichr(self):
        addr = self.__stck.pop()
        # Input Routine
        while msvcrt.kbhit():
            msvcrt.getwch()
        while True:
            char = msvcrt.getwch()
            if char in '\x00\xE0':
                msvcrt.getwch()
            elif char in string.printable:
                char = char.replace('\r', '\n')
                msvcrt.putwch(char)
                break
        item = ord(char)
        # Storing Number
        self.__heap.set_(addr, item) 
开发者ID:ActiveState,项目名称:code,代码行数:18,代码来源:recipe-577110.py

示例6: cancel

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getwch [as 别名]
def cancel(self):
                # CancelIo, CancelSynchronousIo do not seem to work when using
                # getwch, so instead, send a key to the window with the console
                hwnd = ctypes.windll.kernel32.GetConsoleWindow()
                ctypes.windll.user32.PostMessageA(hwnd, 0x100, 0x0D, 0) 
开发者ID:wendlers,项目名称:mpfshell,代码行数:7,代码来源:term.py

示例7: getkey

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getwch [as 别名]
def getkey(self):
            while True:
                z = msvcrt.getwch()
                if z == unichr(13):
                    return unichr(10)
                elif z in (unichr(0), unichr(0x0e)):    # functions keys, ignore
                    msvcrt.getwch()
                else:
                    return z 
开发者ID:cedricp,项目名称:ddt4all,代码行数:11,代码来源:miniterm.py

示例8: cancel

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getwch [as 别名]
def cancel(self):
            # CancelIo, CancelSynchronousIo do not seem to work when using
            # getwch, so instead, send a key to the window with the console
            hwnd = ctypes.windll.kernel32.GetConsoleWindow()
            ctypes.windll.user32.PostMessageA(hwnd, 0x100, 0x0d, 0) 
开发者ID:cedricp,项目名称:ddt4all,代码行数:7,代码来源:miniterm.py

示例9: getkey

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getwch [as 别名]
def getkey(self):
            while True:
                z = msvcrt.getwch()
                if z == chr(13):
                    return chr(10)
                elif z in (chr(0), chr(0x0e)):    # functions keys, ignore
                    msvcrt.getwch()
                else:
                    return z 
开发者ID:purduesigbots,项目名称:pros-cli2,代码行数:11,代码来源:serial_terminal.py

示例10: get_key

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getwch [as 别名]
def get_key():
    ch = msvcrt.getwch()
    if ch in ('\x00', '\xe0'):  # arrow or function key prefix?
        ch = msvcrt.getwch()  # second call returns the actual key code

    if ch in const.KEY_MAPPING:
        return const.KEY_MAPPING[ch]
    if ch == 'H':
        return const.KEY_UP
    if ch == 'P':
        return const.KEY_DOWN

    return ch 
开发者ID:nvbn,项目名称:thefuck,代码行数:15,代码来源:win32.py

示例11: __iint

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getwch [as 别名]
def __iint(self):
        addr = self.__stck.pop()
        # Input Routine
        while msvcrt.kbhit():
            msvcrt.getwch()
        buff = ''
        char = msvcrt.getwch()
        while char != '\r' or not buff or len(buff) == 1 and buff in '+-':
            if char in '\x00\xE0':
                msvcrt.getwch()
            elif char in '+-' and not buff:
                msvcrt.putwch(char)
                buff += char
            elif '0' <= char <= '9':
                msvcrt.putwch(char)
                buff += char
            elif char == '\b':
                if buff:
                    buff = buff[:-1]
                    msvcrt.putwch(char)
                    msvcrt.putwch(' ')
                    msvcrt.putwch(char)
            char = msvcrt.getwch()
        msvcrt.putwch(char)
        msvcrt.putwch('\n')
        item = int(buff)
        # Storing Number
        self.__heap.set_(addr, item) 
开发者ID:ActiveState,项目名称:code,代码行数:30,代码来源:recipe-577110.py

示例12: getchar

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getwch [as 别名]
def getchar(echo):
        # The function `getch` will return a bytes object corresponding to
        # the pressed character. Since Windows 10 build 1803, it will also
        # return \x00 when called a second time after pressing a regular key.
        #
        # `getwch` does not share this probably-bugged behavior. Moreover, it
        # returns a Unicode object by default, which is what we want.
        #
        # Either of these functions will return \x00 or \xe0 to indicate
        # a special key, and you need to call the same function again to get
        # the "rest" of the code. The fun part is that \u00e0 is
        # "latin small letter a with grave", so if you type that on a French
        # keyboard, you _also_ get a \xe0.
        # E.g., consider the Up arrow. This returns \xe0 and then \x48. The
        # resulting Unicode string reads as "a with grave" + "capital H".
        # This is indistinguishable from when the user actually types
        # "a with grave" and then "capital H".
        #
        # When \xe0 is returned, we assume it's part of a special-key sequence
        # and call `getwch` again, but that means that when the user types
        # the \u00e0 character, `getchar` doesn't return until a second
        # character is typed.
        # The alternative is returning immediately, but that would mess up
        # cross-platform handling of arrow keys and others that start with
        # \xe0. Another option is using `getch`, but then we can't reliably
        # read non-ASCII characters, because return values of `getch` are
        # limited to the current 8-bit codepage.
        #
        # Anyway, Click doesn't claim to do this Right(tm), and using `getwch`
        # is doing the right thing in more situations than with `getch`.
        if echo:
            func = msvcrt.getwche
        else:
            func = msvcrt.getwch

        rv = func()
        if rv in (u'\x00', u'\xe0'):
            # \x00 and \xe0 are control characters that indicate special key,
            # see above.
            rv += func()
        _translate_ch_to_exc(rv)
        return rv 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:44,代码来源:_termui_impl.py

示例13: inkey

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getwch [as 别名]
def inkey(self, timeout=None):
        # Since get_key is a single method, we will just do the cbreak
        # and input stuff in a single method.
        # We should ever need inkey without cbreak

        if sys.version_info[0] >= 3:
            from msvcrt import kbhit, getwch as _getch
        else:
            from msvcrt import kbhit, getch as _getch

        def readInput():
            start_time = time.time()
            while True:
                if kbhit():
                    return _getch()
                if (time.time() - start_time) > timeout:
                    return None

        key = readInput()
        if not key:
            return None

        if key == '\x03':
            # Ctrl C
            raise CaughtSignal(2, None)

        elif key == '\x1c':
            # Ctrl \
            sys.exit(1)

        elif key == '\xe0':
            # Its an arrow key, get next symbol
            next_key = _getch()
            if next_key == 'H':
                return Val(name='KEY_UP', code=259)
            elif next_key == 'K':
                return Val(name='KEY_LEFT', code=260)
            elif next_key == 'P':
                return Val(name='KEY_DOWN', code=258)
            elif next_key == 'M':
                return Val(name='KEY_RIGHT', code=261)

        elif key == '\x1b':
            return Val(name='KEY_ESCAPE', code=361)
        elif key == '\x0d':
            return Val(name='KEY_ENTER', code=362)

        else:
            return Val(key=key) 
开发者ID:QData,项目名称:deepWordBug,代码行数:51,代码来源:term.py

示例14: getchar

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getwch [as 别名]
def getchar(echo):
        # The function `getch` will return a bytes object corresponding to
        # the pressed character. Since Windows 10 build 1803, it will also
        # return \x00 when called a second time after pressing a regular key.
        #
        # `getwch` does not share this probably-bugged behavior. Moreover, it
        # returns a Unicode object by default, which is what we want.
        #
        # Either of these functions will return \x00 or \xe0 to indicate
        # a special key, and you need to call the same function again to get
        # the "rest" of the code. The fun part is that \u00e0 is
        # "latin small letter a with grave", so if you type that on a French
        # keyboard, you _also_ get a \xe0.
        # E.g., consider the Up arrow. This returns \xe0 and then \x48. The
        # resulting Unicode string reads as "a with grave" + "capital H".
        # This is indistinguishable from when the user actually types
        # "a with grave" and then "capital H".
        #
        # When \xe0 is returned, we assume it's part of a special-key sequence
        # and call `getwch` again, but that means that when the user types
        # the \u00e0 character, `getchar` doesn't return until a second
        # character is typed.
        # The alternative is returning immediately, but that would mess up
        # cross-platform handling of arrow keys and others that start with
        # \xe0. Another option is using `getch`, but then we can't reliably
        # read non-ASCII characters, because return values of `getch` are
        # limited to the current 8-bit codepage.
        #
        # Anyway, Click doesn't claim to do this Right(tm), and using `getwch`
        # is doing the right thing in more situations than with `getch`.
        if echo:
            func = msvcrt.getwche
        else:
            func = msvcrt.getwch

        rv = func()
        if rv in (u"\x00", u"\xe0"):
            # \x00 and \xe0 are control characters that indicate special key,
            # see above.
            rv += func()
        _translate_ch_to_exc(rv)
        return rv 
开发者ID:pypa,项目名称:pipenv,代码行数:44,代码来源:_termui_impl.py


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