Reputation: 7212
Having a single KeyboardEvent object, is it possible to know if it corresponds to a KeyDown or KeyUp event? (I know I can keep somewhere the event KeyUp or Down that triggers it but I am looking for a way to assess that independently of the trigger)
Upvotes: 1
Views: 160
Reputation: 4387
Look at the type
property on the object you've got:
let b = document.getElementById('b');
b.onkeydown = b.onkeyup = function(e){ console.log(e.type); };
<button id="b">Button</button>
Upvotes: 1