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


Python msvcrt.putch函数代码示例

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


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

示例1: getpass

def getpass(prompt = 'Password: '):
    count = 0
    chars = []
    for x in prompt:
        msvcrt.putch(bytes(x,'utf8'))
    while True:
        new_char = msvcrt.getch()
        if new_char in b'\r\n':
            break
        elif new_char == b'\0x3': #ctrl + c
            raise KeyboardInterrupt
        elif new_char == b'\b':
            if chars and count >= 0:
                count -= 1
                chars =  chars[:-1]
                msvcrt.putch(b'\b')
                msvcrt.putch(b'\x20')#space
                msvcrt.putch(b'\b')
        else:
            if count < 0:
                count = 0
            count += 1
            chars.append(new_char.decode('utf8'))
            msvcrt.putch(b'*')
    return ''.join(chars)
开发者ID:fengwn1997,项目名称:getpass_mod,代码行数:25,代码来源:getpass_mod.py

示例2: getResponse

    def getResponse(self):

        try:
            if sys.stdin.isatty():
                return raw_input(">")
            else:
                if sys.platform[:3] == "win":
                    import msvcrt

                    msvcrt.putch(">")
                    key = msvcrt.getche()
                    msvcrt.putch("\n")
                    return key
                elif sys.platform[:5] == "linux":
                    print ">"
                    console = open("/dev/tty")
                    line = console.readline()[:-1]
                    return line
                else:
                    print "[pause]"
                    import time

                    time.sleep(5)
                    return "y"
        except:
            return "done"
开发者ID:fygrave,项目名称:wibat,代码行数:26,代码来源:wi.py

示例3: get_command

 def get_command():
     """Uses the msvcrt module to get key codes from buttons pressed to navigate through the game. The arrows,
     enter, tab, Page Down, and escape keys are used so far."""
     cmd = ""
     while 1:
         key = ord(getch())
         if key == 224:
             key = ord(getch())
             cmd = arrow_keys.get(key, "")
             return cmd
         elif key == 13:
             putch("\n")
             break
         elif key == 8:
             cmd = cmd[:-1]
             putch(chr(8))
             putch(" ")
             putch(chr(8))
         elif key == 27:
             cmd = 'q'
             return cmd
         elif key == 9:
             cmd = 'tab'
             return cmd
         else:
             putch(chr(key))
             cmd += chr(key)
     return cmd
开发者ID:TeddyBerhane,项目名称:PyCharm,代码行数:28,代码来源:Zombie+Raid.py

示例4: _getpass

def _getpass(prompt='Password:'):
    """
    获取用户输入的密码,在控制台输入的时候显示星号
    """
    count = 0
    chars = []
    for xchar in prompt:
        msvcrt.putch(xchar)
    while True:
        new_char = msvcrt.getch()
        if new_char in '\r\n':
            break
        elif new_char == '\0x3': #ctrl + c
            raise KeyboardInterrupt
        elif new_char == '\b':
            if chars and count >= 0:
                count -= 1
                chars = chars[:-1]
                msvcrt.putch('\b')
                msvcrt.putch('\x20')#space
                msvcrt.putch('\b')
        else:
            if count < 0:
                count = 0
            count += 1
            chars.append(new_char)
            msvcrt.putch('*')
    # 在输入之后回车,防止下一个输出直接接在在密码后面
    print ""
    return ''.join(chars)
开发者ID:ljm1992,项目名称:leangoo_helper,代码行数:30,代码来源:leangoo_interface.py

示例5: run

    def run(self):
        """

        """
        global _Server_Queue
        while True:  # What would cause this to stop? Only the program ending.
            line = ""
            while 1:
                char = msvcrt.getche()
                if char == "\r":  # enter
                    break

                elif char == "\x08":  # backspace
                    # Remove a character from the screen
                    msvcrt.putch(" ")
                    msvcrt.putch(char)

                    # Remove a character from the string
                    line = line[:-1]

                elif char in string.printable:
                    line += char

                time.sleep(0.01)

            try:
                _Server_Queue.put(line)
                if line != "":
                    _Logger.debug("Input from server console: %s" % line)
            except:
                pass
开发者ID:AbeDillon,项目名称:RenAdventure,代码行数:31,代码来源:Single_Port_server.py

示例6: putchxy

def putchxy(x, y, ch):
  """
  Puts a char at the specified position. The cursor position is not affected.
  """
  prevCurPos = getcurpos()
  setcurpos(x, y)
  msvcrt.putch(ch)
  setcurpos(prevCurPos.x, prevCurPos.y)
开发者ID:jeaf,项目名称:apptrigger,代码行数:8,代码来源:cio.py

示例7: getReply

def getReply():
        if sys.stdin.isatty():
                return input("?")
        if sys.platform[:3] == 'win':
                import msvcrt
                msvcrt.putch(b'?')
                key = msvcrt.getche()
                msvcrt.putch(b'\n')
                return key
        else:
                assert False, 'platform not supported'
开发者ID:wangmingzhitu,项目名称:tools,代码行数:11,代码来源:paging.py

示例8: getreply

