Simulate keypress from javascript/jquery

Hi, I’ve tried to look for something similar here in the forum but not able to find.

I have a “fight game”, but the idea is to use external controls , such as API events etc.

So I have connected the “Enter” key to an animation, and now am trying to trigger that keypress via javascript but unable to.

So far I’ve tried to use this:
$.event.trigger({ type: ‘keydown’, which: 13 }); // 13 = “Enter”

I have made sure the window is focused, and also tested to manually hit Enter, which works fine. It’s just when I try to send the “Enter” keypress via javascript that I don’t get any response.

NOTE:
In previous edits I thought it was because I tried to reach and simulate from outside an iframe. Unfortunately that wasn’t the case.