PDA

Просмотр полной версии : создание горячих клавиш на JS


buka2
17.03.2006, 22:37
как сделать, чтобы при нажатии на определенную клавишу (комбинацию клавиш) запускалась конкретная функция?

KidsKilla
18.03.2006, 15:21
код с яндекса:

function init() {
if (self.parent.frames.length != 0) {
self.parent.location = document.location;
}
if (document.getElementById) {
document.onkeydown = register;
if (document.forms['web'].text) {
document.forms['web'].text.onfocus = function () {
searchInputIsActive = true;
if (document.forms['web'].text.select && CtrlUp) {document.forms['web'].text.select();}
};
document.forms['web'].text.onblur = function () {searchInputIsActive = false; CtrlUp = false;};
queryString = document.forms['web'].text.value;
}
}
}

function register(e) {
var code;
if (!e) var e = window.event;
if (e.keyCode) code = e.keyCode;
else if (e.which) code = e.which;


if ((code == 13) && (e.ctrlKey == true)) document.forms['web'].submit();

if (!searchInputIsActive) {
if ((code == 37) && (e.ctrlKey == true)) {
var destination = document.getElementById('previous_page');
if (destination) {
r(destination, 'stred/pid=1/cid=51');
location.href = destination.href;
}
}
if ((code == 39) && (e.ctrlKey == true)) {
var destination = document.getElementById('next_page');
if (destination) {
r(destination, 'stred/pid=1/cid=50');
location.href = destination.href;
}
}
}
if ((code == 38) && (e.ctrlKey == true) && document.forms['web'].text) {
CtrlUp = true;
r(location, 'stred/pid=1/cid=52');
document.forms['web'].text.focus();
}
}