Keyboard macros: Difference between revisions

Content added Content deleted
({{omit from|PARI/GP}})
(→‎{{header|JavaScript}}: Fix assertion regarding returning value from event)
Line 127: Line 127:
</lang>
</lang>
=={{header|JavaScript}}==
=={{header|JavaScript}}==
The example below captures the F7 key when pressed, if the document (that is, the web page) has focus. If the function returns ''false'', the event processing is halted. If it returns ''true'', the event continues up the DOM tree ('bubbling').
The example below captures the F7 key when pressed, if the document (that is, the web page) has focus. If the function returns ''false'', the event processing is halted. If it returns any other value, including ''undefined'', the event continues up the DOM tree ('bubbling').


<lang javascript>document.onkeydown = function(ev) {
<lang javascript>document.onkeydown = function(evt) {
if (ev.keyCode == 118) {
if (evt.keyCode === 118) {
alert("You pressed F7!");
alert("You pressed F7!");
return false;
return false;
} else {
return true;
}
}
}</lang>
}</lang>