AutoHotkey Community

It is currently May 26th, 2012, 11:52 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: November 12th, 2009, 6:22 pm 
Offline

Joined: November 12th, 2009, 5:52 pm
Posts: 5
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!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 12th, 2009, 6:45 pm 
please check help file on Settimer/loop, Process/IfWinNotExist and Run
example:
Code:
SetTitleMatchMode,2
loop
{
ifWinNotExist, Notepad
Run, notepad.exe
sleep 1000
}
 


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 12th, 2009, 7:53 pm 
Online

Joined: April 8th, 2009, 7:49 pm
Posts: 6068
Location: San Diego, California
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 12th, 2009, 8:42 pm 
Offline

Joined: November 12th, 2009, 5:52 pm
Posts: 5
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.
Code:
Code:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 12th, 2009, 9:41 pm 
Online

Joined: April 8th, 2009, 7:49 pm
Posts: 6068
Location: San Diego, California
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 12th, 2009, 11:14 pm 
Offline

Joined: November 12th, 2009, 5:52 pm
Posts: 5
Leef_me wrote:
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 ... lFocus.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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 13th, 2009, 3:28 am 
Offline

Joined: November 12th, 2009, 5:52 pm
Posts: 5
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)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 13th, 2009, 4:50 am 
try SetKeyDelay on send clicks (make the duration longer)


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: hyper_, Leef_me, patgenn123, Pulover, rbrtryn, tidbit, XstatyK and 21 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
cron
Powered by phpBB® Forum Software © phpBB Group