Revision: 18263
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at September 24, 2009 17:56 by marcocs
Initial Code
var arrShortCut = [{ name: 'test1', key: 15, fx: 'alert(1);' }, { name: 'test2', key: 90, fx: 'alert(2);'}];
var iShortCutControlKey = 17; // CTRL;
var bIsControlKeyActived = false;
$(document).keyup(function(e) {
if (e.which == iShortCutControlKey) bIsControlKeyActived = false;
}).keydown(function(e) {
if (e.which == iShortCutControlKey) bIsControlKeyActived = true;
if (bIsControlKeyActived == true) {
jQuery.each(arrShortCut, function(i) {
if (arrShortCut[i].key == e.which) {
execShortCut(arrShortCut[i].fx);
return;
}
});
}
});
function execShortCut(fx) {
eval(fx);
}
Initial URL
Initial Description
Una forma de vincular combinaciones de teclas con ejecución de codigo. se supone que tengamos un array (arrShortCut) que define lo siguiente: un nombre (solo para referencia) ; un codigo teclado (http://www.js-x.com/page/tutorials__key_codes.html) una función a ejecutar en la variable "iShortCutControlKey" definimos cual es la tecla de control (en este caso 17 CTRL) ; al keydown, si es la tecla control "activamos el estado"; al keyup, si es la tecla control "desactivamos el estado"; si se verifica un keydown de una tecla "no control" con "el estado activo" buscamos en el array si existe un preset para esa tecla; si existe llamamos la funcion "execShortCut" que ... ejecuta la función; Para probarlo solo pegar... CTRL+Z = alert(2)
Initial Title
Key Combination + Code Execution
Initial Tags
Initial Language
jQuery