Python Forum
Looping Input form / results
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Looping Input form / results
#2
Infinite loop is usually done with while True:

Capturing a specific key (as opposed to input terminated by the enter key) is tricky in standard console based Python, and varies from platform to platform.

This will work on many systems, but does not catch ctrl alone (usually a modifier key) but I'm sure there is more to termios that would allow you to address that.

import sys, termios, tty

stdinFileDesc = sys.stdin.fileno() #store stdin's file descriptor
oldStdinTtyAttr = termios.tcgetattr(stdinFileDesc) #save stdin's tty attributes so I can reset it later

try:
    print('Press any key to exit...')
    tty.setraw(stdinFileDesc) #set the input mode of stdin so that it gets added to char by char rather than line by line
    sys.stdin.read(1) #read 1 byte from stdin (indicating that a key has been pressed)
finally:
    termios.tcsetattr(stdinFileDesc, termios.TCSADRAIN, oldStdinTtyAttr) #reset stdin to its normal behavior
    print('Goodbye!')
I am trying to help you, really, even if it doesn't always seem that way
Reply


Messages In This Thread
Looping Input form / results - by MikeAW2010 - Jan-16-2018, 06:50 AM
RE: Looping Input form / results - by gruntfutuk - Jan-16-2018, 11:36 AM
RE: Looping Input form / results - by MikeAW2010 - Jan-16-2018, 06:02 PM
RE: Looping Input form / results - by Gribouillis - Jan-16-2018, 06:07 PM
RE: Looping Input form / results - by MikeAW2010 - Jan-16-2018, 09:39 PM
RE: Looping Input form / results - by Gribouillis - Jan-16-2018, 10:10 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  pyscript index error while calling input from html form pyscript_dude 2 1,160 May-21-2023, 08:17 AM
Last Post: snippsat
  Form Results onto Page StewartLFI 3 125,141 Sep-18-2021, 05:00 AM
Last Post: ndc85430
  Search Results Web results Printing the number of days in a given month and year afefDXCTN 1 2,367 Aug-21-2020, 12:20 PM
Last Post: DeaD_EyE
  How to append one function1 results to function2 results SriRajesh 5 3,367 Jan-02-2020, 12:11 PM
Last Post: Killertjuh
  Trying to send input from html form to database SQLite3 RonnyGiezen 3 96,083 Dec-21-2019, 02:09 PM
Last Post: ibreeden
  Need Help with input from Web form amitjain78 3 2,162 Sep-03-2019, 10:13 AM
Last Post: snippsat
  How to keep looping until the user input is valid ? KyawMyo 12 6,545 Jun-10-2019, 02:51 AM
Last Post: KyawMyo
  [Help] Using "Class" with User Input in an online sign up form vanicci 8 6,932 Aug-29-2018, 10:52 AM
Last Post: vanicci

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020