VBScript disable Alt + Home

Before anyone asks why you want to do this, this is for an in-house web application, so we want to prevent users from doing things that will put their application into a weird state.  So that being said, I have been able to disable all the IE keyboard shortcuts, all except for the Alt + Home key.  Basically I'm doing everything onKeyDown, and I've noticed that for single key presses you have to set the windows.event.returnValue to false and the window.event.keyCode to 0 as well.  But some key combinations all you need to do is set the window.event.returnValue to false.  Is there something else that you need to do to "cancel" the Alt + Home combination?

Thanks in advance,

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chriskchanAuthor Commented:
Thanks for the reply, but I have already seen that, and it's Javascript, not VBScript.  I have disabled everything else, e.g. Ctrl +N, F5, Ctrl+R, Backspace, Alt + Left, Alt + Right, etc., but I can't figure out how to disable Alt + Home.  There must be something else that you have to do to disable it.
sorry, the one above is java, these are vbs:

Tis is also java which you didn't request, but it works:
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
 function NoIEKey()
  return false
 window.onhelp=function(){return false};

JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

Hmm ... I did something similar to this in javascript, but haven't done this with VBscript.  I set the page up to "alert()" me with the keycode each time a key was pressed, so I could grab the codes for each key combination, and used the info to restrict input.

Have you tried something like that in VBscript ?
sorry, didn't read your question good enough, will try to disable alt home for you.
chriskchanAuthor Commented:
Gitcho, thanks for the reply but yes I already know the key combination for Alt + Home, but even though I can capture it, I can't disable that combination, even by setting the window.event.returnValue to false and the window.event.keyCode to 0.  
chrishchan, could you post your code?

If you put an alert in it won't redirect you to the homepage:

<SCRIPT language="vbscript">

Function onKeyDown()
      If (window.event.keycode=36) And (window.event.altkey)Then
            call alert("Alt-Home Pressed")            
      End If
End Function


<body onkeydown="call onKeyDown()">

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
chriskchanAuthor Commented:
Here is my code for the rest:

function document_onKeyDown
                  dim bAltKey
                  dim bCtrlKey
                  dim bShiftKey
                  dim kpressed
                  dim srcElementTagName
                  dim bDisableBackspace

                  kpressed = window.event.keyCode
                  srcElementTagName = window.event.srcElement.tagName
                  if (srcElementTagName = "INPUT") then
                        bDisableBackspace = false
                        bDisableBackspace = true
                  end if

                  if window.event.altKey = true then
                        bAltKey = true
                        bAltKey = false
                  end if

                  if window.event.ctrlKey = true then
                        bCtrlKey = true
                        bCtrlKey = false
                  end if

                  if window.event.shiftKey = true then
                        bShiftKey = true
                        bShiftKey = false
                  end if
                  window.status = "key pressed code = " & kpressed & " altkey=" & bAltKey & " ctrlkey=" & bCtrlKey
                  'Detect for single key presses
                  'F4,F5,F6,F11, extended windows keyboard "Back" and "Forward", backspace (as long as it's not in an input field), Ctrl + O (this one is special and needs to set the keycode to 0), Escape, (Alt + Home)
                  if ((kpressed = 116) or (kpressed = 115) or (kpressed = 117) or (kpressed = 122) or (kpressed = 166) or (kpressed = 167) or (kpressed = 8 and bDisableBackspace) _
                  or (kpressed = 79 and bCtrlKey) or (kpressed = 27)) then
                        window.event.keyCode = 0
                        window.event.returnValue = false
                  'detect for combination key presses (Alt + Left Arrow) and (Alt + Right Arrow), (Ctrl + N), (Ctrl + L), (Shift + F10), (Ctrl + R), (Ctrl + E), (Ctrl + I), (Ctrl + H)
                  elseif ((kpressed = 37 and bAltKey) or (kpressed = 39 and bAltKey) or (kpressed = 78 and bCtrlKey) or (kpressed = 76 and bCtrlKey) _
                  or (kpressed = 121 and bShiftKey) or (kpressed = 82 and bCtrlKey) or (kpressed = 69 and bCtrlKey) or (kpressed = 73 and bCtrlKey) _
                  or (kpressed = 72 and bCtrlKey) or (kpressed = 9 and bCtrlKey)) then
                        window.event.returnValue = false
                  elseif ((kpressed = 36 and bAltKey)) then
                        window.event.keyCode = 0
                        window.event.returnValue = false
                        window.event.altKey = false
                  end if
            end function

The last elseif is for the Alt + Home combination, but it's not working.  I was trying to set the altKey to false too but that didn't do anything.

chriskchanAuthor Commented:
Hey John you're right, that's weird, popping up an alert does the trick.  But I wonder if there's a way to do it without popping up a message?  The alert must cancel something that the keyCode = 0 and returnValue = false is not?
altkey is a read-only property and is TRUE if the key is down, or FALSE otherwise, so that doesn't work, nice one this is, puzzle along
chriskchanAuthor Commented:
setting the cancelBubble to false doesn't seem to do anything either... hmmm
chriskchanAuthor Commented:
Woops I mean cancelBubble to true
*grin*, just fiound that out too.
Seems to have something to di with fireing the event
Looks like its either an IE bug or a feature (depending how you look at it...)

Here's the best solution I could come up with (Its a major hack but it might meet your requirements):

<SCRIPT language="vbscript">
function onKeyDown()
      If (window.event.keycode=36) And (window.event.altkey) Then
            call window.setTimeout("window.focus",1)
      End If
End Function

<body onkeydown="onKeyDown()"></body>


Would you be so kind to respond to the suggestions?
chriskchanAuthor Commented:
Sure, well I haven't been able to find anything better than John's alert popup to disable the Alt+Home combination.  So I'm just using that method if they hit the Alt+Home keys.  All the other "forbidden" key combinations just get disabled silently.
Hi Chriskchan,

Thanks for the update!
(i'm still searching on the alt-home disable, nothing so far..
If I ever find it, I will let you know.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.