Solved

Capture ALT+F4

Posted on 2011-09-12
4
1,480 Views
Last Modified: 2012-05-12
I have an hta that uses VBScript that cannot be closed by any other way except clicking on a button on the form. The problem is that it can also be exited by hitting Alt and F4. What I want is to either disable that (which I don't believe is possible using VBScript), or capturing Alt+F4 event in my VBScript code in order to perform other actions before closing the hta (the same thing as done with a button on the form). How can that be accomplished?
0
Comment
Question by:YZlat
  • 2
4 Comments
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
Some discussion of this here, and the linked solution, although it seems like jscript was needed as well.

http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_23881380.html

~bp
0
 
LVL 12

Accepted Solution

by:
Daz_1234 earned 500 total points
Comment Utility
Hi YZlat,

In one of my HTA's I have the following VBScript sub:
  Sub KeyDown()
      '# MsgBox window.event.keyCode
      Select Case window.event.keyCode
          Case 115  'F4
              window.event.returnValue = false
              window.event.keyCode = 0
          Case 116  'F5
              window.event.returnValue = false
              window.event.keyCode = 0
          Case 70   'Ctrl + F
              If window.event.ctrlKey Then window.event.returnValue = false
          Case 27   'Escape
              Window.Close()
      End Select
  End Sub

Open in new window

... which when called from here:
<body onKeyDown='KeyDown()'>

Open in new window

... means that ALt-F4 is disabled (actually F4 is disabled whether or not you use ALT. If you wan't just Alt-F4 and not all F4 then let me know), F5 is disabled (refresh), CTRL+F is disabled (find) and the Escape key will close the application.

Hope this helps.
Daz.

0
 
LVL 35

Author Closing Comment

by:YZlat
Comment Utility
Perfect! Thank you, it is just what I needed
0
 
LVL 12

Expert Comment

by:Daz_1234
Comment Utility
You're welcome, cheers for the grade!

Daz.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now