• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python msvcrt.putch函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: 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("More? y/Y")                        # 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
        elif sys.platform == 'darwin':
            os.system("printf 'More? '")
            key = open('/dev/tty').readline()[:-1]
            os.system("printf '\n'")
            return key
        else:
            assert False, 'platform not supported'
开发者ID:KhalidEzzeldeen,项目名称:BitsAndBobs,代码行数:21,代码来源:moreplusplus.py


示例17: run

    def run(self):
        """

        """
        global _CMD_Queue
        global _Quit
        _Quit_Lock.acquire()
        done = _Quit
        _Quit_Lock.release()
        logger.write_line("Beginning Read Line Thread loop")
        while not done:
            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:
                _CMD_Queue.put(line)
                if line != "":
                    logger.write_line("Input from user: %s" % line)
            except:
                pass
            _Quit_Lock.acquire()
            done = _Quit
            _Quit_Lock.release()
开发者ID:AbeDillon,项目名称:RenAdventure,代码行数:39,代码来源:Single_Port_client.py


示例18: ReadLine

def ReadLine(label, defaultValue = "", password = False):
    """Read a line of input from stdin and return it. If nothing is read, the
       default value is returned. Note that if stdin in not a TTY, the label
       will not be displayed."""
    if sys.stdin.isatty():
        if defaultValue:
            label += " [%s]" % defaultValue
        label += ": "
        if password:
            result = getpass.getpass(label)
        else:
            if sys.platform == "win32":
                import msvcrt
                for c in label:
                    msvcrt.putch(c)
                result = sys.stdin.readline().strip()
            else:
                result = raw_input(label).strip()
    else:
        result = raw_input().strip()
    if not result:
        return defaultValue
    return result
开发者ID:marhar,项目名称:cx_OracleTools,代码行数:23,代码来源:cx_ReadLine.py


示例19: 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 raw_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('?')                               # use windows console tools
            key = msvcrt.getche()                           # getch( ) does not echo key
            msvcrt.putch('\n')
            return key
        elif sys.platform[:5] == 'linux':                   # use linux console device
            print '?'                                       # strip eoln at line end
            console = open('/dev/tty')
            line = console.readline()[:-1]
            return line
        else:
            print '[pause]'                                 # else just pause--improve me
            import time                                     # see also modules curses, tty
            time.sleep(5)                                   # or copy to temp file, rerun
            return 'y'                                      # or GUI pop up, tk key bind
开发者ID:zzygit,项目名称:python,代码行数:24,代码来源:moreplus.py


示例20: getreply

def getreply():
    '''
    read a reply from a user ,even if
    stdin redirected to a file or pipe
    '''
    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'
开发者ID:kcatl,项目名称:pygame_temp,代码行数:24,代码来源:moreplus.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python msvcrt.setmode函数代码示例发布时间:2022-05-27
下一篇:
Python msvcrt.open_osfhandle函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap