当前位置: 首页>>代码示例>>Python>>正文


Python msvcrt.kbhit函数代码示例

本文整理汇总了Python中msvcrt.kbhit函数的典型用法代码示例。如果您正苦于以下问题:Python kbhit函数的具体用法?Python kbhit怎么用?Python kbhit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了kbhit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

def main(channel = 'Z'):
    ##channel = 'X' # This can be 'X' or 'Y' or 'Z' channels
    min_position = -4 # mm
    max_position = 12.2 # m
    rate = 0.5 # number of points written per second to the stage
    density = 2 # number of points across the full scale range
    wait =  6 # Wait time before sweeping back in seconds

    x_mm_array_f = numpy.linspace(min_position,max_position,density)
    x_mm_array_b = numpy.linspace(max_position,min_position,density)
    xps = qt.instruments['xps']

    while 1:
        if (msvcrt.kbhit() and (msvcrt.getch() == 'q')): break
        print 'Sweeping %s forward...' % channel
        for i in x_mm_array_f:
            xps.set('abs_position%s' % channel, i)
            time.sleep(1.0/rate)
        time.sleep(wait)
        if (msvcrt.kbhit() and (msvcrt.getch() == 'q')): break
        print 'Sweeping %s backward...' % channel
        for i in x_mm_array_b:
            xps.set('abs_position%s' % channel, i)
            time.sleep(1.0/rate)
        time.sleep(wait)


    f_string = 'set_abs_position' + channel
    # Create function that corresponds to the abs_position set function of
    # the correct channel, then call it to reset the voltage to 0.
    reset_channel = getattr(xps, f_string)
    reset_channel(0.0)
    return
开发者ID:berkdiler,项目名称:measurement,代码行数:33,代码来源:xps_back_and_forth.py

示例2: player

def player(sm, sprite, fb, global_frame_number: int):
    fb_width = len(fb[0])
    fb_height = len(fb)
    # Reduce invincibility frames TODO checks if attribute exists or better, make invincibility more generic
    if sprite.info['invincibility'] > 0:
        sprite.info['invincibility'] -= 1
    # Player movement
    if msvcrt.kbhit():
        x = sprite.info['x']
        y = sprite.info['y']
        parsed_chars = set()
        while msvcrt.kbhit():
            input_char = msvcrt.getch()
            input_int = struct.unpack('B', input_char)[0]
            if input_int in parsed_chars:
                continue
            parsed_chars.add(input_int)
            if input_char == b'w':
                sprite.info['y'] = max(0, y - 2)
            if input_char == b's':
                sprite.info['y'] = min(fb_height - sprite.info['height'], y + 2)
            if input_char == b'a':
                sprite.info['x'] = max(0, x - 3)
            if input_char == b'd':
                sprite.info['x'] = min(fb_width - sprite.info['width'], x + 3)
            if input_char == b'\x1b':
                # See game loop for details
                sprite.info['ai_quit_to_main_menu'] = True
    # Player is shooting every 10 frames
    sprite.info['ai_last_move'] += 1
    if sprite.info['ai_last_move'] > 3:
        sm.add_sprite('projectile_p_big', sprite.info['x'] + sprite.info['width'], sprite.info['y'])
        sprite.info['ai_last_move'] = 0
开发者ID:0xFAIL,项目名称:lantern,代码行数:33,代码来源:ai.py

示例3: alarm

def alarm(hours, minutes, seconds):
    time.sleep(abs(hours * 3600 + minutes * 60 + seconds))
    while msvcrt.kbhit():
        msvcrt.getch()
    while not msvcrt.kbhit():
        winsound.Beep(440, 250)
        time.sleep(0.25)
开发者ID:bhramoss,项目名称:code,代码行数:7,代码来源:recipe-510390.py

示例4: get_ui_to

