JuanLopez

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

6 posts in this topic

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. 

 

 

 

 

 

Share this post


Link to post
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. 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

@spudw2k - Don't quite follow with regards to using GUISetAccelerators over HotKeySet since the Window we're checking is active is "Google Chrome", 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)


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

Share this post


Link to post
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