本文整理匯總了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)