def get_ui_to(prompt, toSec=None, tSleepSec=None):
  # import sys
  from time import time, sleep
  from msvcrt import getch, getche, kbhit

  if toSec==None: # wait forever
    userKey = raw_input(prompt)
    return userKey

  tElapsed = 0
  t0 = time()
  if tSleepSec == None:
    tSleep = 0.1*toSec
  else:
    tSleep = tSleepSec
  while True:
    if tElapsed > toSec:
      print "Timeout after tElapsed secs...%.3f"%tElapsed
      userKey = ''
      break
    print "\n", prompt,
    if kbhit():
      userKey = getche()
      while kbhit(): # flush input
        getch() # sys.stdin.flush()
      # userKey = raw_input(prompt)
      break
    # print "sleep tSleep secs...%.3f"%tSleep
    sleep(tSleep)
    tNow = time()
    tElapsed = tNow - t0

  return userKey
开发者ID:Agueeva,项目名称:bert100,代码行数:33,代码来源:labutils.py

示例5: update

def update():
    global bx, by, vx, vy, p1, p2, score, paused
    if msvcrt.kbhit():
        k = msvcrt.getch()
        if msvcrt.kbhit():
            k += msvcrt.getch()
        if k == b'\xe0K' and not paused:
            p1 -= 2
        elif k == b'\xe0M' and not paused:
            p1 += 2
        elif k == b'p':
            paused = not paused
        elif k in (b'\x1b', b'q'):
            return QUIT
    if paused:
        return CONT
    p1 = max(4, min(W-5, p1))
    p2 = max(4, min(W-5, bx))
    bx += vx
    by += vy
    if bx == 0 or bx == W-1:
        vx = -vx
    if by == 1 and abs(bx - p2) < 5:
        vy = -vy
    if by == H-2 and abs(bx - p1) < 5:
        vy = -vy
        score += 1
    if by < 0:
        return WIN
    if by >= H:
        return LOSE
    return CONT
开发者ID:rmccampbell,项目名称:PythonProjects,代码行数:32,代码来源:pong.py

示例6: main

def main():
    channel = 'X' # This can be 'X' or 'Y' channels
    min_position = -10 # Volts
    max_position = 10 # Volts
    rate = 100 # number of points written per second to DAQ
    density = 100 # number of points across the full scale range
    wait = 1 # Wait time before sweeping back in seconds

    x_V_array_f = numpy.linspace(min_position,max_position,density)
    x_V_array_b = numpy.linspace(max_position,min_position,density)
    fsm = qt.instruments['fsm']

    while 1:
        if (msvcrt.kbhit() and (msvcrt.getch() == 'q')): break
        print 'Sweeping %s forward...' % channel
        fsm.simple_sweep_V(x_V_array_f,rate,channel)
        time.sleep(wait)
        if (msvcrt.kbhit() and (msvcrt.getch() == 'q')): break
        print 'Sweeping %s backward...' % channel
        fsm.simple_sweep_V(x_V_array_b,rate,channel)
        time.sleep(wait)


    f_string = 'set_abs_position' + channel
    # Create function that corresponds to the abs_position set function of
    # the correct channel, then call it to reset the voltage to 0.
    reset_channel = getattr(fsm, f_string)
    reset_channel(0.0)
    return
开发者ID:liuche,项目名称:qtlab,代码行数:29,代码来源:fsm_back_and_forth.py

示例7: ingreso_rapido

def ingreso_rapido():
    print "Ingrese el numero de la carta: "
    cr = 0
    while True:
        if kbhit():
            n = getch()
            if (n.isdigit() == False) or (int(n) < 1) or (int(n) > 12):
                print "Numero ingresado incorrecto"
            else:
                n2 = int(n)
                if (cr == 0) and (n2 == 1):
                    tt = n2
                    cr = 1
                elif (cr == 1) and (n2 == 1):
                    n2 += tt
                    break
                else:
                    break
                n = str(n2)
    print "Ingrese el palo de la carta: "
    while True:
        if kbhit():
            palo = getch()
            if palo not in ['c', 'o', 'e', 'b']:
                print "Palo ingresado incorrecto"
            else:
                break
    return n+palo
开发者ID:ErmantrautJoel,项目名称:Python,代码行数:28,代码来源:Ingreso+rapido.py

示例8: getKey

