Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here



How to detect if shift key is pressed when clicking on a link by bustell
Posted: 27 Feb 04

Here is a little something that I have used to detect if the shift key is pressed while a user is clicking on a link.  

I used it for resorting a table by invoking the resort function through the onclick event of <a> tag like this:

onclick="resort("fieldName","DESC");return false;"

Here is the code:

<body  onKeyDown="aKeyDown();" onKeyUp="aKeyUp();">    
  <Script language="javascript">
    var shiftPressed;
    shiftPressed = false;

    function aKeyDown(e) {
      if (e.keyCode==16) {shiftPressed=true;}

    function aKeyUp(e) {
      if (e.keyCode==16) {shiftPressed=false;}

    function resort(fieldName, direction) {
      if (shiftPressed) {
        //Do this if shift is pressed
      else {
        //Do this if shift is not pressed



Back to Javascript FAQ Index
Back to Javascript Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close