Solved

Capture ALT+F4

Posted on 2011-09-12
4
1,504 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 53

Expert Comment

by:Bill Prew
ID: 36525673
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 13

Accepted Solution

by:
Daz_1234 earned 500 total points
ID: 36528449
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
ID: 36528999
Perfect! Thank you, it is just what I needed
0
 
LVL 13

Expert Comment

by:Daz_1234
ID: 36529010
You're welcome, cheers for the grade!

Daz.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

789 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