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


Python msvcrt.getche函数代码示例

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


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

示例1: main

def main():
  time_start=time.time()
  ser = serial.Serial(1)  # open first serial port
  ser.baudrate =115200
  print (ser.name)          # check which port was really used
  try:
    sys.stderr.write('--- Miniterm on %s: %d,%s,%s,%s ---\n' % (
      ser.portstr,
      ser.baudrate,
      ser.bytesize,
      ser.parity,
      ser.stopbits,
    ))
  except serial.SerialException as e:
    sys.stderr.write("could not open port %r: %s\n" % (port, e))
    sys.exit(1)
  cmd_en = 0
  Packet_class = Packet()
  packet = list(range(0,200))
  log = open('log.log','w')
  ptr_packet = 0
  time_packet = time.time()
  count = 0 
  while 1:
    hello = ser.readline(ser.inWaiting())
    if (((time.time()-time_packet)>1.0)and cmd_en):
      cmd_en=0
    j=0
    while(j<len(hello)):
      if (hello[j] == '~'): 
        if (cmd_en == 0):
          time_packet = time.time()
          cmd_en = 1
          count = 0
          packet[count] = hello[j]
          count = 1
        else: 
          time_packet = time.time()
          packet[count] = hello[j]
          cmd_en = 0
          count += 1
          ptr_packet+=1
          log = open('log.log','a')
          packet_temp = char_to_int(packet,count)
          print(time.time()-time_start)
          log.write(str(time.time()-time_start)+'\t')  
          Packet_class.parser(packet_temp,count,ptr_packet)
          Packet_class.packet_print(log)
          log.close()
      elif (hello != '' and cmd_en == 1):
        packet[count] = hello[j]
    #    print_hex(char_to_int(hello,1),1)
        if (count == len(packet)-1): count =0
        else: count += 1  
      j+=1
    if m.kbhit() == 1:
      q = m.getche()
      if q == 'q':
        log.close()
        sys.exit(1)
开发者ID:shomagan,项目名称:cmd_py,代码行数:60,代码来源:RTMpaketParser.py

示例2: userinput_with_timeout_windows

    def userinput_with_timeout_windows(timeout, default=''):
        """Read user input. Return default value given after timeout.
           This function is used when running on windows-based systems.

          :param timeout: Number of seconds till timeout
          :param default: Default string to be returned after timeout
          :type default: String

          :returns: String

        """
        start_time = time.time()
        sys.stdout.flush()
        userinput = ''
        while True:
            if msvcrt.kbhit():
                readchar = msvcrt.getche()
                if ord(readchar) == 13:  # enter_key
                    break
                elif ord(readchar) >= 32:  # space_char
                    userinput += readchar
            if len(userinput) == 0 and (time.time() - start_time) > timeout:
                break
        if len(userinput) > 0:
            return userinput
        else:
            return default
开发者ID:biorack,项目名称:BASTet,代码行数:27,代码来源:omsi_web_helper.py

示例3: inline_menu

def inline_menu(reload = "None"):
    """ Test for in-line menu commands while waiting. """

    # enter timer loop
    # start_time = time.time()
    while True:

        # check for keyboard events
        if msvcrt.kbhit():
            key = msvcrt.getche()

            try:
                option = key.decode()
            except:
                option = ""

            # capture menu presses
            if option in ['E', 'e'] : email()
            if option in ['Q', 'q'] : sys.exit()
            if option in ['L', 'l'] : load_lusas(True)

            if reload == "Reload":
                if option in ['Y', 'y'] : return
                if option in ['N', 'n'] : sys.exit()

        # break timer
        if reload == "None":
            time.sleep(MEN_WAIT)
            break
开发者ID:thomasmichaelwallace,项目名称:challenger,代码行数:29,代码来源:challenger.py

