python类kbhit()的实例源码

main.py 文件源码 项目:OpenCLGA 作者: PyOCL 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def get_input():
    global lines
    data = None
    try:
        if sys.platform in ['linux', 'darwin']:
            import select
            time.sleep(0.01)
            if select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], []):
                data = sys.stdin.readline().rstrip()
        elif sys.platform == 'win32':
            import msvcrt
            time.sleep(0.01)
            if msvcrt.kbhit():
                data = msvcrt.getch().decode('utf-8')
                if data == '\r':
                    # Enter is pressed
                    data = lines
                    lines = ''
                else:
                    lines += data
                    print(data)
                    data = None
        else:
            pass
    except KeyboardInterrupt:
        data = 'exit'
    return data
noncanon_input.py 文件源码 项目:FrozenBottle 作者: freieslabor 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def getbyt(self):
        res = None
        if len(self.buf)>0:
            res = self.buf[0]
            self.buf = self.buf[1:]
        elif self.posix:
            nw = sys.stdin.read(32)
            if len(nw)>0:
                self.buf = nw[1:]
                res = nw[0]
        else:
            if msvcrt.kbhit():
                res = msvcrt.getch()
        return res
glfw_inputhook.py 文件源码 项目:yt 作者: yt-project 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def stdin_ready():
        return msvcrt.kbhit()

#-----------------------------------------------------------------------------
# Code
#-----------------------------------------------------------------------------
main_game.py 文件源码 项目:Console-Car-Racer 作者: gaborvecsei 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def userKeyboardInput():
    """
    Reads the input from the user
    :return: Keycode or None if there was no hit
    """

    x = msvcrt.kbhit()
    if x:
        ret = msvcrt.getch()
    else:
        ret = None
    return ret
logserver.py 文件源码 项目:PyMal 作者: cysinfo 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def check_key():
    if msvcrt is None:
        return False
    else:
        if msvcrt.kbhit()!=0:
            q=msvcrt.getch()

            return q in "q" 
        else:
            return False
logserver1.py 文件源码 项目:isf 作者: w3h 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def check_key():
    if msvcrt is None:
        return False
    else:
        if msvcrt.kbhit():
            q = ensure_unicode(msvcrt.getch())
            return q
    return ""
logserver.py 文件源码 项目:isf 作者: w3h 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def check_key():
    if msvcrt is None:
        return False
    else:
        if msvcrt.kbhit():
            q = ensure_unicode(msvcrt.getch())
            return q
    return ""
kbhit.py 文件源码 项目:overhead_mobile_tracker 作者: NU-MSR 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
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)
kbhit.py 文件源码 项目:overhead_mobile_tracker 作者: NU-MSR 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
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 != []
kbhit.py 文件源码 项目:overhead_mobile_tracker 作者: NU-MSR 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def flush(self):
        """
        flush stdin... untested on Windows"
        """
        if os.name == 'nt':
            while self.kbhit():
                self.getch()
        else:
            termios.tcflush(sys.stdin, termios.TCIOFLUSH)
        return


# Test
chipcon_usb.py 文件源码 项目:rfcat 作者: atlas0fd00m 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def keystop(delay=0):
    if os.name == 'posix':
        return len(select.select([sys.stdin],[],[],delay)[0])
    else:
        return msvcrt.kbhit()
kbhit.py 文件源码 项目:RobotControl 作者: vdwel 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
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)
kbhit.py 文件源码 项目:RobotControl 作者: vdwel 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
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
kbhit.py 文件源码 项目:speech_ml 作者: coopie 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
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)
kbhit.py 文件源码 项目:speech_ml 作者: coopie 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
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
inputhookpyglet.py 文件源码 项目:Repobot 作者: Desgard 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
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
inputhookglut.py 文件源码 项目:Repobot 作者: Desgard 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def stdin_ready():
        return msvcrt.kbhit()

#-----------------------------------------------------------------------------
# Callback functions
#-----------------------------------------------------------------------------
inputhook.py 文件源码 项目:Repobot 作者: Desgard 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def _stdin_ready_nt():
    """Return True if there's something to read on stdin (nt version)."""
    return msvcrt.kbhit()
_process_win32_controller.py 文件源码 项目:Repobot 作者: Desgard 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
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()
logserver.py 文件源码 项目:OWASP-ZSC-API 作者: viraintel 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def check_key():
    if msvcrt is None:
        return False
    else:
        if msvcrt.kbhit():
            q = ensure_unicode(msvcrt.getch())
            return q
    return ""


问题


面经


文章

微信
公众号

扫码关注公众号