How to make my code shorter. This Code formats Credit card number. Vanilla JS
I've mainly got three points:

The whole thing should be wrapped in a function with the reference to the input element passed in. Currently it is hard coded to (only) apply to the first input on the page, which doesn't seem like a practical scenerio.

Instead of using the deprecated/non-standard keyCode and which, you should be using key. And if you do use keyCode you should define all code numbers as constants.

Unless I'm missing some side-effect, the use of parseInt on inpVal.length is pointless.