示例4: getResponse

    def getResponse(self):

        try:
            if sys.stdin.isatty():
                return raw_input(">")
            else:
                if sys.platform[:3] == "win":
                    import msvcrt

                    msvcrt.putch(">")
                    key = msvcrt.getche()
                    msvcrt.putch("\n")
                    return key
                elif sys.platform[:5] == "linux":
                    print ">"
                    console = open("/dev/tty")
                    line = console.readline()[:-1]
                    return line
                else:
                    print "[pause]"
                    import time

                    time.sleep(5)
                    return "y"
        except:
            return "done"
开发者ID:fygrave,项目名称:wibat,代码行数:26,代码来源:wi.py

示例5: input_with_timeout

def input_with_timeout(timeout):
    if platform.system() == 'Windows':
        start_time = time.time()
        s = ''
        while True:
            while msvcrt.kbhit():
                c = msvcrt.getche()
                if ord(c) == 13: # enter_key
                    break
                elif ord(c) >= 32: #space_char
                    s += c
            if time.time() - start_time > timeout:
                return None

        return s
    else:
        while True:
            try:
                rlist, _, _ = select.select([sys.stdin], [], [], timeout)
                break
            except (OSError, select.error) as e:
                if e.args[0] != errno.EINTR:
                    raise e
        if rlist:
            return sys.stdin.readline()
        else:
            return None
开发者ID:zfn-ww,项目名称:frida-python,代码行数:27,代码来源:application.py

示例6: 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

示例7: CheckFiles

def CheckFiles(infilename, outfilename, forceoverwrite=False):
	print('Source file:  %s' % infilename)
	print('Destination file: %s' % outfilename)

	if not os.path.exists(infilename):
		print('Source file doesn\'t exist!')
		return False
	
	if os.path.exists(outfilename):
		if forceoverwrite:
			print('Destination file already exists!  Overwriting.' )
		else:
			print('Destination file already exists!  Overwrite the existing file? (y/n) ' )
			sys.stdout.flush()

			answer = msvcrt.getche()
			print('')
			if answer != b'y' :
				return False

		try:
			os.remove(outfilename);
		except:
			print('Error while trying to delete file: %s' % sys.exc_info()[1])
			return False

	return True
开发者ID:Bridenbecker,项目名称:EMOD,代码行数:27,代码来源:compiledemog.py

示例8: run

    def run(self):
        """

        """
        global _Server_Queue
        while True:  # What would cause this to stop? Only the program ending.
            line = ""
            while 1:
                char = msvcrt.getche()
                if char == "\r":  # enter
                    break

                elif char == "\x08":  # backspace
                    # Remove a character from the screen
                    msvcrt.putch(" ")
                    msvcrt.putch(char)

                    # Remove a character from the string
                    line = line[:-1]

                elif char in string.printable:
                    line += char

                time.sleep(0.01)

            try:
                _Server_Queue.put(line)
                if line != "":
                    _Logger.debug("Input from server console: %s" % line)
            except:
                pass
开发者ID:AbeDillon,项目名称:RenAdventure,代码行数:31,代码来源:Single_Port_server.py

示例9: inputLoop

def inputLoop():
    global userInput
    global sendThis
    global continueRunning
    while continueRunning:
        try:
            newChar = msvcrt.getche()   # get and echo whatever key the user pressed. #TODO: Disallow backspace, delete, etc.
            if newChar==chr(8): #backspace
                if len(userInput)>0: #if there is something to erase....
                    userInput = userInput[:-1]
                    sys.stdout.write(chr(0))
                    sys.stdout.write(chr(8)) 
            elif newChar=='\r': # is enter
                sys.stdout.write(chr(13)) # Bring to front
                for pos in range(len(userInput)):
                    sys.stdout.write(chr(0)) #Erase all chars written
                sys.stdout.write(chr(13)) # bring to front
                sys.stdout.write('\r') # enterrrr
                sendThis = userInput
                userInput = ''
            elif (ord(newChar)>=32 and ord(newChar)<=126): #alpha numerics
                userInput = userInput + newChar
            else:#  Erase the echo.
                sys.stdout.write(chr(8)) 
                sys.stdout.write(chr(0))
                sys.stdout.write(chr(8)) 
            newChar = ''
        except:
            'Input error.'
