/    Sign up×
Community /Pin to ProfileBookmark

if(e.keyCode == ?????)

When I pressed to F1 (or F2 or F3 ) key, Google home page will be opened. How can I do?

I found this page:
[url]http://www.mediaevent.de/javascript/needful_tables.html[/url]
F1 —- 112
F2 —- 123
F3 —– ???

[code]
<script type=”text/javascript”>

document.onkeydown= openPage ;

function openPage(e) {

e= window.event ? event : e;

if (e.keyCode == 112 ) { location.href=”http://www.google.com.tr” ; }

}

</script>
[/code]

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@KorJan 18.2007 — You can't. Functions keys (F1 --- F12) "belong" to the Operating System or to the application (browser) via the Operating System, so that, even if you may capture them a way or another, for most of them you can not change the default actions from within the web page). At least not with javascript.
Copy linkTweet thisAlerts:
@mrhooJan 18.2007 — The function keycodes are from 112(f1) to 123(f12).

Remember that some function keys have system or user defined behavior.

The only time I needed to hijack their events was in an app that I wrote to make a table of keyCodes and keyChars from the keyup, press and down events-

I didn't want to reload the page when I hit f5, or have any of the other behavior interupt my catching the codes. And even there I caught the key events from an input box and not the window.

An access key, like alt+'G' might be a safer choice. Or a link...
Copy linkTweet thisAlerts:
@RobDavidJan 18.2007 — 112 = F1

113 = F2

114 = F3

Because those are already brower/operating shortcuts you might get some window stuff going on too (help popup with F1 ?)
Copy linkTweet thisAlerts:
@felgallJan 18.2007 — Any keys that have predefined browser functions attached will not get passed to the web page at all. Since F1 is predefined as help web pages will never receive the 112 code because the browser will intercept the code and trigger the help function and then discard the keycode without passing it to the page. For a web page to see the keys that are pressed those keys must not have been assigned a use by either the operating system or browser.
×

Success!

Help @samanyolu spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.30,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...