What piece of script would I need to restrict certain keys from being pressed?

I’m currently in the process of creating a 2d sidescroller, and I find that my character falls off my 2d plane very often if I push either the W or the S key. Is there any piece of code that can restrict these keys from being pushed, or any help to solve why my characters are falling off the edge?

Problem solved. For some reason my box colliders were connecting and causing my player to phase through blocks. All good now!