Jump to content

question for expert module (.ahk) writers


craiganderson

Recommended Posts

hello

im working on a module and need to do the following:

if game belongs to this list: game a, game b, game c

then load the following way

if game belongs to this list: game d, game e, game f

then load the following way

if game belongs to this list: game g, game h, game i

then load the following way

probably real easy for the experts on here

point me in right direction?

thanks

craig

Link to comment
Share on other sites

something like this?

if (romName = "addemup_interact" or romName = "knockdown_interact" or romName = "backgammon_interact" or romName = 

"addition_hector1" or romName = "asteroides_hector1" or romName = attro_logic_interact" or romName = "base_spatiale_hector1")
{
ControlClick, Button5,  DCHector settings
Sleep, 1000
ControlClick, Button31,  DCHector settings

IfWinExist, DCHector Setting modification ahk_class #32770
	{
   			WinActivate  ; Automatically uses the window found above.
  			ControlSend, Button1, {Enter}, DCHector Setting modification ahk_class #32770
	}


WinWait(" DCHector - Micronique Hector emulatorahk_class Hector")
WinWaitActive(" DCHector - Micronique Hector emulatorahk_class Hector")
WinActivate,  DCHector - Micronique Hector emulatorahk_class Hector

Sleep,1000

WinMenuSelectItem, ahk_class Hector, , File, Load Tape

Sleep,3000

Loop 
{
ControlGetText, edit1Text, Edit1, Open ahk_class #32770
If ( edit1Text = romPath . "\" . romName . romExtension )
Break
Sleep, 200
ControlSetText, Edit1, %romPath%\%romName%%romExtension%, Open ahk_class #32770
}

Sleep, 3000

ControlSend, Button1, {Enter}, ahk_class #32770

Sleep, 5500
SetKeyDelay, 50
Send {l down}
Sleep,1000
Send {l up}

}

Link to comment
Share on other sites

I would do the following way.

1) Load a ini setting parameter to define the execution mode:

settingsFile := modulePath . "\" . moduleName . ".ini"
executionMode := IniReadCheck(settingsFile, "Settings|" . dbName, "Execution_Mode","Mode1",,1)

2) use the executionMode variable to define the execution:

if (executionMode="Mode2") {
  ;Do whatever you want for games listed on mode2
} else if (executionMode="Mode3") {
  ;Do whatever you want for games listed on mode3
} else {
  ;Do whatever you want for games listed on mode1
}

3) Them I would simply fill the settings.ini file with the games that do not use the default Mode1 execution (I would make sure that the Mode 1 is the more common one to save some of the ini editing required). Any games not listed on the ini file would make use of the mode1 execution.

settings.ini file

[Game1Name]
Execution_Mode=Mode2
[Game2Name]
Execution_Mode=Mode2
[Game3Name]
Execution_Mode=Mode3

Link to comment
Share on other sites

thank you

i actually worked on it before i had a chanced to see your post

thank you for your post

so what i ended up doing is making 4 different sections of the module

1 for each type of rom/system

each rom/game only works well being run under one specific system

the emulator emulates 4 systems

it doesnt really accept any command line stuff

so its all sends and clicks etc

BUT

what i could have done

because the rom names actually include the system that runs them

ie

combat_hector

combat_interact

combat_HR+

combat_HRX

as made up examples

maybe i should have said

if romName includes hector...load this way

if romName includes interact...load this way

if romName includes HR+ ...load this way

if romName includes HRX ... load this way

How would I do that in autohotkey? Specifically, the "if romName includes the term "interact"" portion of the idea?

thanks

craiganderson

see below for what i have done so far

and because autohotkey ControlClick has known issues of being unreliable i played with the setkeydelay

and used little loops to click things a few times to make sure clicks accepted

and on my system

it is working 100% perfectly!!!

ive tested it about a million times now

thanks

