Working version of key press parsing function