def getKey():
    import msvcrt
    if msvcrt.kbhit():
        msvcrt.getch()
    while (1):
        if msvcrt.kbhit():
            msvcrt.getch()
            break
开发者ID:BackupTheBerlios,项目名称:pws,代码行数:8,代码来源:Interface.py

示例9: recalibrate_lt2_lasers

def recalibrate_lt2_lasers(names=['MatisseAOM', 'NewfocusAOM', 'GreenAOM', 'YellowAOM'], awg_names=['NewfocusAOM']):
    turn_off_all_lt2_lasers()
    for n in names:
        if (msvcrt.kbhit() and (msvcrt.getch() == 'q')): break
        recalibrate_laser(n, 'PMServo', 'adwin')
    for n in awg_names:
        if (msvcrt.kbhit() and (msvcrt.getch() == 'q')): break
        recalibrate_laser(n, 'PMServo', 'adwin',awg=True)
开发者ID:AdriaanRol,项目名称:measurement,代码行数:8,代码来源:stools.py

示例10: recalibrate_lasers

def recalibrate_lasers(names = ADWINAOMS, awg_names = AWGAOMS):    
    turn_off_all_lasers()
    for n in names:
        if (msvcrt.kbhit() and (msvcrt.getch() == 'q')): break
        stools.recalibrate_laser(n, PMSERVO, ADWIN)
    
    for n in awg_names:
        if (msvcrt.kbhit() and (msvcrt.getch() == 'q')): break
        stools.recalibrate_laser(n, PMSERVO, ADWIN, awg=True)
开发者ID:AdriaanRol,项目名称:measurement,代码行数:9,代码来源:stools.py

示例11: run

 def run(self):
     this_char = ''
     while this_char != self.exit_criteria:
         # print("waiting for", self.exit_criteria)
         msvcrt.kbhit() # waits for the keyboard hit
         this_char = msvcrt.getwch() # eats the character just hit
         if this_char == self.exit_criteria:
             self.trigger_all_events()
         else:
             print("waiting for '%s' : got '%s'" % (str(self.exit_criteria), this_char))
开发者ID:takluyver,项目名称:latus,代码行数:10,代码来源:exitcontrol.py

示例12: __call__

 def __call__(self):
   import msvcrt
   if msvcrt.kbhit():
     while msvcrt.kbhit():
       ch = msvcrt.getch()
     while ch in b'\x00\xe0':
       msvcrt.getch()
       ch = msvcrt.getch()
     return ord( ch.decode() )
   else:
     return -1
开发者ID:Blackladder,项目名称:ELSYS-Prosjekt,代码行数:11,代码来源:gameTest.py

示例13: ascii_challenge

def ascii_challenge(stop):
    '''
    separate image_to_ascii function to have guessing game.
    image_folder: where the images are stored
    (All images need to have 3-letter formats a.k.a. .jpegs won't work)
    img: string from stop.attrs
    img_txt: possible text string that would've already been generated
    '''
    global rhymes
    global ats
    play_music(stop,True) #pauses music
    image_folder = os.listdir('images/')
    img = str(stop.attrs["im"]).strip(string.whitespace)
    img_txt = img[:-4]+'.txt'
    logging.debug("Image Text:",img_txt) #log image text for debugging
    play_music(stop)
    boss = str(stop.attrs["kw"]).strip(string.whitespace)
    if img_txt not in image_folder: #convert image to txt file if not already.
        print "Converting jpg to txt!"
        ascii_string = ASC.image_diff('images/'+img)
        fin = open('images/'+img_txt,'w')
        print "file opened"
        for i in range(len(ascii_string)):
            fin.write(ascii_string[i]+'\t')
        fin.close()
    with open('images/'+img_txt) as f:
        lines = f.read()
        print "Guess ascii by pressing enter!"
        for l in lines.split('\t'):
            while not msvcrt.kbhit():
                time.sleep(1.2)
                print l
                break

            while msvcrt.kbhit():
                play_music(stop,True)
                msvcrt.getch()
                print "_________________________________________________________________"
                print "What's your guess?"
                print boss
                boss_guess = raw_input(">>")
                if boss_guess[:2] == boss[:2]:
                    play_music(stop)
                    print "You guessed right! Here are 5 hashes and ats for your prowess!"
                    rhymes += 5
                    ats += 5
                    return rhymes, ats
                else:
                    print "You guessed wrong!"
                    play_music(stop)
    return rhymes,ats
