mikeveli20 Posted June 28, 2008 Share Posted June 28, 2008 Hey all,I have a bit of a programming background so I understand concepts and stuff like that, but I'm brand new to AutoIt. I'm trying to create a simple script that will exit a game when I press the ESC key which I'm trying to map to Alt-F4. Is this even possible? Here's what I've got so far that isn't working:--StartHotKeySet("{ESC}","_GetOut") $executable = "" $directory = ""if $numParms > 0 Then $game = $CmdLine[1]Else msgBox(4096,"Error","You must provide a game parameter") exit(1)EndIf$var = IniReadSection("test.ini",$game)If @error Then MsgBox(4096, "", "Error occured, Invalid parameter or the ini file is missing.") exit(1)Else $executable = IniRead("test.ini",$game,"executable","") $directory = IniRead("test.ini",$game,"directory","") $fullpath = $directory & $executable $msg = ">>" & $directory & $executable & "<<" ;msgBox(4096,"Testing",$msg,15) run($fullpath,$directory)EndIf_GetOut() Func _GetOut() send("{AltDown}{F4}") send("{AltUp}")EndFunc--EndI've based the script on the code and concepts from a script found here:http://www.a-ruud-awakening.com/arcade/ind...Site.AmLasGamesI'm trying to achieve the same effect, by exiting the game while just pressing ESC.Any help would be great. Thanks. Link to comment Share on other sites More sharing options...
martin Posted June 28, 2008 Share Posted June 28, 2008 Hey all, I have a bit of a programming background so I understand concepts and stuff like that, but I'm brand new to AutoIt. I'm trying to create a simple script that will exit a game when I press the ESC key which I'm trying to map to Alt-F4. Is this even possible? Here's what I've got so far that isn't working: --Start HotKeySet("{ESC}","_GetOut") $executable = "" $directory = "" if $numParms > 0 Then $game = $CmdLine[1] Else msgBox(4096,"Error","You must provide a game parameter") exit(1) EndIf $var = IniReadSection("test.ini",$game) If @error Then MsgBox(4096, "", "Error occured, Invalid parameter or the ini file is missing.") exit(1) Else $executable = IniRead("test.ini",$game,"executable","") $directory = IniRead("test.ini",$game,"directory","") $fullpath = $directory & $executable $msg = ">>" & $directory & $executable & "<<" ;msgBox(4096,"Testing",$msg,15) run($fullpath,$directory) EndIf _GetOut() Func _GetOut() send("{AltDown}{F4}") send("{AltUp}") EndFunc --End I've based the script on the code and concepts from a script found here: http://www.a-ruud-awakening.com/arcade/ind...Site.AmLasGames I'm trying to achieve the same effect, by exiting the game while just pressing ESC. Any help would be great. Thanks.Welcome to the AutoIt forums mikeveli20 Looks like the only thing missing in your script is a loop to keep the script running. Another hotkey to exit the script would be useful. To send Alt and F4 you can use Send("!{F4}") If you use code tags around your code it's easier to read. [ code ] before and [ /code ] after but without the spaces. HotKeySet("{ESC}", "_GetOut") HotKeySet("{F*}", "StopRun") $executable = "" $directory = "" If $numParms > 0 Then $game = $CmdLine[1] Else MsgBox(4096, "Error", "You must provide a game parameter") Exit (1) EndIf $var = IniReadSection("test.ini", $game) If @error Then MsgBox(4096, "", "Error occured, Invalid parameter or the ini file is missing.") Exit (1) Else $executable = IniRead("test.ini", $game, "executable", "") $directory = IniRead("test.ini", $game, "directory", "") $fullpath = $directory & $executable $msg = ">>" & $directory & $executable & "<<" ;msgBox(4096,"Testing",$msg,15) Run($fullpath, $directory) EndIf While 1 Sleep(100) WEnd Func StopRun() Exit EndFunc ;==>StopRun _GetOut() Func _GetOut() Send("!{F4}") EndFunc ;==>_GetOut Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
mikeveli20 Posted June 28, 2008 Author Share Posted June 28, 2008 Worked like a charm! Thanks! The only thing is when the game exits, there is a command window open. Is there a way to close this automatically? When I run the game without the script and press Alt-F4 to exit, there is no command window. However, when the script is running and I press ESC or Alt-F4 to exit, there is a command window. Link to comment Share on other sites More sharing options...
Nevin Posted June 28, 2008 Share Posted June 28, 2008 WinClose() or WinKill() won't work for this whole thing? Link to comment Share on other sites More sharing options...
mikeveli20 Posted June 28, 2008 Author Share Posted June 28, 2008 (edited) WinClose worked. Here is the final script: expandcollapse popup$numParms=$CmdLine[0] HotKeySet("{ESC}", "_GetOut") HotKeySet("{F*}", "StopRun") $executable = "" $directory = "" $window = "" If $numParms > 0 Then $game = $CmdLine[1] Else MsgBox(4096, "Error", "You must provide a game parameter") Exit (1) EndIf $var = IniReadSection("test.ini", $game) If @error Then MsgBox(4096, "", "Error occured, Invalid parameter or the ini file is missing.") Exit (1) Else $executable = IniRead("test.ini", $game, "executable", "") $directory = IniRead("test.ini", $game, "directory", "") $fullpath = $directory & $executable $msg = ">>" & $directory & $executable & "<<" ;msgBox(4096,"Testing",$msg,15) Run($fullpath, $directory) winwait($window) WinActivate($window) EndIf While 1 Sleep(100) WEnd Func StopRun() Exit EndFunc;==>StopRun _GetOut() Func _GetOut() if winexists($window) Then ;msgBox(4096,"Getting Out","Killing Window",15) winClose($window) Send("!{F4}") EndIf Exit(0) EndFunc;==>_GetOut Is there anything in here that is not necessary or redundant that I can eliminate to tighten up the code? I'm not sure if I used the WinClose function efficiently. It does the trick so I guess it's ok. Edited June 28, 2008 by mikeveli20 Link to comment Share on other sites More sharing options...
martin Posted June 29, 2008 Share Posted June 29, 2008 WinClose worked. Here is the final script: expandcollapse popup$numParms=$CmdLine[0] HotKeySet("{ESC}", "_GetOut") HotKeySet("{F*}", "StopRun") $executable = "" $directory = "" $window = "" If $numParms > 0 Then $game = $CmdLine[1] Else MsgBox(4096, "Error", "You must provide a game parameter") Exit (1) EndIf $var = IniReadSection("test.ini", $game) If @error Then MsgBox(4096, "", "Error occured, Invalid parameter or the ini file is missing.") Exit (1) Else $executable = IniRead("test.ini", $game, "executable", "") $directory = IniRead("test.ini", $game, "directory", "") $fullpath = $directory & $executable $msg = ">>" & $directory & $executable & "<<" ;msgBox(4096,"Testing",$msg,15) Run($fullpath, $directory) winwait($window) WinActivate($window) EndIf While 1 Sleep(100) WEnd Func StopRun() Exit EndFunc;==>StopRun _GetOut() Func _GetOut() if winexists($window) Then ;msgBox(4096,"Getting Out","Killing Window",15) winClose($window) Send("!{F4}") EndIf Exit(0) EndFunc;==>_GetOut Is there anything in here that is not necessary or redundant that I can eliminate to tighten up the code? I'm not sure if I used the WinClose function efficiently. It does the trick so I guess it's ok.Apart from F* which I guess should be F8, it looks ok to me. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Zedna Posted June 29, 2008 Share Posted June 29, 2008 (edited) Is there anything in here that is not necessary or redundant that I can eliminate to tighten up the code? I'm not sure if I used the WinClose function efficiently. It does the trick so I guess it's ok.I think Send("!{F4}") is not neccessary after WinClose($window) anymore.WinClose($window) does the same job as Send("!{F4}").BTW: Nice first script ;-) Edited June 29, 2008 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now