本文整理汇总了Python中msvcrt.getwch函数的典型用法代码示例。如果您正苦于以下问题:Python getwch函数的具体用法?Python getwch怎么用?Python getwch使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getwch函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例2: _getch
def _getch():
a = msvcrt.getwch()
if a == '\x00' or a == '\xe0':
b = msvcrt.getwch()
return [a, b]
else:
return a
示例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
示例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
示例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
示例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
示例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
示例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)
示例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)
示例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
示例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"
示例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
示例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"
示例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
示例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