开发者ID:q2nev,项目名称:MixMaster,代码行数:51,代码来源:game_play.py

示例14: countdown

def countdown(timeout):
    '''A countdown function, asking for a keypress.
    It returns whether a key was pressed during countdown or not.
    Works on both linux on windows. Timeout in seconds.'''
    sys.stdout.write("Press any key to abort... %02d" % (timeout))
    sys.stdout.flush()
    keypressed = False
    try:
        # Windows
        import msvcrt
        while not msvcrt.kbhit() or timeout == 0:
            time.sleep(1)
            timeout = timeout - 1
            sys.stdout.write("\b"*len("%02d"%(timeout+1)) + "%02d"%(timeout))
            sys.stdout.flush()
        if msvcrt.kbhit():
            keypressed = True
    except:
        # Linux
        try:
            import termios, select
            fd = sys.stdin.fileno()
            new_term = termios.tcgetattr(fd)
            old_term = termios.tcgetattr(fd)
            # new terminal setting unbuffered
            new_term[3] = (new_term[3] & ~termios.ICANON & ~termios.ECHO)
            # switch to unbuffered terminal
            termios.tcsetattr(fd, termios.TCSAFLUSH, new_term)

            dr, _, _ = select.select([sys.stdin], [], [], 0)
            while dr == [] and timeout > 0:
                time.sleep(1)
                timeout = timeout - 1
                sys.stdout.write("\b"*len("%02d"%(timeout+1)) + "%02d"%(timeout))
                sys.stdout.flush()
                dr, _, _ = select.select([sys.stdin], [], [], 0)

            if dr != []:
                keypressed = True
        finally:
            try:
                # switch to normal terminal
                termios.tcsetattr(fd, termios.TCSAFLUSH, old_term)
            except:
                sys.stdout.write("\nAttention: Terminal unacessable. If SGpp was built within Eclipse, everything is fine!\n")
                sys.stdout.flush()
                return keypressed

    sys.stdout.write("\n")
    sys.stdout.flush()
    return keypressed
开发者ID:ABAtanasov,项目名称:Sparse-Grids,代码行数:51,代码来源:toolsKbhitCountdown.py

示例15: image_to_ascii

def image_to_ascii(stop):
    '''
    separate image_to_ascii function to have guessing game.
    image_folder: where the images are stored
    img:
    img_txt: possible text string that would've already been generated
    '''
    global hashes
    global ats
    image_folder = os.listdir('images/')
    img= str(stop.attrs["im"]).strip(string.whitespace)
    img_txt = img[:-4]+'.txt'

    play_music(stop)
    boss_kw = str(stop.attrs["nomen"]).strip(string.whitespace)
    if img_txt in image_folder:
        with open('images/'+img_txt) as f:
            lines = f.read()
            print "Guess ascii by pressing enter!"

            for l in lines.split('\t'):

                while not msvcrt.kbhit():
                    time.sleep(1.5)
                    break
                print l

                while msvcrt.kbhit():
                    msvcrt.getch()
                    play_music(stop,False)
                    print "-----------------------------------------------"
                    print "What's your guess?"
                    boss_guess = raw_input(">>")

                    if boss_guess == boss_kw:
                        print "You guessed right! Here are 5 hashes and ats for your prowess!"
                        hashes += 5
                        ats += 5

                        break
    else:
        #try:
        ascii_string = ASC.image_diff('images/'+img)
        print type(ascii_string)
        fin = open('../images/'+img_txt,'w')
        print "file opened"
        for i in range(len(ascii_string)):
            fin.write(ascii_string[i]+'\t')
        fin.close()
开发者ID:q2nev,项目名称:PusherMan,代码行数:49,代码来源:game_play2.py


注:本文中的msvcrt.kbhit函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。