Hello,
I've been coding a script that uses multiple instances of Shaiya windows, problem is that when I set focus to one, and press Enter, the other window also receives the message. I've noticed this occurs with shaiya even if you use any other application.
If their any way of preventing both windows from receiving the Enter keypress?
Here is a code sample to demonstrate what I mean.. You need the Shaiya bomber.exe multiclient.
function get_windows(win_name)
local l_windows = findWindowList(win_name);
local l_new_win_name;
for i, win in pairs(l_windows) do
printf("Found window %x [%s]\n", win, getWindowName(win));
l_new_win_name = win_name .. "_" .. i;
setWindowName(win, l_new_win_name);
end
return l_windows;
end
function enter_msg(win, msg)
showWindow(win, sw.shownormal);
yrest("2000");
attach(win)
keyboardPress(key.VK_ENTER);
keyboardPress(key.VK_BACK);
keyboardPress(key.VK_BACK);
keyboardType(msg);
keyboardPress(key.VK_ENTER);
detach();
end
function main()
local wins = get_windows("Shaiya");
while(true) do
enter_msg(wins[1], "@ test 1");
enter_msg(wins[2], "@ test 2");
coroutine.yield();
end
end
startMacro(main);
As far as I know, there's nothing that can be done about it. It should be considered a bug in Shaiya and fixed. Like you said, it happens even if you press enter in a whole other window. I'm guessing that this is because they used GetKeyState()/GetAsyncKeyState() where they shouldn't have.
I suppose you could hook GetKeyState()/GetAsyncKeyState() and have it return false if the correct window is not on top. If you can find a way to get the correct HWND of the main window of the current thread, then this will be pretty easy.
Rather than manipulate the binary (which can be difficult -- especially in this case), I've started writing a DLL which can be injected, and overrides GetAsyncKeyState().
It is now officially working. Download hook_GetAsyncKeyState.dll and put it in micromacro/data folder. You will then use the shaiya_launcher.lua to launch the game and inject the DLL. You will need the injector plugin to use this (just place injector.dll into the plugins folder).
Make note that the window will be locked onto after ~30 seconds of starting the game. This is to give ample time for the game windows to gain focus, and selected properly. By the time you get your first client in game, it should be ready to start the second client. You must not switch windows until after it has locked on, otherwise it may target the wrong window. Yeah, it's a hackish little trick, but it works.
local success = inject(findWindow("Shaiya"), getPath() .. "/data/hook_GetAsyncKeyState.dll");
if( success == false ) then
printf("Injecting has failed.\n");
end
zerosignal: Try injecting this version of the DLL, then post your hooklog.txt here. You will find this file in the Shaiya folder after injecting (or, attempting to, rather).
Hey, Shaiya is now running and it looks like from the log that it's hooking. But it's not working on Vista. I tried it both in native Vista, and win xp compatibility.
edit: in another test. the "hooklog.txt" said "Locking onto window: 0x1f0096" but when I use the findWindow("Shaiya") function it returns decimal: 2229416 or 0x2204A8. Should they be the same values?
Is it hooking into the wrong process?
I've disabled window previewing so it shouldn't be that annoying issue.
Can you define "not working"? Do you mean it starts, but does not prevent outside input from effecting Shaiya? Or do you mean that once it locks onto the window, you cannot input any method? And yes, it should give the same HWND. I might've created a bug somehow, so it may not be on your end.
Ok, lets try this again. This time I tested to make sure it worked (at least under XP) before I uploaded it. In the last version, it was not hooking the address (hence, not effecting the game in any way).
I was able to successfully accomplish this using autoit script, and I've never run into any problems with inactive game windows receiving keystrokes.
I can switch between up to 3 characters on the same computer (if I run 4 clients things get unstable for some reason), and sending keystrokes to any single clients does not affect the inactive clients.
Why would I not have the same issue that you guys do if it is a game bug?