PDA

View Full Version : AHK mapping keys problem



MiTKiNG
03-16-2011, 09:38 AM
Hi everyone,

i have some ahk scripting problem. Lets see if anyone can give me a hand on this. Im using the new HL2.0 and i have a module for runing pc games. Like each pc game is a world by itself, i have done an if else statements for doing specific things per game based.

For launching a lnk without doing anything else im doing this:



Run,%romPath%%romName%
ExitApp


So, for doing specific things im doing this:



if (romName="House of the Dead 3") {
} else if (romName="Crazy Power Disc Perfect") {
} else if (romName="Street Fighter IV") {
} else {
}


Everything is right and working. But my problem is when i remap keys in one of the ifs statements. The remaped keys are always trigered when launching a pc game. If i do this:



if (romName="House of the Dead 3") {
1::Enter
w::g
e::h
r::j
t::k
} else if (romName="Crazy Power Disc Perfect") {
} else if (romName="Street Fighter IV") {
} else {
}


and i launch street fighter 4, the house of the dead keys assigment has done and thats not what i want. Moreover if i define the same mapping in other if statement, ahk gives me an error of a duplicate assignment.

This is giving an assignment error:



if (romName="House of the Dead 3") {
1::Enter
w::g
e::h
r::j
t::k
} else if (romName="Crazy Power Disc Perfect") {
1::l
} else if (romName="Street Fighter IV") {
t::p
} else {
}


I hope have explained myself. Do you know how to solve this?

Thank you in advance!

blur
03-17-2011, 01:51 AM
You have the answer in your question.

From your explanation I would guess this is what happens:

When ahk starts it scans your whole script and finds all lines with patern:
*::*
and forces all the mappings regardless of their position between if statements.


to make translations that depends on window you can use:
#ifwinactive window_name
..::..
#ifwinactive

you will have to find window names or class names of your games with win spy

or you can use something similar that does care about if statements and gives you translation and that is hotkey statement


for example:
if ...
Hotkey Esc ExitApp
else if
...
else if
...


:ExitApp
Send Esc
return

check my scripts for examples
maybe i will have to check my script also to make sure i never use *::* cause i also did not know about this peculiar behavior before

ahk is funny thing, it is very powerful and you can do wonders with it but also there are some so stupid limits, so most of the time you write scripts you spend working around these limits - like ahk can't send gamepad buttons, ahk can't stop gamepad buttons, ahk can't see gamepad buttons in keys history, and so on, thousands of limits, you just bump into them as you go :)

MiTKiNG
03-17-2011, 02:47 AM
Thats exactcly my problem and what you suggested works really great.

Thank you very much as allways blur ;)

Congui
03-17-2011, 07:29 AM
I also had that same problem, the only solution I found was to use a custom build called AutoHotkey_L. You can get it at: http://www.autohotkey.net/~Lexikos/AutoHotkey_L/#Get_It

With this build you have the IF# expression. This way I can map a key differently for various games. For example:
#if (Game = "Queen of Heart 2001")
{
lctrl::n
lalt::m
space::.
r::t
f::g
d::f
g::h
a::z
s::x
q::c
}
#if (Game = "Queen of Heart 99")
{
lctrl::z
lalt::x
space::c
r::i
f::k
d::j
g::l
;a::a
;s::s
q::d
}

As you can see, Queen of Hearts 2001 and Queen of Hearts 99 (both doujin games) have different mappings, so my doujin.ahk script assigns a different mapping to the same keys.

Of course, this being a custom build, it has minor sintax differences with the original build. I found this when I compiled Hyperlaunch, and had the following error: Make sure your paths contain a backslash on the end. You can see the following post: http://www.hyperspin-fe.com/forum/showthread.php?t=10081

Hope this helps.

Cheers,
Congui

MiTKiNG
03-17-2011, 08:08 AM
Congui your information is much appreciated but im using hyperlaunch 2.0 which uses ahk scripts directly and you dont need to compile. I dont know if you are using HL2.0 but for the information that blur has give us, you dont need to use a modded build of ahk.

I have just tried what blur suggested and works really great. Your code would be like this, using blur suggestion:



if (Game = "Queen of Heart 2001")
{
#ifwinactive window_name
lctrl::n
lalt::m
space::.
r::t
f::g
d::f
g::h
a::z
s::x
q::c
#ifwinactive
}
else if (Game = "Queen of Heart 99")
{
#ifwinactive window_name
lctrl::z
lalt::x
space::c
r::i
f::k
d::j
g::l
;a::a
;s::s
q::d
#ifwinactive
}


With this solution you only need to know the window_name for your games: Queen of Heart 2001 and Queen of Heart 99.

As blur said, you can acomplish this with win spy (i havent use it, because i had the window_name of my pc games).

Is the window name, the name that you see when use ALT+TAB on windows? Im not sure of this.

Congui, try this with an original ahk compiler if you want, and tell us results.