To regain keyboard access to your machine to troubleshoot the fault and restore correct functionality, here are (2) options to get back into your machine:
Option 1: Wireless Keyboard
Buy a Wireless (USB) Keyboard which uses a USB dongle that looks like a USB Flash Drive that you can just insert into a USB port (or USB-C adapter) and it should "just work". This should enable you to regain the required access to troubleshoot the fault to restore normal keyboard functionality. A wireless Keyboard I like is:
Note: Although I initially suggested a Bluetooth keyboard in addition to the Wireless one, since it's not possible to "click" to add the Bluetooth device to your system this is a non-starter on a system broken in such a way as you describe.
Although I'm in Amsterdam at the mo' and unable to test it on my Macbook, I Googled and the k400 is Mac compatible. I actually use this one with Raspberry Pi's, but might need it when my own Macbook's keyboard craps-out ;-)
Option 2: Remote Access Via SSH (requires another computer)
When I’ve had issues with things like this in the past, I’ve gotten in remotely via SSH. If you can get into the machine via SSH, you can troubleshoot the fault as well as get files you require until the issue Is resolved. Could use a cheap £32 Raspberry Pi to get a terminal session going into the Mac with the broken keyboard.
This possible solution implies of course you’ve enabled the SSH access in your system preferences as below:
Given the problems with Apple's keyboards these past few years, I don't doubt others might be having similar issues.
Finally, I'd suggest storing docs in iCloud (DropBox is also really good, but with the codicile that it's not integrated into Apple's ecosphere like iCloud) so you can access your data if you keep having grief with your keyboard-