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

Python msvcrt.getwch函数代码示例

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

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



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

示例1: processKey

def processKey():
	"""Process the user input for menu navigation."""
	global option, size, difficulty, placeObstacles, play, quit

	key = msvcrt.getwch()

	if key == "\xe0":
		key = msvcrt.getwch()

		if key == Direction.UP and option > 0:
			option -= 1
		elif key == Direction.DOWN and option < 4:
			option += 1
		elif key == Direction.LEFT:
			if option == 1 and size > 0 and size <= 2:
				size -= 1
			elif option == 2 and difficulty > 0 and difficulty <= 2:
				difficulty -= 1
			elif option == 3:
				placeObstacles = not placeObstacles
		elif key == Direction.RIGHT:
			if option == 1 and size >= 0 and size < 2:
				size += 1
			elif option == 2 and difficulty >= 0 and difficulty < 2:
				difficulty += 1
			elif option == 3:
				placeObstacles = not placeObstacles
	elif key == "\r":
		if option == 0:
			play = True
		elif option == 4:
			quit = True
开发者ID:jaminthorns,项目名称:ascii-snake,代码行数:32,代码来源:Play.py


示例2: _getch

 def _getch():
     a = msvcrt.getwch()
     if a == '\x00' or a == '\xe0':
         b = msvcrt.getwch()
         return [a, b]
     else:
         return a
开发者ID:FedeG,项目名称:autopython,代码行数:7,代码来源:console.py


示例3: getkey

 def getkey(self):
     while True:
         z = msvcrt.getwch()
         if z == '\r':
             return '\n'
         elif z in '\x00\x0e':    # functions keys, ignore
             msvcrt.getwch()
         else:
             return z
开发者ID:hardkrash,项目名称:pyserial,代码行数:9,代码来源:miniterm.py


示例4: getkey

 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:bq,项目名称:witbox-updater,代码行数:9,代码来源:miniterm.py


示例5: readch

 def readch(echo=True):
     "Get a single character on Windows."
     while msvcrt.kbhit():  # clear out keyboard buffer
         msvcrt.getwch()
     ch = msvcrt.getwch()
     if ch in u'\x00\xe0':  # arrow or function key prefix?
         ch = msvcrt.getwch()  # second call returns the actual key code
     if echo:
         msvcrt.putwch(ch)
     return ch
开发者ID:dmf24,项目名称:pyscripting,代码行数:10,代码来源:getkey.py


示例6: get_key

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:alexandre-paroissien,项目名称:thefuck,代码行数:13,代码来源:win32.py


示例7: WinGetPass

