How do I stop a “while loop” from getting and saving user inputs while it is looping?

Solution for How do I stop a “while loop” from getting and saving user inputs while it is looping?
is Given Below:

import time
t = 500
while t: # while t > 0 for clarity 
    try:
        # Timer
        mins = t // 60
        secs = t % 60
        timer="{:02d}:{:02d}".format(mins, secs)
        print(timer, end="r")
        time.sleep(1)
        t -= 1
    except KeyboardInterrupt:
        response = input("-- Press 'enter' to unpause 
                        n-- Type s to skip timer 
                        n-- Type e to close program 
                        nYour Response Here: ")

How to Replicate: While timer is running, specifically try block, press keyboard letter keys randomly. Ctrl+c to stop the loop and you’ll see the keys you pressed earlier.

Q: How do I stop a while loop from getting user inputs and transferring it to the next code block, specifically an input()

solution for windows : msvcrt

msvcrt.kbhit() 

Return True if a keypress is waiting to be read.

msvcrt.getch()

Read a keypress and return the resulting character as a byte string.
Nothing is echoed to the console.

This will clear:

import time
import msvcrt

t = 500
while t: # while t > 0 for clarity 
    try:
        # Timer
        mins = t // 60
        secs = t % 60
        timer="{:02d}:{:02d}".format(mins, secs)
        print(timer, end="r")
        time.sleep(1)
        t -= 1
    except KeyboardInterrupt:

        # clear 
        while msvcrt.kbhit():
            msvcrt.getch()

        response = input("-- Press 'enter' to unpause 
                        n-- Type s to skip timer 
                        n-- Type e to close program 
                        nYour Response Here: ")
        
        

Output:

enter image description here

On linux:

#! /usr/bin/env python3

import sys
import termios
import fcntl
import os
import time


def getchar():
    fd = sys.stdin.fileno()
    oldatribut = termios.tcgetattr(fd)
    newatribut = termios.tcgetattr(fd)
    newatribut[3] = newatribut[3] & ~termios.ICANON & ~termios.ECHO
    termios.tcsetattr(fd, termios.TCSANOW, newatribut)
    oldflags = fcntl.fcntl(fd, fcntl.F_GETFL)
    fcntl.fcntl(fd, fcntl.F_SETFL, oldflags | os.O_NONBLOCK)
    mychar = None
    try:
        mychar = sys.stdin.read(1)
    except IOError:
        pass
    termios.tcsetattr(fd, termios.TCSAFLUSH, oldatribut)
    fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)
    return mychar


keys: str = ""
t = 500
while t:  # while t > 0 for clarity
    try:
        # Timer
        mins = t // 60
        secs = t % 60
        timer="{:02d}:{:02d}".format(mins, secs)
        print(timer, end="r")
        key = getchar()
        if key:
            keys += key
        time.sleep(1)
        t -= 1
    except KeyboardInterrupt:
        # print(f"You have '{keys}' key pressed")
        response = input(f"-- Press 'enter' to unpause 
                        n-- Type s to skip timer 
                        n-- Type e to close program 
                        nYour Response Here: {keys}")
        break

This work in terminal, not in Pycharm etc.