keyboard https://github.com/boppreh/keyboard を使います。
上のリンクと下のコードだけでわかると思いますが、需要があれば解説を足します。
pip install keyboard
python -m keyboard
実行例
{"event_type": "down", "scan_code": 16, "name": "q", "time": 1646975615.8746192, "is_keypad": false}
q{"event_type": "up", "scan_code": 16, "name": "q", "time": 1646975615.9862385, "is_keypad": false}
{"event_type": "down", "scan_code": 42, "name": "shift", "time": 1646975617.9866295, "is_keypad": false}
{"event_type": "up", "scan_code": 42, "name": "shift", "time": 1646975618.059266, "is_keypad": false}
{"event_type": "down", "scan_code": 54, "name": "right shift", "time": 1646975621.0223727, "is_keypad": false}
{"event_type": "up", "scan_code": 54, "name": "right shift", "time": 1646975621.0913706, "is_keypad": false}
{"event_type": "down", "scan_code": 29, "name": "right ctrl", "time": 1646975624.3792064, "is_keypad": false}
{"event_type": "up", "scan_code": 29, "name": "right ctrl", "time": 1646975624.4272087, "is_keypad": false}
{"event_type": "down", "scan_code": 28, "name": "enter", "time": 1646975626.379538, "is_keypad": false}
最後の Enter で抜けています。