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,

Chris
chriskchanAsked:
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.

avidyaCommented:
0
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.
0
avidyaCommented:
sorry, the one above is java, these are vbs:
http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_20903665.html

Tis is also java which you didn't request, but it works:
===============
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
<script>
 function NoIEKey()
 {
  event.keyCode=0
  return false
 }
 document.onkeydown=NoIEKey
 window.onhelp=function(){return false};
</script>
</HEAD>
<BODY>

</BODY>
</HTML>
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

GitchoCommented:
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 ?
0
avidyaCommented:
sorry, didn't read your question good enough, will try to disable alt home for you.
0
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.  
0
avidyaCommented:
chrishchan, could you post your code?
0
john_horn1234Commented:
Weird...

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

</SCRIPT>

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

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
                  else
                        bDisableBackspace = true
                  end if

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

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

                  if window.event.shiftKey = true then
                        bShiftKey = true
                  else
                        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.

Chris
0
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?
0
avidyaCommented:
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
0
chriskchanAuthor Commented:
setting the cancelBubble to false doesn't seem to do anything either... hmmm
0
chriskchanAuthor Commented:
Woops I mean cancelBubble to true
0
avidyaCommented:
*grin*, just fiound that out too.
Seems to have something to di with fireing the event
0
john_horn1234Commented:
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
            window.open("","","height=1,width=1,top=1,left=1").close
            call window.setTimeout("window.focus",1)
      End If
End Function
</SCRIPT>

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

0
avidyaCommented:
Hi,

Would you be so kind to respond to the suggestions?
0
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.
0
avidyaCommented:
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.
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.