You have not escaped the second single quote after the number 4.
Try this: client.println("document.body.addEventListener(\'keydown\', (e) =>{if(e.key==\'a\'||e.key==\'4\'){window.location.href=\"/left\"\";}})</script>");
That's all I can say; as I mentioned in our private exchange, I have no interest in jscript.
I'll alert this post to the moderators to ask them to move it to a more appropriate place on this forum, as this doesn't look like a covid-19 response issue.
Also, please give that link I sent you another very thorough read as you've only posted a snippet of your full code, making it impossible for people to help you in a constructive way.
The code you posted is essentially how it is done. The arduino code does not know that there is JavaScript or html inside the strings that are printed, they are just strings. When your browser receives the page, it executes the html/JavaScript.
A better/more detailed description of what goes wrong would be beneficial.
Btw, since it seems to be a specific JavaScript problem, this forum may not be the best place to get help.
Have you tried just hardcoding the jScript code in a file and running that in your browser directly? I'd start from there, get it to work, and then parse it into your C/C++ Arduino code. Keep in mind the escape character issue I pointed out earlier.
Like I said, look at the source code of that page in your browser. The error on the right hand side suggests you may indeed have an escape character problem as I've mentioned several times.