yMEmu = DCHector
MEmuV =  v0.1
MURL = http://dchector.free.fr/index.html#top
MAuthor = craiganderson
MVersion =1.1
MCRC = 
iCRC =
MID = 
MSystem = "Hector HRX"
;----------------------------------------------------------------------------
; Notes:
; This module uses a BlockInput command which on my computer requires hyperspin and xpadder to be run as administrator.
; If Emulator Language is French and you would like English: Go to Options>Paramatres and Click "Anglais".
; In Emulator, go to Options>Settings: Click "Fast input" under Tape. Seems like a good idea to me. Has not caused a problem on my system yet. 
; To Setup Keyboard/Joysticks: In Emulator, go to Options>Keyboard. But...Fyi....The DEFAULT joystick input is as follows (all on number pad):
;...........................Player 1..........Player 2
; Up........................Num5............Num/
; Down...................Num2............Num8
; Left.....................Num1.............Num7
; Right...................Num3.............Num9
; Button.................NumEnter......Num+
; Set fullscreen mode in Global Module Settings in HLHQ (and fullscreen equals maximized window because fullscreen emulator seems to act odd).
; Roms must be named exactly as they are referred to in module. This is because there are four ways (i.e. four systems) to load different roms and the module assigns the rom to the right loading process based upon its full name.
;----------------------------------------------------------------------------

StartModule()
BlockInput, On
FadeInStart()

7z(romPath, romName, romExtension, 7zExtractPath)

settingsFile := modulePath . "\" . moduleName . ".ini"
Fullscreen := IniReadCheck(settingsFile, "Settings", "Fullscreen","true",,1)

SetKeyDelay, 200

Run(executable, emuPath)

WinWait(" DCHector - Micronique Hector emulator ahk_class Hector")
WinWaitActive(" DCHector - Micronique Hector emulator ahk_class Hector")

Sleep, 100
WinMenuSelectItem, ahk_class Hector, , Options, Settings

WinWait(" DCHector settings ahk_class #32770")
WinWaitActive(" DCHector settings ahk_class #32770")

Sleep,2000

