Jump to content

Disable ESC if certain window is opened


Go to solution Solved by MikahS,

Recommended Posts

So currently I have this where it will pop up a message box when i press ESC in that particular window.  What it also does it still send the ESC key command.  I am trying to make it NOT send ESC if that particular window is active.  Here is what i tried so far, but didn't seem to work.  Do I need to do a keyboard hook or something?

#include <Misc.au3>

While 1
    If _IsPressed("1B") AND WinActive("MyWindow") Then
        ;Disable ESC key here
        MsgBox(0, "", "Esc pressed")
    EndIf
WEnd
Link to comment
Share on other sites

  • Solution

Something like this:

Local $hotKey = 0

While 1
    If WinActive("MyWindow") Then
        $hotKey = HotKeySet("{ESC}", "DoNothing")
    Else
        If $hotKey = 0 Then
            ContinueLoop
        Else
            $hotKey = HotKeySet("{ESC}")
        EndIf
    EndIf
WEnd
 
Func DoNothing()
    ;0/0
EndFunc

Does that help? :)

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

Ah! PERFECT.  Thank you very much!

 

My pleasure. ;)

P.S. The only reason I added the extra If statement was so that you are not sitting their calling HotKeySet("{ESC}") every time you loop through, just because that certain window is not active. :)

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...