First i will recommend you to run a PSA test.
This is done by, turning on the computer, and press "F12" under POST.
Then you'll get a boot menu, where you can choose, "Diagnostic"
This will test most of your hardware for errors.
Does it only shut down while typing?
Maybe try reseat the keyboard.