當前位置: 首頁>>代碼示例>>Python>>正文


Python msvcrt.kbhit方法代碼示例

本文整理匯總了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() 
開發者ID:mertsarica,項目名稱:hack4career,代碼行數:23,代碼來源:apt_simulator.py

示例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 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:24,代碼來源:testMSOfficeEvents.py

示例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'))) 
開發者ID:sonofeft,項目名稱:RocketCEA,代碼行數:21,代碼來源:keyboard_hit.py

示例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) 
開發者ID:Keeper-Security,項目名稱:Commander,代碼行數:24,代碼來源:yubikey.py

示例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) 
開發者ID:ActiveState,項目名稱:code,代碼行數:18,代碼來源:recipe-577110.py

示例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'))) 
開發者ID:fandoghpaas,項目名稱:fandogh-cli,代碼行數:21,代碼來源:utils.py

示例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. 
開發者ID:PyOCL,項目名稱:OpenCLGA,代碼行數:25,代碼來源:ocl_ga_server.py

示例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 
開發者ID:corpnewt,項目名稱:USBMap,代碼行數:37,代碼來源:utils.py

示例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() 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:30,代碼來源:_process_win32_controller.py

示例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 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:9,代碼來源:inputhookpyglet.py

示例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() 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:5,代碼來源:inputhook.py

示例12: stdin_ready

# 需要導入模塊: import msvcrt [as 別名]
# 或者: from msvcrt import kbhit [as 別名]
def stdin_ready():
        return msvcrt.kbhit()

#-----------------------------------------------------------------------------
# Callback functions
#----------------------------------------------------------------------------- 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:8,代碼來源:inputhookglut.py

示例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 
開發者ID:AlexisTM,項目名稱:flyingros,代碼行數:15,代碼來源:getch.py

示例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) 
開發者ID:sonofeft,項目名稱:RocketCEA,代碼行數:14,代碼來源:keyboard_hit.py

示例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 
開發者ID:sonofeft,項目名稱:RocketCEA,代碼行數:14,代碼來源:keyboard_hit.py


注:本文中的msvcrt.kbhit方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。