[thelist] function keys

Mark Groen mark at markgroen.com
Tue Jun 25 11:57:04 CDT 2002


> --
> [ Picked text/plain from multipart/alternative ]
> is it possible to use the function keys as event handlers? my client
> switched an as400 application from a system interface that used
> function keys, to a browser based interface and now they miss there
> old function key events. can onkeypress determine this?
>  russ

Looks like it may be a PITA and can be done for IE but not NN quite as
easily. Did a Google on "function keys" + javascript and came up with a bit.

This one  seemed to be a good overall view of the task at hand:
http://www.suite101.com/article.cfm/6196/56492

To get a bit more intricate, this is taken from:
http://www.faqts.com/knowledge_base/view.phtml/aid/5768

document.onkeydown = function(){

if(window.event && window.event.keyCode == 116)
        { // Capture and remap F5
	window.event.keyCode = 505;
  	}

if(window.event && window.event.keyCode == 505)
        { // New action for F5
	alert('F5 key was pressed');
	return false;
        // Must return false or the browser will refresh anyway
	}
}



This snippet of code for a "view cart" function may help too, the principles
should apply and works for IE and NN for Aa-Zz letters:

    function keyPressed(key) {
       var sentString = ""

       if (navigator.appName == "Netscape") {
          var KeyChar = new Number(key.which)
          sentString = sentString + unescape("%" + KeyChar.toString(16))
          if (sentString == "v" || sentString == "V")
             viewCart()
       }
       if (navigator.appName == "Microsoft Internet Explorer") {
          sentString = sentString +
String.fromCharCode(top.MAIN.window.event.keyCode)
          if (sentString == "v" || sentString == "V")
             viewCart()
       }
    }

For Modifiers like Control, Alt, Shift it's different yet, taken from:
http://www.webreference.com/js/column11/modifierkeys.html


<SCRIPT LANGUAGE="JavaScript">
<!--

var nav4 = window.Event ? true : false;

function modifiers(e) {
  if (nav4) {
     document.keys.alt.checked = e.modifiers & Event.ALT_MASK;
     document.keys.control.checked = e.modifiers & Event.CONTROL_MASK;
     document.keys.shift.checked = e.modifiers & Event.SHIFT_MASK;
     document.keys.meta.checked = e.modifiers & Event.META_MASK;
  } else {
     document.keys.alt.checked = window.event.altKey;
     document.keys.control.checked = window.event.ctrlKey;
     document.keys.shift.checked = window.event.shiftKey;
     document.keys.meta.checked = false;
  }
  return false;
}

// -->
</SCRIPT>

<P>Hold one or more modifier keys and click
<A HREF="javascript:void(0)"
   onMouseDown="return modifiers(event)"
   onClick="return false">here</A>.</P>
<FORM NAME="keys">
<INPUT TYPE="checkbox" NAME="alt"> Alt
<INPUT TYPE="checkbox" NAME="control"> Control
<INPUT TYPE="checkbox" NAME="meta"> Meta
<INPUT TYPE="checkbox" NAME="shift"> Shift
</FORM>


HTH!



More information about the thelist mailing list