当前位置: 首页>>代码示例>>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;未经允许,请勿转载。