Main > Main Forum
Huge, huge problem.
jasonbar:
Thanks-
I spent the better part of today on this program. :-[
Barked up lots of wrong trees...trees that were aaaalmost the right tree...
Finally got help at the AutoHotKey forum: xxxxxxxxxxxx
My final scripts, for reference:
AutoHotKey (launches as my Windows XP shell instead of explorer):
; Launch MaLa & CPW, ensure MaLa focus, play random start & end sounds w/out clipping
; run shutdown monitor script
run, C:\Documents and Settings\Customer\My Documents\shutdownmonitor.ahk
; launch CPWizard minimized
run, C:\program files\cpwizard\cpwizard.exe -minimized
; generate random #...set high value to # of files in start sound directory, name all files #.wav
random, startsound, 1, 20
; play random start sound
soundplay, c:\emulators\mala\Sound-MaLa_Start\%startsound%.wav, wait
;Loop to launch MaLa & monitor if MaLa closes
monitormala:
; launch MaLa
run, C:\emulators\mala\mala.exe
; make sure MaLa exists before continuing
winwait, MaLa
; as soon as MaLa loses focus, get it back
sleep, 1000 ; had to have a short pause here or regaining focus wouldn't work...
winwaitnotactive, MaLa
winactivate, MaLa
; wait for MaLa to close (intentionally or not)
winwaitclose, MaLa
;Check for MaLa close while holding down Exit Code Key
getkeystate, state, F10
if state = D
{
; generate random #...set 2nd # to # of files in exit sound directory, name all files #.wav
random, exitsound, 1, 16
; play random exit sound
soundplay, c:\emulators\mala\Sound-MaLa_Exit\%exitsound%.wav, wait
; launch Windows Explorer
run, explorer
; exit script
exit
}
;If MaLa exits w/out Exit Code Key...
else
{
; generate random #...set 2nd # to # of files in exit sound directory, name all files #.wav
random, exitsound, 1, 11
; play random exit sound
soundplay, c:\emulators\mala\Sound-MaLa_Exit\%exitsound%.wav, wait
goto, monitormala
}
And here's the concise shutdown monitor that detects shutdown & plays a sound & then shuts down. The only catch is that it can't distinguish between a restart from the Start Menu & a shutdown from the PC case button. Oh well...
shutdownmonitor.ahk:
#singleinstance ignore
SetTimer, soundoff, Off
OnMessage(0x11, "powerbutton")
Return
powerbutton(wParam, lParam)
{
SetTimer, soundoff, On
Return false ; abort shutdown
}
soundoff:
SetTimer, soundoff, Off
; generate random #...set 2nd # to # of files in exit sound directory, name all files #.wav
random, exitsound, 1, 16
; play random exit sound
soundplay, c:\emulators\mala\Sound-MaLa_Exit\%exitsound%.wav, wait
Shutdown,5
ExitApp
Return
Phew. Done! :cheers:
Thanks,
-Jason
bkenobi:
Nice work! Isn't it satisfying coding it yourself rather than having someone else do it for you. :cheers:
Btw, I didn't know about OnMessage to start with, so this has been informative for me too!
jasonbar:
Glad you learned something too! Yah, it's satisfying to figure it out myself, but it's also been a big time-sink for me while I fuss with it. :]
Also, I had a big scare where I foolishly edited the script incorrectly so that it would simply shut down my PC as soon as the script launched, & I have my main script as my shell & the first thing it does is call the shutdownmonitor script, so I simply got a power-down every time I booted. =( Safe mode didn't work, as it was still shelling to my main script. Then I discovered a "safe mode with command prompt" option. Phew! :dizzy:
Anyway, a little further discussion & code optimization/explanation at the AHK forum: http://www.autohotkey.com/forum/viewtopic.php?p=304698
Thanks,
-Jason
bkenobi:
Yeah, that would be pretty scary. I would have been all over google for that one!
BamBam:
--- Quote from: Chukka on October 12, 2009, 01:44:51 pm ---
--- Quote from: DeLuSioNal29 on October 12, 2009, 01:27:16 pm ---First and foremost... Try updating the title of this topic. Can you be any more generic?
Perhaps you will get a greater response when you are specific in what you need help with.
Just a thought.
D
--- End quote ---
Eat ####.
Thanks everyone else for their help. The CD drive wasn't working because the power wire wasn't connected properly. I got it working and used the XP CD to rebuild the boot.ini. The boot.bmp was the problem. Got it working now.
Thanks to all the helpful people except Delusional and BamBam.
--- End quote ---
Chucka,
My bad. I should have thrown a ;) in with my comment. Chill out and have fun.