;These games are played via Hector 1 Computer
if (romName = "addition_hector1" or romName = "asteroides_hector1" or romName = "base_spatiale_hector1" or romName = "chatbyrinthe_hector1" or romName = "combat_hector1" or romName = "cow-boys_hector1" or romName = "crazy8_hector1" or romName = "credits-avec-imprimante_hector1" or romName = "credits-sans-imprimante_hector1" or romName = "dogfight_hector1" or romName = "encerclement_hector1" or romName = "envahisseurs_hector1" or romName = "flipper_hector1" or romName = "formule1_hector1" or romName = "galaxius_hector1" or romName = "goofygolf_hector1" or romName = "grenouille_hector1" or romName = "jeu-de-la-vie_hector1" or romName = "knockdown_hector1" or romName = "la-caverne-des-lutins_hector1" or romName = "le-baroudeur_hector1" or romName = "le-glouton_hector1" or romName = "le-pendu_hector1" or romName = "piranhas_hector1" or romName = "sous-marin_hector1")
{
Loop, 3
{
ControlClick, Button5,  DCHector settings
Sleep,500
}

Loop, 25
{
ControlClick, Button5,  DCHector settings
Sleep,10
}

Sleep, 1000

Loop,5
{
IfWinExist, DCHector settings ahk_class #32770
	{
   			Sleep, 100
  			ControlSend, Button31, {Enter}, DCHector settings ahk_class #32770
	}
}

Sleep,500

Loop,5
{
IfWinExist, DCHector Setting modification ahk_class #32770
	{
   			Sleep, 100
  			ControlSend, Button1, {Enter}, DCHector Setting modification ahk_class #32770
	}
}

Sleep, 500

WinWait(" DCHector - Micronique Hector emulator ahk_class Hector")
WinWaitActive(" DCHector - Micronique Hector emulator ahk_class Hector")
WinActivate,  DCHector - Micronique Hector emulator ahk_class Hector

Sleep,1000

WinMenuSelectItem, ahk_class Hector, , File, Load Tape

Sleep,3000

Loop 
{
	ControlGetText, edit1Text, Edit1, Open ahk_class #32770
	If ( edit1Text = romPath . "\" . romName . romExtension )
	Break
	Sleep, 200
	ControlSetText, Edit1, %romPath%\%romName%%romExtension%, Open ahk_class #32770
}

Sleep, 3000

Loop,5
{
IfWinExist, Open ahk_class #32770
	{
   			Sleep, 100
		ControlSend, Button1, {Enter}, Open ahk_class #32770	
	}
}

Sleep, 3000
SetKeyDelay, 50
Send {l down}
Sleep,1000
Send {l up}
}

;These games are played via Interact Computer
if (romName = "addemup_interact" or romName = "attro_logic_interact" or romName = "backgammon_interact" or romName = "blackjack_interact" or romName = "hangman_interact" or romName = "knockdown_interact")
{
Loop, 3
{
ControlClick, Button6,  DCHector settings
Sleep,500
}

Loop, 25
{
ControlClick, Button6,  DCHector settings
Sleep,10
}

Sleep, 1000

Loop,5
{
IfWinExist, DCHector settings ahk_class #32770
	{
   			Sleep, 100
  			ControlSend, Button31, {Enter}, DCHector settings ahk_class #32770
	}
}

Sleep,500

Loop,5
{
IfWinExist, DCHector Setting modification ahk_class #32770
	{
   			Sleep, 100
  			ControlSend, Button1, {Enter}, DCHector Setting modification ahk_class #32770
	}
}

Sleep, 500

WinWait(" DCHector - Micronique Hector emulator ahk_class Hector")
WinWaitActive(" DCHector - Micronique Hector emulator ahk_class Hector")
WinActivate,  DCHector - Micronique Hector emulator ahk_class Hector

Sleep,1000

WinMenuSelectItem, ahk_class Hector, , File, Load Tape

Sleep,3000

Loop 
{
	ControlGetText, edit1Text, Edit1, Open ahk_class #32770
	If ( edit1Text = romPath . "\" . romName . romExtension )
	Break
	Sleep, 200
	ControlSetText, Edit1, %romPath%\%romName%%romExtension%, Open ahk_class #32770
}

Sleep, 3000

Loop,5
{
IfWinExist, Open ahk_class #32770
	{
   			Sleep, 100
		ControlSend, Button1, {Enter}, Open ahk_class #32770	
	}
}

Sleep, 4000
SetKeyDelay, 50
Send {l down}
Sleep,1250
Send {l up}
}

;These games are played via Hector 2 HR+
if (romName = "stramble_hr" or romName = "jeep-lunaire_hr" or romName = "chenille_hr")
{
Loop, 3
{
ControlClick, Button7,  DCHector settings
Sleep,500
}

Loop, 25
{
ControlClick, Button7,  DCHector settings
Sleep,10
}

Sleep, 1000

Loop,5
{
IfWinExist, DCHector settings ahk_class #32770
	{
   			Sleep, 100
  			ControlSend, Button31, {Enter}, DCHector settings ahk_class #32770
	}
}

Sleep,500

Loop,5
{
IfWinExist, DCHector Setting modification ahk_class #32770
	{
   			Sleep, 100
  			ControlSend, Button1, {Enter}, DCHector Setting modification ahk_class #32770
	}
}

Sleep, 500

WinWait(" DCHector - Micronique Hector emulator ahk_class Hector")
WinWaitActive(" DCHector - Micronique Hector emulator ahk_class Hector")
WinActivate,  DCHector - Micronique Hector emulator ahk_class Hector

Sleep,1000

WinMenuSelectItem, ahk_class Hector, , File, Load Tape

Sleep,3000

Loop 
{
	ControlGetText, edit1Text, Edit1, Open ahk_class #32770
	If ( edit1Text = romPath . "\" . romName . romExtension )
	Break
	Sleep, 200
	ControlSetText, Edit1, %romPath%\%romName%%romExtension%, Open ahk_class #32770
}

Sleep, 3000

Loop,5
{
IfWinExist, Open ahk_class #32770
	{
   			Sleep, 100
		ControlSend, Button1, {Enter}, Open ahk_class #32770	
	}
}

Sleep, 3000
SetKeyDelay, 50
Send {1 down}
Sleep,1000
Send {1 up}
}


;These games are played via Hector 2 HRX
if (romName = "pengo_hrx" or romName = "hep-taxi_hrx")
{
Loop, 3
{
ControlClick, Button8,  DCHector settings
Sleep,500
}

Loop, 25
{
ControlClick, Button8,  DCHector settings
Sleep,10
}

Sleep, 1000

Loop,5
{
IfWinExist, DCHector settings ahk_class #32770
	{
   			Sleep, 100
  			ControlSend, Button31, {Enter}, DCHector settings ahk_class #32770
	}
}

Sleep,500

Loop,5
{
IfWinExist, DCHector Setting modification ahk_class #32770
	{
   			Sleep, 100
  			ControlSend, Button1, {Enter}, DCHector Setting modification ahk_class #32770
	}
}

Sleep, 500

WinWait(" DCHector - Micronique Hector emulator ahk_class Hector")
WinWaitActive(" DCHector - Micronique Hector emulator ahk_class Hector")
WinActivate,  DCHector - Micronique Hector emulator ahk_class Hector

Sleep,1000

WinMenuSelectItem, ahk_class Hector, , File, Load Tape

Sleep,3000

Loop 
{
	ControlGetText, edit1Text, Edit1, Open ahk_class #32770
	If ( edit1Text = romPath . "\" . romName . romExtension )
	Break
	Sleep, 200
	ControlSetText, Edit1, %romPath%\%romName%%romExtension%, Open ahk_class #32770
}

Sleep, 3000

Loop,5
{
IfWinExist, Open ahk_class #32770
	{
   			Sleep, 100
		ControlSend, Button1, {Enter}, Open ahk_class #32770	
	}
}

Sleep, 3000
SetKeyDelay, 50
Send {2 down}
Sleep,1000
Send {2 up}
}


If Fullscreen = true
{	
	Sleep,1250
	SetKeyDelay, 50
	;Send, {ALT down}{ENTER down}{ALT UP}{ENTER UP}
	WinMaximize,  DCHector - Micronique Hector emulator ahk_class Hector
}

Sleep, 500
BlockInput, Off

FadeInExit()
Process("WaitClose", executable)
7zCleanUp()
FadeOutExit()
ExitModule()

CloseProcess:
FadeOutStart()
  	Process, Close, dchector.exe  
Return

Link to comment
Share on other sites

if romName includes hector...load this way

if romName includes interact...load this way

if romName includes HR+ ...load this way

if romName includes HRX ... load this way

How would I do that in autohotkey? Specifically, the "if romName includes the term "interact"" portion of the idea?

thanks

craiganderson

http://www.autohotkey.com/docs/commands/IfIn.htm

http://www.autohotkey.com/docs/Functions.htm#InStr

About your solution, happy that you got it working. But if they are from different systems, you should use the systemName variable instead of looking for which system they are from on their file names.

Try to look at a multisystem module, like mess for an example on how to do it.

You should basically use conditionals like

if (systeName="Hector")

;dosomething

else if (systemName="HRX")

; do something

...

Link to comment
Share on other sites

My Bad for not explaining well

Different "systems" but emulated all within one emulator

Think Like hector, hector2, hector2+, hectorhxr kinda thing

So all use same emulator but NEED to have different button (hector, hector2, hector2+, hectorhrx) clicked for different roms

Sent from my Droid Mini.

Link to comment
Share on other sites

yes. But all relayed systems like msx msx2 msx2+ etc.

here is a picture of the settings popup from within the emulator

see under "computer" there are four choices

each game only works with one of those choices (of all related systems (like msx msx2 msx2+))

does not accept command line

so using clickcontrol to click different choices/system for different games

thank you very much for ur time and expertise

2014-06-16_6-44-20_zps2002c156.png

Sent from my Droid Mini.

Link to comment
Share on other sites

If you want to use them as a single system I would follow the suggestion that I gave to you on the first post.

Editing your module I would do something like this:

yMEmu = DCHector
MEmuV =  v0.1
MURL = http://dchector.free.fr/index.html#top
MAuthor = craiganderson
MVersion =1.1
MCRC = 
iCRC =
MID = 
MSystem = "Hector HRX"
;----------------------------------------------------------------------------
; Notes:
; This module uses a BlockInput command which on my computer requires hyperspin and xpadder to be run as administrator.
; If Emulator Language is French and you would like English: Go to Options>Paramatres and Click "Anglais".
; In Emulator, go to Options>Settings: Click "Fast input" under Tape. Seems like a good idea to me. Has not caused a problem on my system yet. 
; To Setup Keyboard/Joysticks: In Emulator, go to Options>Keyboard. But...Fyi....The DEFAULT joystick input is as follows (all on number pad):
;...........................Player 1..........Player 2
; Up........................Num5............Num/
; Down...................Num2............Num8
; Left.....................Num1.............Num7
; Right...................Num3.............Num9
; Button.................NumEnter......Num+
; Set fullscreen mode in Global Module Settings in HLHQ (and fullscreen equals maximized window because fullscreen emulator seems to act odd).
; Roms must be named exactly as they are referred to in module. This is because there are four ways (i.e. four systems) to load different roms and the module assigns the rom to the right loading process based upon its full name.
;----------------------------------------------------------------------------

StartModule()
FadeInStart()

7z(romPath, romName, romExtension, 7zExtractPath)

settingsFile := modulePath . "\" . moduleName . ".ini"
micronComputer := IniReadCheck(settingsFile, "Settings|" . dbName, "Micron_Computer","Hector1",,1) ;Hector1, Interact, Hector2HRp, Hector2HRX
Fullscreen := IniReadCheck(settingsFile, "Settings", "Fullscreen","true",,1)

SetKeyDelay, 200

BlockInput, On

Run(executable, emuPath)

WinWait(" DCHector - Micronique Hector emulator ahk_class Hector")
WinWaitActive(" DCHector - Micronique Hector emulator ahk_class Hector")

Sleep, 100
WinMenuSelectItem, ahk_class Hector, , Options, Settings

WinWait(" DCHector settings ahk_class #32770")
WinWaitActive(" DCHector settings ahk_class #32770")

Sleep,2000

if  (micronComputer="Interact")
CurrentButtom := "Button6"
else if  (micronComputer="Hector2HRp")
CurrentButtom := "Button7"	
else if (micronComputer="Hector2HRX")	
CurrentButtom := "Button8"	
else ;micronComputer="Hector1"
CurrentButtom := "Button5"

Loop, 3
{
ControlClick, %CurrentButtom%,  DCHector settings
Sleep,500
}
Loop, 25
{
ControlClick, %CurrentButtom%,  DCHector settings
Sleep,10
}
Sleep, 1000
Loop,5
{
IfWinExist, DCHector settings ahk_class #32770
{
		Sleep, 100
	ControlSend, Button31, {Enter}, DCHector settings ahk_class #32770
}
}
Sleep,500
Loop,5
{
IfWinExist, DCHector Setting modification ahk_class #32770
{
		Sleep, 100
	ControlSend, Button1, {Enter}, DCHector Setting modification ahk_class #32770
}
}
Sleep, 500
WinWait(" DCHector - Micronique Hector emulator ahk_class Hector")
WinWaitActive(" DCHector - Micronique Hector emulator ahk_class Hector")
WinActivate,  DCHector - Micronique Hector emulator ahk_class Hector
Sleep,1000
WinMenuSelectItem, ahk_class Hector, , File, Load Tape
Sleep,3000
Loop 
{
ControlGetText, edit1Text, Edit1, Open ahk_class #32770
If ( edit1Text = romPath . "\" . romName . romExtension )
Break
Sleep, 200
ControlSetText, Edit1, %romPath%\%romName%%romExtension%, Open ahk_class #32770
}
Sleep, 3000
Loop,5
{
IfWinExist, Open ahk_class #32770
{
		Sleep, 100
	ControlSend, Button1, {Enter}, Open ahk_class #32770	
}
}
Sleep, 4000
SetKeyDelay, 50

if (micronComputer="Hector2HRX"){
Send {2 down}
Sleep,1225
Send {2 up}
} else {
Send {l down}
Sleep,1225
Send {l up}	
}


If Fullscreen = true
{	
	Sleep,1250
	SetKeyDelay, 50
	;Send, {ALT down}{ENTER down}{ALT UP}{ENTER UP}
	WinMaximize,  DCHector - Micronique Hector emulator ahk_class Hector
}

Sleep, 500
BlockInput, Off

FadeInExit()
Process("WaitClose", executable)
7zCleanUp()
FadeOutExit()
ExitModule()

CloseProcess:
FadeOutStart()
  	Process, Close, dchector.exe  
Return

and include on the same folder this ini file with the filename equal to your module name:

[addemup_interact]
Micron_Computer=Interact

[attro_logic_interact]
Micron_Computer=Interact

[backgammon_interact]
Micron_Computer=Interact

[blackjack_interact]
Micron_Computer=Interact

[hangman_interact]
Micron_Computer=Interact

[knockdown_interact]
Micron_Computer=Interact



[stramble_hr]
Micron_Computer=Hector2HRp

[jeep-lunaire_hr]
Micron_Computer=Hector2HRp

[chenille_hr]
Micron_Computer=Hector2HRp



[pengo_hrx]
Micron_Computer=Hector2HRX

[hep-taxi_hrx]
Micron_Computer=Hector2HRX

#no need for settings games that follows the default micron computer Hector1: addition_hector1, asteroides_hector1, base_spatiale_hector1, chatbyrinthe_hector1, combat_hector1, cow-boys_hector1, crazy8_hector1, credits-avec-imprimante_hector1,credits-sans-imprimante_hector1, dogfight_hector1, encerclement_hector1, envahisseurs_hector1, flipper_hector1, formule1_hector1, galaxius_hector1, goofygolf_hector1, grenouille_hector1, jeu-de-la-vie_hector1, knockdown_hector1, la-caverne-des-lutins_hector1, le-baroudeur_hector1, le-glouton_hector1, le-pendu_hector1, piranhas_hector1, sous-marin_hector1

I hope it works for you. But you do some things that makes it very difficult to work on other users computers.

- You use a lot of sleep commands. This must be avoid and used only at last resort as it is very computer dependable.

- You seam to use loops to assure that you select the options that you are trying to set. This is not a good practice also.

Link to comment
Share on other sites

thanks

the sleep commands sometimes seem to be needed when everything is manual (click, send etc)

[and i have a pretty good/fast /new computer]

without them sometimes gets hung up

i read that controlclick and controlsend etc are inherently unreliable and that is a known issue with ahk...

so i used the loops to make sure right box gets clicked

but i have not seen it cause a problem yet

i realize the loops are sort of overkill but do u think they might cause a problem? they havent yet but im not an expert..

without them i noticed that with the same exact game/same exact system sometimes the box would get clicked, sometimes it would NOT and on other forums its seems that this is a known issue with those commands being unreliable,......with the short little loops (like 5) this has gone away completely>>>>

i tried to use more complicated

combinations of

ifwinexist and ifwinnotexist to "reclick if needed"

but it kept getting hung up

im still learning

thanks

Link to comment
Share on other sites

- About the loops

Did you tested if controlGet (http://www.autohotkey.com/docs/commands/ControlGet.htm) works to retrieve the emulator micron computer button setting?

If yes you can use a loop that only exits when the controlGet have the desired value set, instead of using a predefined number of iterations on the loop.

You could also use the errorlevel value set by the controlClick command to know if the command was sucessful or not to know if you have to try it again.

Also, did you tried to use a postmessage command instead? Something like this http://www.autohotkey.com/board/topic/96952-possible-controlclick-improve/

Using postmessages is much more reliable than any alternative.

- About the sleeps

Using ways to check if the controls changed, or if the correct window is active before sending a command is much better than using the sleeps top wait for the windows.

If the controlGet gives you the info about the button5, 6, ... state or if you actually use the errorLevel info you don't need a sleep to wait for it to change.

If you use correctly the winwait or winexist commands, you don't need sleeps for assure that these windows were created before sending your key presses.

And so on.

Just try to check, one at time, if you can do the same thing that you are currently achieving on your module, by using the commands that I mentioned above intead of pre defined loop interactions or sleeps. If you get ride of at least a few of the sleeps that you use you will have a much more reliable and fast module.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...