Javascript event check if events were triggered by the same user action

I want to check if two different events were triggered by the same user action.
For example, I have a “keydown” event listener and a “beforeinput” event listener with an editable div.
Is there a way I can check if both events were triggered by the same key press?
I know I could do it in a hacky way checking the time between the events, but is there a reliable/deterministic way to know if the events were triggered by the same input from the user?

If not a specific property, is there maybe a more reliable way to increment an id number after each event loop or push a callback to the end of the stack after the event loop to know the events on the stack would have all needed to be added at the same time by the same user input before the user would have been able to press another key or do another action?