Jump to content

Send alt+f4 if the esc button is pressed and only when program is running


Recommended Posts

Ive been trying all day to put something together, but something not clicking. 

 

This is what I have. 

 

#include <MsgBoxConstants.au3>

If ProcessExists("chrome.exe") Then ; Check if the Notepad process is running.
    HotKeySet("{ESC}", "Main")
    HotKeySet("{PAUSE}", "Main1")
    Func Main()
       Send("!+{F4}",0)
    ;MsgBox($MB_SYSTEMMODAL, "", "Notepad is running")
    Func Main1()
       ControlClick ( [, button = "left" [, clicks = 3 [, 1629 [, 105]]]] )
Else
    MsgBox($MB_SYSTEMMODAL, "", "Notepad is not running")
EndIf

 

what I am trying to do is run a script that will only work when chrome is running and if the ESCAPE button gets pressed it will send the alt+f4 combo to terminate the program, or if the PAUSE button gets click it will click 3 clicks to a pre-determined spot on the webpage (1629,105).

 

Ive been trying all day, and im at a stand still now, I think I have it right. PLease tell me im not that way off, that its some ; missing somewhere or soemthing lol. 

 

 

 

 

 

Link to comment
Share on other sites

3 minutes ago, Subz said:

You mean something like this?

#include <AutoItConstants.au3>

HotKeySet("{ESC}", "AltF4")
HotKeySet("{PAUSE}", "Pause")

While 1
    Sleep(100)
WEnd

Func Pause()
    If WinActive('[CLASS:Chrome_WidgetWin_1]') Then MouseClick($MOUSE_CLICK_LEFT, 1629, 105, 3)
EndFunc

Func AltF4()
    If WinActive('[CLASS:Chrome_WidgetWin_1]') Then Send('!+{F4}')
EndFunc

 

Yeah that worked perfectly, and is similar but different to what I tried. I guess with more expresience ill learn more different ways to accomplish the same thing. Thanks big time. 

Link to comment
Share on other sites

Just a couple comments.  

If you opt to use GUISetAccelerators instead of HotKeySet, you won't have to worry about the window being active or not.  The "hotkey" function will only fire if the GUI is already active.  

Also,
instead of sending the Alt+F4 keystrokes, you could use the WinClose function--more elegant and less room for human error.

Edited by spudw2k
strike-through, see next posts
Link to comment
Share on other sites


Doh, you are totally right.  I glazed over the fact that the OP is not dealing with a GUI they made.  Apologies.

My second statement still stands....I think  :blink:

Edited by spudw2k
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...