• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1585
  • Last Modified:

Capture ALT+F4

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
YZlat
Asked:
YZlat
  • 2
1 Solution
 
Bill PrewCommented:
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
 
Daz_1234Commented:
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
 
YZlatAuthor Commented:
Perfect! Thank you, it is just what I needed
0
 
Daz_1234Commented:
You're welcome, cheers for the grade!

Daz.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now