how to record keyboard press in python code example

Example 1: python check key press

import keyboard
# if key 'a' is pressed 
if keyboard.is_pressed('a'):
	print('a key has ben pressed')

Example 2: python get key module

import getkey, os
def clear():
  if os.name == "nt":
    _ = os.system('cls') #Clear function
  else:
    _ = os.system('clear')
current = "" 
while True:
  clear() #Clearing, required at beginning at end in order for algorithm to work
  print(current)
  key = getkey.key() # Gets the key
  if key == getkey.keys.BACKSPACE: # Detects if key is backspace
    current = current[:-1]
  elif key == getkey.keys.ENTER: # Detecs if key is the enter(return) key
    break
  else:
    current = current + key # Otherwise, adds on the the current variable
  clear()
clear()
print("\n\n\n You typed: " + current)