Sign in to follow this  
Followers 0
Mingre

Terminating 2 AutoIt3.exe with a hotkey [RESOLVED]

8 posts in this topic

#1 ·  Posted (edited)

How do I terminate two (different) au3 scripts running at the same time with just one hotkey?

The best I can do for now is to have two hotkeys (technically) although I only need to press the first hotkey.

The files are P1.au3 and P2.au3 and are located on the same folder.

The first and only successful method I have was to create in each script a terminating function Ex1() and Ex2(). Pressing the hotkey for the 'terminating function' of the first script triggers that of the second.

The P1.au3 contains the following:

Hotkeyset ("{ESC}","Ex1")
Func Ex1()
   Send("{F1}")
   Exit
EndFunc

P2.au3:

Hotkeyset ("{F1}","Ex2")
Func Ex2()
   Exit
EndFunc

Edit: I put the wrong script!

This method does work but two keys are used, which kind of bothers me.

The other methods I tried but were a failure include using ProcessClose()and WinKill() functions.

I tried using ProcessClose("AutoIt3.exe") (I used "AutoIt3.exe" because it was the name displayed on the Processes section of the Windows Task manager) but only one script is terminated (the one w/ the highest PID according to AutoIt Help). I learned that I can use ProcessExists to know the PID of a process but I don't know how to get the PID of the other running script. I also tried using @ScriptFullPath for the "process" parameter.

Please help.

Thanks.

L. Go

Edited by Lilbert

Share this post


Link to post
Share on other sites



If two AutoIt scripts set the same HotKeys, you should avoid running those scripts simultaneously.

(The second script cannot capture the hotkey unless the first script terminates or unregisters the key prior to the second script setting the hotkey.)

See _IsPressed function, you'll can set the same 'hotkey' for close them ! Posted Image


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

If two AutoIt scripts set the same HotKeys, you should avoid running those scripts simultaneously.

(The second script cannot capture the hotkey unless the first script terminates or unregisters the key prior to the second script setting the hotkey.)

See _IsPressed function, you'll can set the same 'hotkey' for close them ! Posted Image

Sorry, I ended up putting a different script!

Anyway, I don't think they have the same HotKeys. My P1.au3 uses {ESC} and P2.au3 uses {F1}.

The problem with _IsPressed() Function is that I have to do it in a loop. In which case my scripts won't be able to be in another loop. (The purpose of having two scripts was actually to have two loops running at the same time.)

L. Go

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

it dont need to have specific loop reserved only for it

Some other solutions for loop AdlibRegister

as for how to get pid and close other script

@AutoItPID will return running pid

ProcessList will get currently running processes and their pid-s

Compare one to another in loop to get the other pid

or

Post the script that can replicate problem with

The problem with _IsPressed() Function is that I have to do it in a loop.

Your post of 2 scripts with 4 lines do not help to see about what are you talking about.

Edit:

Note that there isnt alot of things that need 2 scripts running in diffrent loops to achieve something. Mostly the problem is that other side don`t know how to organise their loop.

Edited by bogQ
1 person likes this

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

The problem with _IsPressed() Function is that I have to do it in a loop. In which case my scripts won't be able to be in another loop. (The purpose of having two scripts was actually to have two loops running at the same time.)

L. Go

You can use an AdlibRegister Function for use _IsPressed function and detect a key pressed...


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

wakillon,

Thanks for clarifying! And sorry for immediately dismissing your idea, acting as if I know enough about AutoIt. A problem though about the AdLib function is that it might be too much of a CPU load for my computer since the function is called every 250 ms (less than a second!). I may be exaggerating but I think it's better to do it the "lighter" way.

bogQ,

Thanks for mentioning about @AutoItPID, that really helped me. I scripted using ProcessList and @AutoPID and it works fine! Here's the completed code for my exit function:

otKeySet("{ESC}","Ex")
Func Ex()

$list = ProcessList()
for $i = 1 to $list[0][0]
    If $list[$i][0]="AutoIt3.exe" Then
        If $list[$i][1] <> @AutoItPID Then
            Processclose($list[$i][1])
            ExitLoop
        EndIf
    EndIf
Next

Processclose(@AutoItPID)

EndFunc

(If you could simplify, please do so. I'd appreciate it.)

And sorry about not posting the whole script in this forum. I'd rather not because my script's badly-written and it's embarrassing! (Posting it'd b like showing everyone else your flunked exam. I hope you get what I mean.)

Share this post


Link to post
Share on other sites

AdlibRegister functions, if just looking for a key press, aren't very CPU intensive. Try it, open Taskmanager and watch the CPU usage of your script, it's minimal.

1 person likes this

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

AdlibRegister functions, if just looking for a key press, aren't very CPU intensive. Try it, open Taskmanager and watch the CPU usage of your script, it's minimal.

Thank for clearing that up. I apologize if I tend to make far-fetched assumptions.

I tried checking the Mem Usage and it was indeed not CPU-intensive. I think I'll use this method now. I tested it and it seems like it works better than what I did on my previous script.

Thanks.

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
Sign in to follow this  
Followers 0