2

I am going to try to explain my problem by walking you through it. Thanks in advance for bearing with me.

TL;DR: Start at 4.

1. C#

I am in the process of creating an Arcade machine game launcher application in VS 2008 C#. It reads the 'C:\ARCADE\GAMES' directory and populates a list, which can then be selected. Within each games folder is a AutoHotKey script called 'autohotkey.ahk' which is run. This is the only logic in the C# app tier. This works.

The games are a mixture of

  • Dos games run in Dosbox
  • Snes games run in zsnesw
  • Windows games

2. Autohotkey

The arcade controls output keyboard commands, which cannot be changed. I use autohotkey scripts to rebind the keys for each game.

The 'autohotkey.ahk' script looks like this:

Run C:\BARCADE\GAMES\SIMPSONS\autohotkeybindings.ahk
RunWait, DOSBox.exe -conf "C:\BARCADE\GAMES\SIMPSONS\dosbox.conf" -exit  -noconsole  -fullscreen, C:\BARCADE\DOSBOX\
DetectHiddenWindows On
SetTitleMatchMode 2  
WinClose autohotkeybindings.ahk - AutoHotkey  
Exit

The first line runs the keybinding script, the second line runs dosbox and waits for it to exit/be killed, the other lines unload the keybinding script. This works.

3. DOSBOX

The 'dosbox.conf' script looks like this:

[sdl]
fullscreen=true
[render]
aspect=true
[cpu]
cycles=12000
[autoexec]
mount c C:\BARCADE\GAMES\
c:
cd SIMPSONS
cd PRG
SIMPSONS.EXE

This script runs the Simpsons arcade game, while taking into account the keybindings. The game launches, and can be played with the arcade controls. This works

4. Autohotkey keybindings

An abbreviated version of the keybinding script looks like this:

#MaxHotkeysPerInterval 1000
;p2
Numpad8::w
Numpad2::x
Numpad4::a
Numpad6::d
;FUNCTION BUTTONS
SetTitleMatchMode 2  
3::Process, Close, Dosbox

All buttons are remapped correctly, except for the Kill button (which outputs the number '3'). I started by testing if it was a mechanical problem, it wasn't. I tried attaching the code to any other buttons, didn't work. The kill command I use, "Process, Close, Dosbox" works on most other games, but there are alternatives to this. So I started experimenting with different code. Streetfighter exhibits the same issue, with znesw instead of dropbox:

3::
Run, kill.bat, C:\BARCADE\GAMES\STREETFIGHTER2
Process, Close, zsnesw
Process, Close, zsnesw.exe
WinKill, zsnesw
WinKill, zsnesw.exe
Run, tskill.exe zsnesw
return

contents of kill.bat:

%comspec% /c "taskkill /F /IM zsnesw /T"
%comspec% /c "taskkill /F /IM zsnesw /T"
%comspec% /c "taskkill /F /IM zsnesw.exe /T"
/c "taskkill /F /IM zsnesw /T"
/c "taskkill /F /IM zsnesw /T"
/c "taskkill /F /IM zsnesw.exe /T"

This works about 30% of the time. The other 70% of the time, the game doesn't exit. All other remapped controls work, so it's playable, yet there is no way to go back to the menu and select a different game. This feature breaks the whole purpose of the machine, which is going to be in a public place, and will get an increasing amount of games.

When the exit button doesn't work, all I can do is press ctrl+alt+del twice on the attached keyboard (which will be removed when the project is finished) to open up the task manager and return to windows XP. All button remaps still work (for example wiggling the sticks will output a bunch of letters in notepad) BUT the number 3, just outputs a number 3. So the keybindings seem to be ignored for some inexplicable reason.

I have tried many variations and combinations of all the kill commands I could think of (hence the bloated kill-attemps of zsnesw) and none of them work always. Many of them work sometimes, and over the course of 6 hours I was not able to draw even one parallel between when it worked and when it didn't.

Any help, alternative kill methods or whatever, is appreciated

AstroCB
  • 12,337
  • 20
  • 57
  • 73
joon
  • 832
  • 13
  • 31
  • Check if the taskkill returns with an intelligent ERROLEVEL (=0) if it succeeded. If ERRORLEVEL > 0 print out a message to a logfile. Maybe the taskkill command could not find the process. What does %comspec% contain? – Lucian Dec 09 '11 at 11:55

1 Answers1

1
3:: 
zKill:
Process, Exist, zsnesw.exe
If ErrorLevel {
    RunWait, %comspec% /c "taskkill /F /IM zsnesw.exe /T"  ,,hide
    Sleep, 300
    Goto, zKill
} Else
    ExitApp
Sampler
  • 17
  • 3
Joe
  • 11
  • 1