• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python msvcrt.getche函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: getreply

def getreply():
    if sys.stdin.isatty():
        return raw_input("?")
    else:
        if sys.platform[:3] == "lin":
            import msvcrt

            msvcrt.putch(b"?")
            key = msvcrt.getche()
            msvcrt.putch(b"\n")
            return key
        else:
            assert False, "platform not supported"
开发者ID:theo-l,项目名称:.blog,代码行数:13,代码来源:moreplus.py


示例17: poll

 def poll(self):
   """Poll for data on msvcrt (Windows only)"""
   completeLineRead = False
   while msvcrt.kbhit():
     nextChar = msvcrt.getche()
     if nextChar == "\r":
       completeLineRead = True
       print("")
       break
     self.inputLine += nextChar
   if completeLineRead:
     self.processBuffer(self.inputLine)
     self.inputLine = ""
开发者ID:Stefan-Korner,项目名称:SpacePyLibrary,代码行数:13,代码来源:TASK.py


示例18: raw_input_with_timeout

	def raw_input_with_timeout(prompt,t,ch):
		print "--->"+prompt   
		finishat = time.time() + t 
		result = []
		while True:
			if msvcrt.kbhit():
				result.append(msvcrt.getche())
				if result[-1] == '\r':   # or \n, whatever Win returns;-)
					return ''.join(result)
				time.sleep(0.1)          # just to yield to other processes/threads
			else:
				if time.time() > finishat:
					return ch
开发者ID:RobertCNelson,项目名称:boot-scripts,代码行数:13,代码来源:control.py


示例19: getreply

def getreply():
    '''
    读取交互式用户的回复键,即使stdin重定向到某个文件或者管道
    '''
    if sys.stdin.isatty():
        return input('?')       # 如果stdin 是控制台 从stdin 读取回复行数据
    else :
        if sys.platform[:3]  == 'win':   # 如果stdin 重定向,不能用于询问用户
            import msvcrt
            msvcrt.putch(b'?')
            key = msvcrt.getche()        # 使用windows 控制台工具 getch()方法不能回应键
            return key
        else:
            assert False,'platform not supported'
开发者ID:PythonStudy,项目名称:CorePython,代码行数:14,代码来源:moreplus.py


示例20: escapableSleep

def escapableSleep(timeout,verbose=True):
	start_time = time.time()
	if verbose: sys.stdout.write("Waiting %d s (press Q to cancel)"%(timeout))
	userStop = False
	while True:
		if msvcrt.kbhit():
			chr = msvcrt.getche()
			if ord(chr) == 113: # q_key
				userStop = True
				break
		if (time.time() - start_time) > timeout:
			break
	print ''  # needed to move to next line
	return userStop
开发者ID:mv20100,项目名称:phd_code_characterization,代码行数:14,代码来源:timeout.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python msvcrt.getwch函数代码示例发布时间:2022-05-27
下一篇:
Python msvcrt.getch函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap