1

I'm trying to listen to keyboard events in contenteditable and apply the same events to an input element (or applying e.keyCode to an input). I've tried this. Element.dispatchEvent will only trigger event listeners but don't seem to change the input value.

But it doesnt update the input value. I don't want to rely on manually modifying the input.value because i need to account for things like backspace.

contentEditableDiv.addEventListener('keydown', e => {
  inputElement.dispatchEvent(e);
});

Reason why i need this: When user enters a hotkey, i show a context menu so the user can continue typing and i can filter the list, i want to throw all those events into an input so that i can use the input value to filter through my list.

goldensausage
  • 229
  • 1
  • 2
  • 11

1 Answers1

-2

try this

document.onkeypress = (e) => console.log(e)

enter image description here

Slava Rozhnev
  • 9,510
  • 6
  • 23
  • 39