def getreply():
	if sys.stdin.isatty():
		return sys.stdin.read(1)
	else:
		if sys.platform[:3] == 'win':
			import msvcrt
			msvcrt.putch(b'?')
			key = msvcrt.getche()
			return key
		else:
			return open('/dev/tty').readline()[:-1]
开发者ID:Ivicel,项目名称:pp4me,代码行数:11,代码来源:moreplus.py

示例9: getreply

def getreply():
    if sys.stdin.isatty():
        return raw_input("?")
    else:
        if sys.platform[:3] == "lin":
            import msvcrt

            msvcrt.putch(b"?")
            key = msvcrt.getche()
            msvcrt.putch(b"\n")
            return key
        else:
            assert False, "platform not supported"
开发者ID:theo-l,项目名称:.blog,代码行数:13,代码来源:moreplus.py

示例10: pwd_input

def pwd_input(msg):
    print msg,

    import msvcrt
    chars = []
    while True:
        try:
            new_char = msvcrt.getch().decode(encoding="utf-8")
        except:
            return input("你很可能不是在 cmd 命令行下运行,密码输入将不能隐藏:")

        if new_char in '\r\n':  # 如果是换行,则输入结束
            break

        elif new_char == '\b':  # 如果是退格,则删除密码末尾一位并且删除一个星号
            if chars is not None:
                del chars[-1]
                msvcrt.putch('\b'.encode(encoding='utf-8'))     # 光标回退一格
                msvcrt.putch(' '.encode(encoding='utf-8'))      # 输出一个空格覆盖原来的星号
                msvcrt.putch('\b'.encode(encoding='utf-8'))     # 光标回退一格准备接受新的输入
        else:
            chars.append(new_char)
            msvcrt.putch('*'.encode(encoding='utf-8'))  # 显示为星号

    print
    return ''.join(chars)
开发者ID:LucaBongiorni,项目名称:nbackdoor,代码行数:26,代码来源:controller_client.py

示例11: getreply

def getreply():
    '''
    读取交互式用户的回复键,即使stdin重定向到某个文件或者管道
    '''
    if sys.stdin.isatty():
        return input('?')       # 如果stdin 是控制台 从stdin 读取回复行数据
    else :
        if sys.platform[:3]  == 'win':   # 如果stdin 重定向,不能用于询问用户
            import msvcrt
            msvcrt.putch(b'?')
            key = msvcrt.getche()        # 使用windows 控制台工具 getch()方法不能回应键
            return key
        else:
            assert False,'platform not supported'
开发者ID:PythonStudy,项目名称:CorePython,代码行数:14,代码来源:moreplus.py

示例12: getreply

def getreply():
    """
    read a reply key from an interactive user
    even if stdin redirected to a file or pipe
    """
    if sys.stdin.isatty():                       # if stdin is console
        return input('?')                        # read reply line from stdin
    else:
        if sys.platform[:3] == 'win':            # if stdin was redirected
            import msvcrt                        # can't use to ask a user
            msvcrt.putch(b'?')
            key = msvcrt.getche()                # use windows console tools
            msvcrt.putch(b'\n')                  # getch() does not echo key
            return key
        else:
            assert False, 'platform not supported'
开发者ID:chuzui,项目名称:algorithm,代码行数:16,代码来源:moreplus.py

示例13: getreply

def getreply():
    """
    читает клавишу, нажатую пользователем,
    даже если stdin перенаправлен в файл или канал
    """
    if sys.stdin.isatty():  # если stdin связан с консолью,
        return input('?')  # читать ответ из stdin
    else:
        if sys.platform[:3] == 'win':  # если stdin был перенаправлен,
            import msvcrt  # его нельзя использовать для чтения
            msvcrt.putch(b'?')  # ответа пользователя
            key = msvcrt.getche()  # использовать инструмент консоли
            msvcrt.putch(b'\n')  # getch(), которая не выводит символ
            return key  # для нажатой клавиши
        else:
            assert False, 'platform not supported'
开发者ID:pasko-evg,项目名称:ProjectLearning,代码行数:16,代码来源:moreplus.py

示例14: getreply

def getreply():
	"""
	read a reply key from an interactive user
	even if stdin redirected to a file or pipe
	"""
	if sys.stdin.isatty():
		return input('?')
	else:
		if sys.platform[:3] == 'win':
			import msvcrt
			msvcrt.putch(b'?')
			key = msvcrt.getche()
			msvcrt.putch(b'\n')
			return key
		else:
			assert False, 'platform not supported'
开发者ID:zhongjiezheng,项目名称:python,代码行数:16,代码来源:moreplus.py

示例15: do_stop

    def do_stop(self, line):
        '''stop

Shuts down the server gently...ish.'''
        global RUNNING
        RUNNING=False
        #In order to finalize this, we need to wake up all
        #threads. Main is awake on a one-second loop, the
        #server does acquiry every 5 seconds, and the client
        #manager every fraction of a second. Our UIthread will
        #respond to a character, so lets put one on there:
        if curses:
            curses.ungetch('\x00')
        elif msvcrt:
            msvcrt.putch('\x00')
        #else, panic.
        #after that's done, all the threads should realize that
        #it's time to pack up.
        print 'This will take up to 5 seconds...'
开发者ID:Grissess,项目名称:nSS,代码行数:19,代码来源:nss.py


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