Friday, January 10, 2020

Restrict / Disable default behaviour of Function Key using Javascript


/* In this example Function Key pressed is F3 its Event Code is 114

F1  (112) - Brings up a Help window in many applications, including browsers, Microsoft Office and others
F2  (113) - Renames a selected object
F3  (114) - Opens search box in browsers
F4  (115) - Displays the Address bar list in My Computer or Windows Explorer (Windows XP)
F5  (116) - Updates the active Window. Useful to refresh a displayed page in a browser
F6  (117) - Cycles through the screen elements in a window
F7  (118) - Turn on/off Caret Mode (Firefox). Performs Spell and Grammar check (MS Word)
F8  (119) - Extend selection (MS Office)
F9  (120) - Updates fields (MS Office)
F10 (121) - Activates menu bar options
F11 (122) - Toggles between full screen and normal display in browsers
F12 (123) - Opens "Save as" dialog (MS Office)

*/
if (event.keyCode == 114){

/*
  Add some code logic, inaddition to Restrict Function key and then it restricts
*/
if (event.stopPropagation) {
event.stopPropagation();
}
if (event.preventDefault) {
event.preventDefault();
return false;
}
else {
event.keyCode = 0;
event.returnValue = false;
}
  }

No comments:

Post a Comment

Popular Posts