def WinGetPass(prompt='Password: ', stream=None):
    """
    Prompt for password with echo off, using Windows getch().

    :param stream: No idea #SorryNotSorry
    :param prompt: What to display/prompt to the user.
    """
    if sys.stdin is not sys.__stdin__:
        return FallbackGetPass(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':
            break
            # raise KeyboardInterrupt
        if c == '\b':
            if len(pw) > 0:
                pw = pw[:-1]
                msvcrt.putwch('\x08')
                msvcrt.putwch(' ')
                msvcrt.putwch('\x08')
        else:
            msvcrt.putwch('*')
            pw = pw + c
    msvcrt.putwch('\r')
    msvcrt.putwch('\n')
    return pw
开发者ID:iaz3,项目名称:RbxAPI,代码行数:31,代码来源:inputPass.py


示例8: __ichr

 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:NilSet,项目名称:whitespacers,代码行数:16,代码来源:interpreter.py


示例9: getpass

 def getpass(prompt):
     if iswindows:
         # getpass is broken on windows with python 2.x and unicode, the
         # below implementation is from the python 3 source code
         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
     else:
         enc = getattr(sys.stdin, 'encoding', preferred_encoding) or preferred_encoding
         from getpass import getpass
         return getpass(prompt).decode(enc)
开发者ID:JimmXinu,项目名称:calibre,代码行数:25,代码来源:unicode_getpass.py


示例10: win_terminal

def win_terminal(input_buffer_number, device_buffer_number, input_device):
    if msvcrt.kbhit():
        # for test purposes!!
        # this is the keyboard interface not according to MYC specification:
        # a numeric input as ascii (decimal 0... 255) values is converted to one byte
        # after each space the sub for checking the v_kbd_input.a is called
        # str
        t = msvcrt.getwch()
        if ord(t) == 32:
            if v_kbd_input.a != "":
                i = (int(v_kbd_input.a))
                if i < 256:
                    # 0: buffer for input, 1: buffer for device
                    if input_device == 0:
                        # start timeout
                        if v_input_buffer.starttime[input_buffer_number] == 0:
                            v_input_buffer.starttime[input_buffer_number] = int(time.time())
                            # input buffer
                            v_input_buffer.inputline[input_buffer_number] += int_to_bytes(i, 1)
                            if input_device == 0:
                                print("HI_in", input_buffer_number, v_kbd_input.a)
                            else:
                                print("device_in", device_buffer_number, v_kbd_input.a)
                    else:
                        v_device_buffer.data_to_CR[device_buffer_number] += int_to_bytes(i, 1)
                    v_kbd_input.a = ""
        else:
            if str.isnumeric(t) == 1:
                v_kbd_input.a += t
    return
开发者ID:dk1ri,项目名称:MYC_project,代码行数:30,代码来源:commandrouter_terminal_handling.py


示例11: main

def main():
    size = input("Choose the size of your board.\n")
    b = Board(int(size),int(size))
    b.generateNewBlock()
    win = graphics.GraphWin("TheBoard", b.cols*cellSize, b.rows*cellSize)
    gameOver = False
    for i in b.board:
        b.board[i].visual.draw(win)
        b.board[i].text.draw(win)
    while not gameOver:
        for i in b.board:
            b.board[i].setColor()
            if b.board[i].number != 0:
                b.board[i].text.setText(str(b.board[i].number))
            else:
                b.board[i].text.setText("")
        char = msvcrt.getwch()
        move = None
        if char == 'a':
            move = 'left'
        if char == 's':
            move = 'down'
        if char == 'd':
            move = 'right'
        if char == 'w':
            move = 'up'
        if char == 'q':
            print("Bye!")
            time.sleep(1)
            return
        if type(move) == type(''):
            b.push(move)
            gameOver = b.generateNewBlock()
    return "GAME OVER"
开发者ID:MichaelSheely,项目名称:Python-Scripts,代码行数:34,代码来源:python2048.py


示例12: readInput

    def readInput(self, prompt, timeout = 10 ) :
        start_time = time.time()
        sys.stdout.write(u'%s'%prompt)
        inputString = u''
        while True :
            if (time.time() - start_time) > timeout :
                return None
            if msvcrt.kbhit() :
                start_time = time.time()
                ch = msvcrt.getwch()

                if ord(ch) == 13 : # enter key
                    if inputString == 'q' :
                        return None
                    elif len(inputString) == 0 :
                        return None
                    elif len(inputString) > 0 :
                        return inputString
                elif ord(ch) == 8 : # back space
                    inputString = inputString[0:-1]
                else : inputString += ch
                
                try : inputString = unicode(inputString)
                except : 
                    sys.stdout.write(u'\r%s%s'%(prompt,
                                     u'unicode converting error for inputString'))
                    sys.stdout.flush()
                    continue
                
                sys.stdout.write(u'\r%s%s'%(prompt,' '*(len(inputString)*2+1)))
                sys.stdout.write(u'\r%s%s'%(prompt, inputString))
                sys.stdout.flush()
        return None
开发者ID:ClarkOh,项目名称:MyWork,代码行数:33,代码来源:cxConsoleThread.py


示例13: normal

def normal(world: World, pl: Character):
    os.system('setterm -cursor off')
    print()
    direction = "down"
    flag = "none"
    while flag == "none":
        os.system('cls')
        pl.update()
        show_world(world, pl)
        print(statusbar_generate(pl))
        print(itembar_generate(pl, world))
        ch = getwch()
        if ch == "w" or ch == "W":
            world.player_shift(pl, "up")
        elif ch == "a" or ch == "A":
            world.player_shift(pl, "left")
        elif ch == "s" or ch == "S":
            world.player_shift(pl, "down")
        elif ch == "d" or ch == "D":
            world.player_shift(pl, "right")
        elif ch == "e" or ch == "E":
            if pl.item_available(world):
                pl.take(world)
            elif pl.nearest(pl.fov(direction, pl.Current_Gun.Range, world), world.Entity_list):
                attack(pl, world, pl.nearest(pl.fov(direction, pl.Current_Gun.Range, world), world.Entity_list,
                                             ["Hostile", "Tile"]))
        elif ch == "`":
            print("GoodBye!")
            flag = "ExitKey"
开发者ID:mkrooted,项目名称:TankBattle,代码行数:29,代码来源:Controls.py


示例14: win_getpass

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.getwch()
		if c == '\r' or c == '\n':
			break
		if c == '\003':
			raise KeyboardInterrupt
		if c == '\b':
			if pw == '':
				pass
			else:
				pw = pw[:-1]
				msvcrt.putch('\b')
				msvcrt.putch(" ")
				msvcrt.putch('\b')
		else:
			pw = pw + c
			msvcrt.putch("*")
	msvcrt.putch('\r')
	msvcrt.putch('\n')
	return pw
开发者ID:essoen,项目名称:ezportify,代码行数:28,代码来源:ezportify.py


示例15: getch

def getch(prompt=''):

	"""Reads a character from standard input.

	If the user enters a newline, an empty string is returned. For the most
	part, this behaves just like input().  An optional prompt can be
	provided.

	"""

	print(prompt, end='')
	sys.stdout.flush()

	# Windows
	try:
		char = msvcrt.getwch()
	except NameError:
		pass
	else:
		if char == '\r' or char == '\n':
			char = ''

		print(char, end='')
		sys.stdout.flush()

		return char

	# Unix
	file_number = sys.stdin.fileno()
	try:
		old_settings = termios.tcgetattr(file_number)
	except NameError:
		pass
	except termios.error:
		pass
	else:
		tty.setcbreak(file_number)

	try:
		char = chr(27)
		if sys.stdin.isatty():
			# avoid escape sequences and other undesired characters
			while ord(char[0]) in (8, 27, 127):
				char = sys.stdin.read(len(sys.stdin.buffer.peek(1)))
		else:
			char = sys.stdin.read(1)

		if char == '\r' or char == '\n':
			char = ''

		if 'old_settings' in locals():
			print(char, end='')
			sys.stdout.flush()
	finally:
		try:
			termios.tcsetattr(file_number, termios.TCSADRAIN, old_settings)
		except NameError:
			pass

	return char
开发者ID:tylercrompton,项目名称:getch,代码行数:60,代码来源:getch.py


示例16: getkey

 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,代码行数:16,代码来源:term.py


示例17: _windows_key_press

def _windows_key_press(wanted_key, stop_event, received_cb):
    '''Check for key presses from stdin in non-blocking way. Check until either
    `wanted_key` was pressed or `stop_event` has been set.
    If we detect `wanted_key` before `stop_event` is set, call `received_cb`
    callback and return.

    @param wanted_key: key to be pressed (in our case "q")
    @type wanted_key: one-letter str

    @param stop_event: indicate to stop reading and return
    @type stop_event: threading.Event

    @param received_cb: called when `wanted_key` was read
    @type received_cb: empty-argument callable
    '''
    import msvcrt
    import sys
    import time

    # skip if input is received from file or pipe redirection
    if not sys.stdin.isatty():
        return

    wanted_key = wanted_key.lower()
    while not stop_event.is_set():
        if msvcrt.kbhit():
            c = msvcrt.getwch()
            if c.lower() == wanted_key:
                received_cb()
                break
        else:
            time.sleep(0.5)
开发者ID:Mimino666,项目名称:tc-marathoner,代码行数:32,代码来源:key_press.py


示例18: raw_getkey

def raw_getkey():
    key = msvcrt.getwch()
    log.debug("key: %r", key)
    nkey = ord(key)

    if nkey in (0, 224):
        key2 = msvcrt.getwch()
        nkey2 = ord(key2)
        log.debug("key2: %r nkey2: %r", key2, nkey2)
        if nkey2 in key_map:
            return key_map[nkey2]
        return "key%s" % key

    if key in ("\r", "\n"):
        key = "enter"

    return key
开发者ID:jtruscott,项目名称:pytality,代码行数:17,代码来源:term_winconsole.py


示例19: _getch_win

 def _getch_win(cl, echo=False):
     import msvcrt
     import time
     while not msvcrt.kbhit():
         time.sleep(0.1)
     if echo:
         return msvcrt.getwche()
     return msvcrt.getwch()
开发者ID:47-,项目名称:Cyprium,代码行数:8,代码来源:ui.py


示例20: donor_data_modifier

def donor_data_modifier():
    lista=[]
    found=0
    os.system('cls')
    change_according_ID=input("What ID you search for: ").lower()
    read_line=open("Data/donor.csv", "r+")
    read_the_list=csv.reader(read_line,delimiter=',',quotechar='"')
    for row in read_the_list:
        if row[7]==change_according_ID:
            found+=1
            lista=row
            print('-'*40)
            name=row[0].split(" ")
            if len(name)==2:
                print("\t "+name[1]+ ", "+ name[0])
            elif len(name)==3:
                print("\t "+name[2]+", "+name[1]+", "+name[0])
            print("\t "+str(row[1])+"kg")
            print("\t "+row[2][0:4]+"."+row[2][5:7]+"."+row[2][8:10]+"  -  "+str(row[3])+" years old")
            print("\t "+row[9])
            print("\t "+row[10])
            print("\t "+"ID: "+row[7])
            print('-'*40)
            print('\n')
    read_line.close()
    if found==0:
        print("This ID not found!")
        msvcrt.getwch()
    else:
        delete_from_csv = open("Data/donor.csv", "r+")
        read_csv_line=delete_from_csv.readlines()
        delete_from_csv.seek(0)
        for i in read_csv_line:
            splitted=i.split(',')
            if change_according_ID!=splitted[7]:
                delete_from_csv.write(i)
        delete_from_csv.truncate()
        delete_from_csv.close()
        write_rows=open("Data/donor.csv", 'a', newline='\n')
        writter=csv.writer(write_rows)
        lista=donor_data_manager(lista)
        writter.writerow(lista)
        write_rows.close()
        msvcrt.getwch()
    main.creat_menu()
开发者ID:Kristof95,项目名称:GoodLuckHaveFun,代码行数:45,代码来源:modify.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python msvcrt.kbhit函数代码示例发布时间:2022-05-27
下一篇:
Python msvcrt.getche函数代码示例发布时间: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