开发者ID:JGefroh,项目名称:imcs,代码行数:29,代码来源:chat_client.py

示例10: getkey

 def getkey():
     while 1:
         if echo:
             z = msvcrt.getche()
         else:
             z = msvcrt.getch()
         if z == '\0' or z == '\xe0':    #functions keys
             msvcrt.getch()
         else:
             return z
开发者ID:dlitz,项目名称:openmsp430,代码行数:10,代码来源:miniterm.py

示例11: getreply

def getreply():
	if sys.stdin.isatty():
		return sys.stdin.read(1)
	else:
		if sys.platform[:3] == 'win':
			import msvcrt
			msvcrt.putch(b'?')
			key = msvcrt.getche()
			return key
		else:
			return open('/dev/tty').readline()[:-1]
开发者ID:Ivicel,项目名称:pp4me,代码行数:11,代码来源:moreplus.py

示例12: getReply

def getReply():
        if sys.stdin.isatty():
                return input("?")
        if sys.platform[:3] == 'win':
                import msvcrt
                msvcrt.putch(b'?')
                key = msvcrt.getche()
                msvcrt.putch(b'\n')
                return key
        else:
                assert False, 'platform not supported'
开发者ID:wangmingzhitu,项目名称:tools,代码行数:11,代码来源:paging.py

示例13: readInput

def readInput( caption, default, timeout = 15):
    start_time = time.time()
    sys.stdout.write('%s[Default=%s]:'%(caption, default));
    print("")
    input = ''
    while True:
        if msvcrt.kbhit(): #kbhit functuion returns true if a key is hit
            chr = msvcrt.getche() #reads the key pressed on keyboard and stores it as chr
            if ord(chr) == 13: # enter_key
                break
            elif ord(chr) == 8: # backspace
                input = input[0:-1]
            elif ord(chr) == 224: #Special Characters like arrows, ins, delete, etc.
                chr = msvcrt.getche()
                if ord(chr) == 72: # Up Arrow
                    pass
                elif ord(chr) == 75: # Left Arrow
                    pass
                elif ord(chr) == 77: # Right Arrow
                    pass
                elif ord(chr) == 80: # Down Arrow
                    pass
                elif ord(chr) == 83: # Delete Key
                    pass
                else:
                    pass
                
            elif chr.isalnum(): #>= 32: #Any other characters
                input += chr
            elif chr == " ":
                input += chr
                
        print("\r"+" "*70+"\r" + input),
        if len(input) == 0 and (time.time() - start_time) > timeout:
            break

    print ''  # needed to move to next line
    if len(input) > 0:
        return input
    else:
        return default #this returns default value for weapon if the user can't select in the appropriate time.
开发者ID:dragongolfer,项目名称:OhSHIT,代码行数:41,代码来源:OhSHIT.py

示例14: getkey

 def getkey():
     while True:
         if echo:
             z = msvcrt.getche()
         else:
             z = msvcrt.getch()
         if z == "\0" or z == "\xe0":  # functions keys
             msvcrt.getch()
         else:
             if z == "\r":
                 return "\n"
             return z
开发者ID:robotota,项目名称:robotech.firmwares,代码行数:12,代码来源:miniterm.py

示例15: keyboardTimeOut

def keyboardTimeOut(timeout = 50):
    now = time.time()
    inp = ''
    chr = '\0'
    while True:
        if msvcrt.kbhit():
            chr = msvcrt.getche()
        if ord(chr) >= 32: #space_char
            inp += chr
            chr = '\0'
        if (time.time()-now)>(0.001*timeout):
            break
    return inp
开发者ID:fatadama,项目名称:python,代码行数:13,代码来源:readSerialSaveFile.py


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