本文整理汇总了Python中msvcrt.getch方法的典型用法代码示例。如果您正苦于以下问题:Python msvcrt.getch方法的具体用法?Python msvcrt.getch怎么用?Python msvcrt.getch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类msvcrt
的用法示例。
在下文中一共展示了msvcrt.getch方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: interpret_keypress
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getch [as 别名]
def interpret_keypress(other_allowable=""):
"""
See whether a number was pressed (give terminal bell if so) and return
value. Otherwise returns none. Tries to handle arrows as a single
press.
"""
press = getch()
if press == '\x1b':
getch()
getch()
press = "direction"
if press.upper() in other_allowable:
return press.upper()
if press != "direction" and press != " ":
try:
press = int(press)
except ValueError:
press = None
return press
示例2: _WaitForFinish
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getch [as 别名]
def _WaitForFinish(ob, timeout):
end = time.time() + timeout
while 1:
if msvcrt.kbhit():
msvcrt.getch()
break
pythoncom.PumpWaitingMessages()
stopEvent.wait(.2)
if stopEvent.isSet():
stopEvent.clear()
break
try:
if not ob.Visible:
# Gone invisible - we need to pretend we timed
# out, so the app is quit.
return 0
except pythoncom.com_error:
# Excel is busy (eg, editing the cell) - ignore
pass
if time.time() > end:
return 0
return 1
示例3: main
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getch [as 别名]
def main():
while (1==1):
try:
take_order()
except SystemExit:
import msvcrt
while msvcrt.kbhit():
msvcrt.getch()
print "* Bye..."
sys.exit(1)
except KeyboardInterrupt:
import msvcrt
while msvcrt.kbhit():
msvcrt.getch()
print "* Bye..."
sys.exit(1)
except:
if console:
print "---\nError, sleeping mode!(", str(sys.exc_info()), ")"
time.sleep(300)
main()
示例4: win_getpass
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getch [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.putch(c)
pw = ""
while 1:
c = msvcrt.getch()
if c == '\r' or c == '\n':
break
if c == '\003':
raise KeyboardInterrupt
if c == '\b':
pw = pw[:-1]
else:
pw = pw + c
msvcrt.putch('\r')
msvcrt.putch('\n')
return pw
示例5: get_pager_start
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getch [as 别名]
def get_pager_start(pager, start):
"""Return the string for paging files with an offset.
This is the '+N' argument which less and more (under Unix) accept.
"""
if pager in ['less','more']:
if start:
start_string = '+' + str(start)
else:
start_string = ''
else:
start_string = ''
return start_string
# (X)emacs on win32 doesn't like to be bypassed with msvcrt.getch()
示例6: getarrow
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getch [as 别名]
def getarrow(self):
''' Returns an arrow-key code after kbhit() has been called. Codes are
0 : up
1 : right
2 : down
3 : left
Should not be called in the same program as getch().
'''
if os.name == 'nt':
msvcrt.getch() # skip 0xE0
c = msvcrt.getch()
vals = [72, 77, 80, 75]
else:
c = sys.stdin.read(3)[2]
vals = [65, 67, 66, 68]
return vals.index(ord(c.decode('utf-8')))
示例7: get_input_interrupted
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getch [as 别名]
def get_input_interrupted(prompt):
# TODO: refactor to use interruptable prompt from prompt_toolkit in api.py:193 (login: process 2fa error codes).
# This method to be removed.
if os.name == 'nt':
global win_cancel_getch
print(prompt)
win_cancel_getch = False
result = b''
while not win_cancel_getch:
if msvcrt.kbhit():
ch = msvcrt.getch()
if ch in [b'\r', b'\n']:
break
result += ch
else:
time.sleep(0.1)
if win_cancel_getch:
raise KeyboardInterrupt()
return result.decode()
else:
return input(prompt)
示例8: getarrow
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getch [as 别名]
def getarrow(self):
''' Returns an arrow-key code after kbhit() has been called. Codes are
0 : up
1 : right
2 : down
3 : left
Should not be called in the same program as getch().
'''
if os.name == 'nt':
msvcrt.getch() # skip 0xE0
c = msvcrt.getch()
vals = [72, 77, 80, 75]
else:
c = sys.stdin.read(3)[2]
vals = [65, 67, 66, 68]
return vals.index(ord(c.decode('utf-8')))
示例9: wait_key
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getch [as 别名]
def wait_key():
''' Wait for a key press on the console and return it. '''
result = None
if os.name == 'nt':
import msvcrt
result = msvcrt.getch()
else:
import termios
fd = sys.stdin.fileno()
oldterm = termios.tcgetattr(fd)
newattr = termios.tcgetattr(fd)
newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO
termios.tcsetattr(fd, termios.TCSANOW, newattr)
try:
result = sys.stdin.read(1)
except IOError:
pass
finally:
termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
return result
示例10: _find_getch
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getch [as 别名]
def _find_getch():
try:
import termios
except ImportError:
# Non-POSIX. Return msvcrt's (Windows') getch.
import msvcrt
return msvcrt.getch
# POSIX system. Create and return a getch that manipulates the tty.
import sys, tty
def _getch():
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(fd)
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
return _getch
示例11: __call__
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getch [as 别名]
def __call__(self):
import msvcrt
return msvcrt.getch()
示例12: getchar
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getch [as 别名]
def getchar():
return msvcrt.getch()
示例13: _find_getch
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getch [as 别名]
def _find_getch():
try:
import termios
except ImportError:
# Non-POSIX. Return msvcrt's (Windows') getch.
import msvcrt
return msvcrt.getch
# POSIX system. Create and return a getch that manipulates the tty.
import sys, tty
def _getch():
fd = sys.stdin.fileno()
old_settings = None
try:
old_settings = termios.tcgetattr(fd)
tty.setraw(fd)
except termios.error:
pass
try:
ch = sys.stdin.read(1)
finally:
if old_settings is not None:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
return _getch
示例14: test_main
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getch [as 别名]
def test_main(external_interpreters):
print('Default JSEngine is %r' % jsengine.JSEngine)
print('Default external_interpreter is %r' % jsengine.external_interpreter)
for JSEngine in (ChakraJSEngine, QuickJSEngine):
test_engine(JSEngine)
for external_interpreter in external_interpreters:
if set_external_interpreter(external_interpreter):
test_engine(ExternalJSEngine)
if platform.system() == 'Windows':
import msvcrt
print('Press any key to continue ...')
msvcrt.getch()
示例15: getch
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import getch [as 别名]
def getch():
"""
Gets a single character from STDIO.
"""
import sys
import tty
import termios
fd = sys.stdin.fileno()
old = termios.tcgetattr(fd)
try:
tty.setraw(fd)
return sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old)