 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
treecar
Joined: 12 Nov 2009 Posts: 5
|
Posted: Thu Nov 12, 2009 5:22 pm Post subject: Keeping a file open - for an arcade game |
|
|
I have a question, I'm pretty new to Autohotkey, and I've searched the forums for a few hours now trying to figure this out with no luck(but I did learn a lot of other cool stuff in the process.)
Here's what I'm trying to do.
I made a little video game in blender, made an arcade cabinet for it and have it all wired to the joystick controls, this part is working fine. The only problem is from time to time it crashes.
What I'm trying to do is write a script that checks to see if a particular file is currently running(mygame.exe), and if it's not then open(meaning it has crashed) it automatically re-opens the file.
I have the game on display and running at my college and I'm trying to figure out a way so I don't have to keep on going back to restart it. I know I should really re-write the program so it doesn't crash and I'm currently working on that, but my main objective is to get it working so people can play it and it doesn't break, and I was thinking Autohotkey might be the answer.
So if anyone has any ideas I would truly appreciate it.
Thanks! |
|
| Back to top |
|
 |
Guest
|
Posted: Thu Nov 12, 2009 5:45 pm Post subject: |
|
|
please check help file on Settimer/loop, Process/IfWinNotExist and Run
example:
| Code: |
SetTitleMatchMode,2
loop
{
ifWinNotExist, Notepad
Run, notepad.exe
sleep 1000
}
|
|
|
| Back to top |
|
 |
Leef_me
Joined: 08 Apr 2009 Posts: 1158 Location: San Diego, California
|
Posted: Thu Nov 12, 2009 6:53 pm Post subject: |
|
|
Here is a more elaborate version | Code: | ;======================================
; Change this parameters as desired
;======================================
external_program_name=Notepad
external_program_run=%SystemRoot%\system32\notepad.exe
check_delay=10000 ; wait before checking if program crashed
start_limit=5 ; limit the number of unsuccessful tries to open program
windows_boot_wait=30
;======================================
Settitlematchmode, 2 ; recognise partial titles
loop, %windows_boot_wait%
{
time_left:=windows_boot_wait-a_index
wait_msg=Waiting %time_left% seconds before starting%a_space%
msgbox,,,%wait_msg%%a_space%%external_program_name%,1
if time_left=1
break
}
start_count=0
loop
{
;k:=WinExist(%external_program_name%)
;msgbox %k%
;msgbox,,, %start_count%!%start_limit%,1
if (start_count > start_limit)
{
msgbox Failed to open %external_program_name% more than %start_limit% times. `nPlease contact treecar @ autohotkey`n Try again ?
start_count=0
}
IfWinNotExist , %external_program_name%
{
msgbox,,, not present %start_count%, 1
run, %external_program_run%
sleep, 2000 ; wait for program to run, otherwise you could have multiple copies
start_count++
}
else
{
msgbox,,, there it is, 1
start_count=0
sleep, %check_delay% ; wait before checking if program crashed
}
}
esc:: ; in case of emergency, press escape
exitapp |
|
|
| Back to top |
|
 |
treecar
Joined: 12 Nov 2009 Posts: 5
|
Posted: Thu Nov 12, 2009 7:42 pm Post subject: |
|
|
thanks so much for the help I truly appreciate it. One other thing I forgot to mention is when the game reloads for some reason it loses focus(the game is run in full screen mode) so what I have to do is emulate a click after the program re-starts to re-gain the focus.
So here's what I was thinking,
| Code: |
SetTitleMatchMode,2
loop
{
ifWinNotExist, game
Run, launch1.bat
sleep 8000
MouseClick, left, 647, 436
SoundBeep
sleep 7000
}
I put a little beep in there too so I could hear when the loop is taking place. When I try this I hear the beep so I know the loop is going on, but for some reason the mouse click isn't being recognized. Any ideas on why this might be happening?
Could it be because I'm running the game in a full screen mode?
I'm pretty stuck. |
|
|
| Back to top |
|
 |
Leef_me
Joined: 08 Apr 2009 Posts: 1158 Location: San Diego, California
|
Posted: Thu Nov 12, 2009 8:41 pm Post subject: |
|
|
| Quote: | | Any ideas on why this might be happening? |
1. Some games are difficult to control with Ahk, there may be a problem with either clicks or keys sent; or both may be ignored
2. You think you know where the mouse is clicking but it isn't the right location.
I suggest looking at the example here, that can show you the location (it uses tooltip and that info may not be visible if game is f.s.)
http://www.autohotkey.com/docs/commands/MouseGetPos.htm
btw, mouse location is relative to the application window, unless changed with CoordMode
http://www.autohotkey.com/docs/commands/CoordMode.htm
3. To diagnose things like this I favor visible feedback
| Code: | MouseMove, 20,20, 10 ; move away from the click
MouseClick, left, 647, 436, 1, 10 ; move toward the click |
4. Would this help ?
http://www.autohotkey.com/docs/commands/WinMaximize.htm |
|
| Back to top |
|
 |
treecar
Joined: 12 Nov 2009 Posts: 5
|
Posted: Thu Nov 12, 2009 10:14 pm Post subject: |
|
|
[quote="Leef_me"] | Quote: | | Any ideas on why this might be happening? |
1. Some games are difficult to control with Ahk, there may be a problem with either clicks or keys sent; or both may be ignored
This seems to be the case, for some reason the game can receive keystrokes but not clicks, it's strange. I checked the mouse position and it seems like everything is in the right place, just for some reason it isn't taking the click.
One idea I was thinking, when the program reloads if it crashes, maybe there is a way to have it so when it reloads it keeps it as the main window in focus. I read this, but can't seem to grasp what I'm supposed to do
http://www.autohotkey.com/docs/commands/ControlFocus.htm
It's crazy I've been working on this since 9 am and my brain is frazzled, I feel like I'm probably missing something big that's probably in front of me but can't figure it out yet |
|
| Back to top |
|
 |
treecar
Joined: 12 Nov 2009 Posts: 5
|
Posted: Fri Nov 13, 2009 2:28 am Post subject: |
|
|
Almost there...
So I have it so the script always checks and make sure the program is always running, and if it crashes it automatically re-opens, I also have it so when it does re-open it emulates some mouse clicks to re-gain the focus. The only strange thing is the mouse clicks don't get recognized every time the script runs. I'm wondering why this might be the case, it works about half of the time.
This is the code for the clicks
Any ideas?
| Code: |
Sleep 9000
Soundbeep
SendEvent {Click 645, 438}
Sleep 1000
SendPlay {Click 645, 438}
MouseClick, left, 645, 438
Sleep, 2000
SoundBeep
I put beeps in to so I can know when the code is running(because the game runs in fullscreen mode) |
|
|
| Back to top |
|
 |
Guest
|
Posted: Fri Nov 13, 2009 3:50 am Post subject: |
|
|
| try SetKeyDelay on send clicks (make the duration longer) |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|