I don't really understand your code. You have so many events for such basic task. And half of these events are running on every tick, which is not great for performance..
Why don't you simply check if player is overlapping an obstacle at offset?
Say, you have a tilemap of obstacles, you can do this:
On A pressed
Player is NOT overlapping Tilemap at offset x=-16
player move left
On D pressed
Player is NOT overlapping Tilemap at offset x=16
player move right
etc.