Introduction
Last day when I saw a banking website that supports the function keys I thought to write an article on this topic. I don't know what platform they (the bank) are using but I thought to write it in ASP.NET.
I am going to consume the jQuery methods to make it possible. So, use the following steps to create this application.
Step 1:
Add reference to the jQuery file in the head section of the page, for example:
<script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script>
Step 2:
Add the following jQuery method in the head section of the page.
<script type="text/javascript">
$(function () {
$(document).keyup(function (e) {
var key = (e.keyCode ? e.keyCode : e.charCode);
switch (key) {
case 112:
navigateUrl($('a[id$=lnk1]'));
break;
case 113:
navigateUrl($('a[id$=lnk2]'));
break;
case 114:
navigateUrl($('a[id$=lnk3]'));
break;
default: ;
}
});
function navigateUrl(jObj) {
window.location.href = $(jObj).attr("href");
}
});
</script>
Step 3:
Here is the list of function keys and their key codes:
|
Function key |
Key code |
|
F1 |
112 |
|
F2 |
113 |
|
F3 |
114 |
|
F4 |
115 |
|
F5 |
116 |
|
F6 |
117 |
|
F7 |
118 |
|
F8 |
119 |
|
F9 |
120 |
|
F10 |
This key is reserved by the system and cannot be used |
|
F11 |
122 |
|
F12 |
123 |
|
F13 |
124 |
|
F14 |
125 |
|
F15 |
126 |
Step 4:
Design the page body as given below:
<p>
Press
<b>F1 for My Blog Page</b>
<br />
<b>F2 for My ASP.NET Posts Page</b>
<br />
<b>F3 for About Me Page</b>
</p>
<div>
<asp:HyperLink ID="lnk1" runat="server" NavigateUrl="http://www.itorian.com">My Blog</asp:HyperLink>
<br />
<asp:HyperLink ID="lnk2" runat="server" NavigateUrl="http://www.itorian.com/articles/aspdotnet/article.aspx">My ASP.NET Posts</asp:HyperLink>
<br />
<asp:HyperLink ID="lnk3" runat="server" NavigateUrl="http://www.itorian.com/about">About Me</asp:HyperLink>
</div>
Step 5:
Now, we are all set to run the project and check it. Let's look at my complete code.
Complete Code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>ASP.NET & jQuery Post</title>
<script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script>
<script type="text/javascript">
$(function () {
$(document).keyup(function (e) {
var key = (e.keyCode ? e.keyCode : e.charCode);
switch (key) {
case 112:
navigateUrl($('a[id$=lnk1]'));
break;
case 113:
navigateUrl($('a[id$=lnk2]'));
break;
case 114:
navigateUrl($('a[id$=lnk3]'));
break;
default: ;
}
});
function navigateUrl(jObj) {
window.location.href = $(jObj).attr("href");
}
});
</script>
</head>
<body>
<form id="form1" runat="server">
<p>
Press
<b>F1 for My Blog Page</b>
<br />
<b>F2 for My ASP.NET Posts Page</b>
<br />
<b>F3 for About Me Page</b>
</p>
<div>
<asp:HyperLink ID="lnk1" runat="server" NavigateUrl="http://www.itorian.com">My Blog</asp:HyperLink>
<br />
<asp:HyperLink ID="lnk2" runat="server" NavigateUrl="http://www.itorian.com/articles/aspdotnet/article.aspx">My ASP.NET Posts</asp:HyperLink>
<br />
<asp:HyperLink ID="lnk3" runat="server" NavigateUrl="http://www.itorian.com/about">About Me</asp:HyperLink>
</div>
</form>
</body>
</html>
I recommend you to download the attached file and check it. I hope you like it. Thanks.

Vishnu BhangalePosted Feb 13, 2018, 11:01 PM
Hi any one help me to open show div when we press F1 i try above but it always open browser Help tab
SrinivasPosted Oct 14, 2014, 2:03 AM
thank u very much .This code is very helpful to me
Debosree MukherjeePosted Dec 20, 2012, 2:18 AM
Very helpful post. But please let me know whether F1 really works on this logic. Because in my case only F1 is not working rather its opening the help file of the ie.
Anil KumarPosted Feb 14, 2012, 11:57 PM
Thank you for sharing this
EdPosted Feb 8, 2012, 12:12 PM
the code link seems broken
Sonakshi SinghPosted Feb 7, 2012, 11:02 PM
Good implementation
Monika AroraPosted Feb 7, 2012, 10:57 PM
Its a very nice and useful article.
Alok PandeyPosted Feb 7, 2012, 10:56 PM
Very useful article.
Arjun PanwarPosted Feb 7, 2012, 10:45 PM
Thank you, really appreciate for this article.
Sam HobbsPosted Feb 7, 2012, 7:07 PM
Thank you, Abhimanyu; that is useful. Yes, Windows applications do not use function keys as much as they could.