0

I want to display Hello when I press the F1 key.

shortcut.add("F1",function(){
      alert("Hello");
});

But the problem is when I pressed F1 it brought me to a new tab. Is there any way to disable this default feature? but I'm not really sure about this code if it's working on F1 keypress. Can anyone help me? thanks in advance.

Jesper Martinez
  • 611
  • 5
  • 15

1 Answers1

1

You need to subscribe on keyup event and check event code. Therefore, onkeydown/up keyCode always holds the key code. onkeypress you can find the actual character the user typed by evt.charCode || evt.keyCode. https://javascript.info/keyboard-events

Andrii Gordiichuk
  • 1,783
  • 1
  • 12
  • 10