Jump to content
Sign in to follow this  
imkrut

Basic help for a complete noob regarding closing a script after use

Recommended Posts

imkrut

Hey guys, first of all, i ask patience, since I'm super dumb when it comes to scripts, codes, etc.

I also been trying stuff on and off, copying scripts, reading help and whatnot, but i sort of hit a wall, and despite trying new stuff i can't quite get it to work.

I've used the search function, read numerous posts, and went through the relevant sections on the wiki, but i can't quite make it do what i want it to.

Basically, i want this program to run fullscreen, and load a certain file (which i already acomplished by copying scripts and fiddling around).

I also want it to close when i press the ESC key, which is also working at the moment.

HOWEVER, the script keeps running after the program closes, and upon pressing ESC it closes other programs, i want to correct that.

So basically, after that particular program closes, the script should stop, im sure a more correct way of doing it, would be to make the script only work while that particular program is running, but i have no idea how to go about doing that.

Also there might be unnecessary lines in there, so if someone is kind enough to correct it and help me, i would much appreciate it.

Thanks a bunch.

$windows = "DeSmuME 0.9.9 svn4565 x86-JIT"

Run ( "C:\Program Files\Steam\SteamApps\common\Emulators\Desmume\DeSmuME.exe castle.nds")
WinWait ( $windows )
WinActivate ( $windows )
WinWaitActive ( $windows )
Send("!{ENTER}")

HotKeySet("{Esc}", "CloseWindow")
While 1
sleep(100)
Wend

Func CloseWindow()
; ... can do stuff here
HotKeySet("{Esc}");unregister hotkey
If WinActive("Microsoft Excel") Then
Send("{Esc}")
Else
Send("!{F4}")
EndIf
HotKeySet("{Esc}", "CloseWindow");re-register
EndFunc

Share this post


Link to post
Share on other sites
FireFox

Hi,

Welcome to the autoit forum :)

If you want to close the script you have two possibilities :

1. Exit the main loop with the ExitLoop statement.

2. Exit the script with the Exit statement.

Local Const $sWndTitle = "DeSmuME 0.9.9 svn4565 x86-JIT"

Run("C:\Program Files\Steam\SteamApps\common\Emulators\Desmume\DeSmuME.exe castle.nds")
WinWait($sWndTitle)
WinActivate($sWndTitle)
WinWaitActive($sWndTitle)
Send("!{ENTER}")

HotKeySet("{Esc}", "CloseWindow")

While 1
    Sleep(100)
WEnd

Func CloseWindow()
    ; ... can do stuff here

    If WinActive("Microsoft Excel") = 1 Then
        Send("{Esc}")
    Else
        Send("!{F4}")
    EndIf

    Exit
EndFunc   ;==>CloseWindow

Note that in your script the hotkey won't work until the window is active.

Br, FireFox.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
imkrut

Thank you for the warm welcome, and insanely fast response.

Regarding the fix, it worked perfectly sir!

Thanks again for the help.

Now this is just me being greedy trying to understand the script better, but is there a way to limit the "close window" to a specific program? right now it just closes whatever is active/focused.

Thanks again.

Share this post


Link to post
Share on other sites
FireFox

Use the WinClose function ;)

Like this :

Func CloseWindow()
    ; ... can do stuff here

    WinClose("Microsoft Excel")

    Exit
EndFunc   ;==>CloseWindow

Br, FireFox.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
imkrut

Awesome, all working like i wanted.

Thank you so much sir.

Share this post


Link to post
Share on other sites
FireFox

You're welcome :)


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

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  

×