Sleep sets @error to 0. You can at least solve this in three ways.
Storing @error in a variable : $pos = PixelSearch (752,345,1001,589,0x3E0C3F)
$error = @error
Sleep(2000)
If $error <> 1 then
;If Ubound($pos) > 0 Then
;If IsArray($pos) Then
Download http://www.autoitscript.com/fileman/users/Helge/udfs/_ProcessGetHWnd.au3 and then run this script in the same directory... #include "_ProcessGetWin.au3"
$iPid = Run("calc.exe")
$hWnd = _ProcessGetWin($iPid)
If NOT @error Then
MsgBox(64, "", "PID : " & @TAB & $iPid & @CRLF & "HWND : " & @TAB & $hWnd)
WinClose($hWnd)
Else
MsgBox(16, "ProcessGetWin", "Couldn't find any matching windows !")
ProcessClose($iPid)
EndIf
Define "help".If you mean by giving you the complete code that you wanted, then no, I didn't help you. When the person asking the question haven't shown much effort I prefer to tell them where and how they can solve it by themselves, and I think I did a good job in this case. If you had opened the helpfile and looked at the suggested functions I'm sure you would've solved your problem by now.
You need to set the workingdir to the game's directory.. This works for me : $BfDir = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\EA GAMES\Battlefield 1942", "GAMEDIR")
$BfExe = $BfDir & "\BF1942.exe"
Run($BfExe, $BfDir) @danwilli : Why use @comspec in this case?
Don't you dude me. You said you wanted the GUI to be closed when you pressed escape.You didn't say anything about if the GUI had to be active or not, but I gave you solutions to both scenarios. "Pressing escape in a active GUI sends the $GUI_EVENT_CLOSE...so you just need to check for that message.""If you would like to close the GUI and/or script even when the GUI is inactive then look up HotKeySet."You now say you wanted the script to be closed even when the GUI was inactive and since Iin the first part of my post explained how to do it when the GUI was active you should've just ignored that part... Instead you should follow my second suggestion... looking up HotKeySet. Did you do that? Somehow I doubt it.
Fast question....hmm, I'm sure you mean you want a fast answer, but you wont get one.
Pressing escape in a active GUI sends the $GUI_EVENT_CLOSE message at default (can be toggled
with GUICloseOnESC), which is also sent when clicking the close-button in a GUI, so you just need to
check for that message.
#include <GUIConstants.au3>
GUICreate("", 300, 300)
GUISetState()
While 1
$nMsg = GUIGetMsg()
If $nMsg = $GUI_EVENT_CLOSE Then Exit
WEnd
If you would like to close the GUI and/or script even when the GUI is inactive then look up HotKeySet.