Solved

Capture ALT+F4

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

776 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