If an external keyboard & mouse have the same issue, then either you have a software/configuration issue, or a hardware failure with the laptop (most likely the Logic Board, but a slim chance the built-in keyboard). Try disconnecting the built-in keyboard to see if the external USB keyboard & mouse work properly now. Maybe even try disconnecting the built-in trackpad as well.
See if you can use the external USB keyboard to reset the PRAM.
Also try booting into Safe Mode which disables third party software from launching automatically during boot & login.
Disconnect all other external devices in case one of them is causing a problem.
Try booting into Internet Recovery Mode using Command + Option + R to see how the keyboard works. You may need to launch the Terminal app from the Utilities menu since I'm not sure anything else will allow you to type anything, but do not press the "Return" key so as not to trigger any commands accidentally. You can try launching a simple command line text editor from the command line by using the following command (followed by pressing the "Return" key to submit the command), although I'm not sure if this text editor is available from the macOS installer, but it is worth a try so as not to accidentally run a command while testing the keys. If it launches the text editor, then you can press Control + X to exit the editor, followed by pressing "N" for no when prompted to save the text.
nano
You can try running the Apple Diagnostics to see if any hardware issues are detected. The only useful diagnostic is one which produces an error or freezes during testing.