Pressing a button on the keyboard

3

Hello,

Within the system I am developing the user can change a registry that is in the database. I would like to know how I can do that instead of the user being able to save the changes just by clicking on the "change" button he can do this by the shortcut "ctrl + s" on the keyboard.

Thank you.

    
asked by anonymous 28.08.2017 / 22:53

2 answers

-1

It also works on Mac:

document.addEventListener("keydown", function(e){
	if (e.keyCode == 83 && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)){
		e.preventDefault();
		alert("CTRL+S pressionado!");
	}
}, false);
Clique aqui e Pressione CTRL+S (para teste)
    
28.08.2017 / 23:00
1

Use Javascript.

  • First recognize which command you want to use.
  • Then define a function that will insert this shortcut.
  • Finally, call up the desired function.

In this example: Shortcut: (Alt + 'a')

document.onkeyup=function(e){
  var e = e || window.event; // for IE to cover IEs window event-object
  if(e.altKey && e.which == 65) {
    //Chama sua função JS aqui
  }
}

In this website you can pick up which code for each key you want.

    
28.08.2017 / 23:00