本文整理匯總了Python中msvcrt.kbhit方法的典型用法代碼示例。如果您正苦於以下問題:Python msvcrt.kbhit方法的具體用法?Python msvcrt.kbhit怎麽用?Python msvcrt.kbhit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類msvcrt
的用法示例。
在下文中一共展示了msvcrt.kbhit方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: main
# 需要導入模塊: import msvcrt [as 別名]
# 或者: from msvcrt import kbhit [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()
示例2: _WaitForFinish
# 需要導入模塊: import msvcrt [as 別名]
# 或者: from msvcrt import kbhit [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: getarrow
# 需要導入模塊: import msvcrt [as 別名]
# 或者: from msvcrt import kbhit [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')))
示例4: get_input_interrupted
# 需要導入模塊: import msvcrt [as 別名]
# 或者: from msvcrt import kbhit [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)
示例5: __ichr
# 需要導入模塊: import msvcrt [as 別名]
# 或者: from msvcrt import kbhit [as 別名]
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)
示例6: getarrow
# 需要導入模塊: import msvcrt [as 別名]
# 或者: from msvcrt import kbhit [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: _handle_keyboard_message
# 需要導入模塊: import msvcrt [as 別名]
# 或者: from msvcrt import kbhit [as 別名]
def _handle_keyboard_message(self):
data = None
if sys.platform in ['linux', 'darwin']:
import select
if select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], []):
data = sys.stdin.readline().rstrip()
elif sys.platform == 'win32':
import msvcrt
if msvcrt.kbhit():
data = msvcrt.getch().decode('utf-8')
if data == '\r':
# Enter is pressed
data = self.__q_kb
self.__q_kb = ''
else:
print(data)
self.__q_kb += data
data = None
else:
pass
return data
## Get the data message which was queued earlier.
示例8: grab
# 需要導入模塊: import msvcrt [as 別名]
# 或者: from msvcrt import kbhit [as 別名]
def grab(self, prompt, **kwargs):
# Takes a prompt, a default, and a timeout and shows it with that timeout
# returning the result
timeout = kwargs.get("timeout", 0)
default = kwargs.get("default", None)
# If we don't have a timeout - then skip the timed sections
if timeout <= 0:
if sys.version_info >= (3, 0):
return input(prompt)
else:
return str(raw_input(prompt))
# Write our prompt
sys.stdout.write(prompt)
sys.stdout.flush()
if os.name == "nt":
start_time = time.time()
i = ''
while True:
if msvcrt.kbhit():
c = msvcrt.getche()
if ord(c) == 13: # enter_key
break
elif ord(c) >= 32: #space_char
i += c
if len(i) == 0 and (time.time() - start_time) > timeout:
break
else:
i, o, e = select.select( [sys.stdin], [], [], timeout )
if i:
i = sys.stdin.readline().strip()
print('') # needed to move to next line
if len(i) > 0:
return i
else:
return default
示例9: _run_stdio
# 需要導入模塊: import msvcrt [as 別名]
# 或者: from msvcrt import kbhit [as 別名]
def _run_stdio(self):
"""Runs the process using the system standard I/O.
IMPORTANT: stdin needs to be asynchronous, so the Python
sys.stdin object is not used. Instead,
msvcrt.kbhit/getwch are used asynchronously.
"""
# Disable Line and Echo mode
#lpMode = DWORD()
#handle = msvcrt.get_osfhandle(sys.stdin.fileno())
#if GetConsoleMode(handle, ctypes.byref(lpMode)):
# set_console_mode = True
# if not SetConsoleMode(handle, lpMode.value &
# ~(ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT)):
# raise ctypes.WinError()
if self.mergeout:
return self.run(stdout_func = self._stdout_raw,
stdin_func = self._stdin_raw_block)
else:
return self.run(stdout_func = self._stdout_raw,
stdin_func = self._stdin_raw_block,
stderr_func = self._stderr_raw)
# Restore the previous console mode
#if set_console_mode:
# if not SetConsoleMode(handle, lpMode.value):
# raise ctypes.WinError()
示例10: stdin_ready
# 需要導入模塊: import msvcrt [as 別名]
# 或者: from msvcrt import kbhit [as 別名]
def stdin_ready():
return msvcrt.kbhit()
# On linux only, window.flip() has a bug that causes an AttributeError on
# window close. For details, see:
# http://groups.google.com/group/pyglet-users/browse_thread/thread/47c1aab9aa4a3d23/c22f9e819826799e?#c22f9e819826799e
示例11: _stdin_ready_nt
# 需要導入模塊: import msvcrt [as 別名]
# 或者: from msvcrt import kbhit [as 別名]
def _stdin_ready_nt():
"""Return True if there's something to read on stdin (nt version)."""
return msvcrt.kbhit()
示例12: stdin_ready
# 需要導入模塊: import msvcrt [as 別名]
# 或者: from msvcrt import kbhit [as 別名]
def stdin_ready():
return msvcrt.kbhit()
#-----------------------------------------------------------------------------
# Callback functions
#-----------------------------------------------------------------------------
示例13: __call__
# 需要導入模塊: import msvcrt [as 別名]
# 或者: from msvcrt import kbhit [as 別名]
def __call__(self):
import msvcrt
import time
# Delay timeout to match UNIX behaviour
time.sleep(1)
# Check if there is a character waiting, otherwise this would block
if msvcrt.kbhit():
return msvcrt.getch()
else:
return
示例14: getch
# 需要導入模塊: import msvcrt [as 別名]
# 或者: from msvcrt import kbhit [as 別名]
def getch(self):
''' Returns a keyboard character after kbhit() has been called.
Should not be called in the same program as getarrow().
'''
s = ''
if os.name == 'nt':
return msvcrt.getch().decode('utf-8')
else:
return sys.stdin.read(1)
示例15: kbhit
# 需要導入模塊: import msvcrt [as 別名]
# 或者: from msvcrt import kbhit [as 別名]
def kbhit(self):
''' Returns True if keyboard character was hit, False otherwise.
'''
if os.name == 'nt':
return msvcrt.kbhit()
else:
dr,dw,de = select([sys.stdin], [], [], 0)
return dr != []
# Test