Push a button through the keyboard

Asked

Viewed 956 times

3

Hello,

within the system I am developing the user can change a registration that is in the database. I wonder how I can do so that instead of the user can save the changes just by clicking on the "change" button he can do it by the shortcut "Ctrl+s" on the keyboard.

Thank you.

2 answers

1

Use Javascript.

  • First recognize which command you want to use.
  • Then set a Function that will insert this shortcut.
  • Finally, call 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 which code for each desired key.

-1


Works also 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)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.