MM doesn't react on Start-Key
Forum rules
This is a sub-forum for things specific to MicroMacro.
This is not the place to ask questions about the RoM bot, which uses MicroMacro. There is a difference.
This is a sub-forum for things specific to MicroMacro.
This is not the place to ask questions about the RoM bot, which uses MicroMacro. There is a difference.
MM doesn't react on Start-Key
Hello! I got a problem using the latest MM version 1.03. MM doesn't recognize when i press the Start or Stop Button unless i activate the window. This is new, 1.02 did so. I am not able to deactivate the running macro when i use the screen the game is running. I got 2 Monitors, the problem occured also when i use the MM window on the same screen as the game.
Help, anyone?
Help, anyone?
- Administrator
- Site Admin
- Posts: 5329
- Joined: Sat Jan 05, 2008 4:21 pm
Re: MM doesn't react on Start-Key
Let me see if I understand you correctly. You are saying that when you are using MicroMacro in attached mode, it doesn't detect start/stop hotkeys when the target window is focused? That is, for the RoM bot, if you have RoM on top and press F5, it doesn't start?
When you upgraded, did you copy all files and not just micromacro.exe?
When you upgraded, did you copy all files and not just micromacro.exe?
Re: MM doesn't react on Start-Key
Its not the RomBot and i didn't attach the target window. I tried to use the standard F5 key also, doesn't work either.Administrator wrote:Let me see if I understand you correctly. You are saying that when you are using MicroMacro in attached mode, it doesn't detect start/stop hotkeys when the target window is focused? That is, for the RoM bot, if you have RoM on top and press F5, it doesn't start?
When you upgraded, did you copy all files and not just micromacro.exe?
The Problem is occuring even before the macro is running. I am forced to klick in the command window of MM to start it. When the window is not activated MM doesn't react to F5 or any other defined Start-Key.
And yes, i did a clean installement, including the complete micromacro dir. I just included my scripts dir in the new installement.
[Edit] I tried to run the Game in Window and Fullscreen Mode. No Difference. I am using a Bot which controls also the mouse and now, when the bot is running, i cant stop the macro at all since i cant move the mouse to the command window of MM, focus it, and press the pause/stopp button. this is really really bad, i really need help in that case.
- Administrator
- Site Admin
- Posts: 5329
- Joined: Sat Jan 05, 2008 4:21 pm
Re: MM doesn't react on Start-Key
I think this was disabled when updating to Lua 5.2. I don't remember the exact reasons for it, though.
You can edit your lib/lib.lua, line 492 to change this:
Removing "ah == 0 or" from that line should do the trick.
You can edit your lib/lib.lua, line 492 to change this:
Code: Select all
if fw ~= getHwnd() and ( ah == 0 or fw ~= ah ) then
Re: MM doesn't react on Start-Key
But doesn't that mean that no matter what program is the active window, if you press the 'stop' key it will stop the bot? So if you are using some other program or application that uses the same key combination, eg. F6, you can unknowingly cause the bot to stop. I think that was the reason we added that. You could also accidentally stop other running bots that are running. The problem is if MM isn't attached then it can't know which program it is associated with.Administrator wrote:Removing "ah == 0 or" from that line should do the trick
I wonder if we could check an associated window anyway. Example, with rombot, even if we were to detach from the game for whatever reason or not attach at all like with getid and getpos, we would still know which window we are associated with because of the __WIN and __PROC variables. I'm not sure how we could make it work, maybe an MM global variable or a function, but it should be possible. Then we coul have the keys check check the associated window as well.
- Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
- I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
- How to: copy and paste in micromacro
________________________
Quote:- “They say hard work never hurt anybody, but I figure, why take the chance.”
- Ronald Reagan
- Administrator
- Site Admin
- Posts: 5329
- Joined: Sat Jan 05, 2008 4:21 pm
Re: MM doesn't react on Start-Key
I agree. I don't want to make that specific change due to those exact reasons. I guess we could add a function (targetWindow() or something similar?) that will set the HWND of a specific window to also check against hotkeys but without attaching to it. Basically, attach() without the keyboard/mouse hooks.
Re: MM doesn't react on Start-Key
So after we set the target you would do something like?
Code: Select all
local check = true;
local ah = getAttachedHwnd();
local fw = foregroundWindow();
local tw = getTargetWindow()
if fw ~= getHwnd() and ( ah == 0 or fw ~= ah ) and (tw == 0 or fw ~= tw) then
check = false;
end
- Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
- I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
- How to: copy and paste in micromacro
________________________
Quote:- “They say hard work never hurt anybody, but I figure, why take the chance.”
- Ronald Reagan
- Administrator
- Site Admin
- Posts: 5329
- Joined: Sat Jan 05, 2008 4:21 pm
Re: MM doesn't react on Start-Key
Something like that, yeah. It could probably all just be done in lib.lua, using a local variable, so we wouldn't even need the getTargetWindow() function.
Re: MM doesn't react on Start-Key
I get it. Use the targetwindow function to set a variable and then just use the variable.
- Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
- I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
- How to: copy and paste in micromacro
________________________
Quote:- “They say hard work never hurt anybody, but I figure, why take the chance.”
- Ronald Reagan
Re: MM doesn't react on Start-Key
Line 492 reads now:Administrator wrote:I think this was disabled when updating to Lua 5.2. I don't remember the exact reasons for it, though.
You can edit your lib/lib.lua, line 492 to change this:
Removing "ah == 0 or" from that line should do the trick.Code: Select all
if fw ~= getHwnd() and ( ah == 0 or fw ~= ah ) then
Code: Select all
if fw ~= getHwnd() and ( fw ~= ah ) then

- Administrator
- Site Admin
- Posts: 5329
- Joined: Sat Jan 05, 2008 4:21 pm
Re: MM doesn't react on Start-Key
Well I found the problem and it is because I overlooked one simple thing: keyboardState() will only grab data from the application's keyboard state and any attached inputs; it will not poll the hardware directly.
I guess there's two things that could be done: go back to using keyPressed() for each key, or look into using some other function for polling the keyboard. Microsoft's Win32 implementation of GetKeyboardState() is buggy, anyways, so I'm not against abandoning it, however I don't want to rely on any big libraries, either.
Here's a (somewhat heavy) modification to lib.lua:
function targetWindow() added and function checkGlobalHotkeys() replaced.
Line ~641:
Comment out the two lines below the while( true ) by adding '--' in front of them.
Now after these modifications, call targetWindow() outside of main() in your script, like so:
I guess there's two things that could be done: go back to using keyPressed() for each key, or look into using some other function for polling the keyboard. Microsoft's Win32 implementation of GetKeyboardState() is buggy, anyways, so I'm not against abandoning it, however I don't want to rely on any big libraries, either.
Here's a (somewhat heavy) modification to lib.lua:
Code: Select all
-- Set a target window that we check for hotkeys from
-- but do not attach to it.
local __targetWindow = nil;
function targetWindow(hwnd)
__targetWindow = hwnd;
end
-- Get debug information from any running script
--[[
local script_line = 0;
local script_name = "";
local function get_script_info(event, line)
script_line = line;
script_name = debug.getinfo(2).short_src;
end
debug.sethook(get_script_info, "l");
]]
local ks = keyboardState();
local lastKS = ks;
local function checkGlobalHotkeys()
local script_status = 'ok';
local function pressed(vk)
if( ks[vk] and not lastKS[vk] ) then
return true;
else
return false;
end
end
lastKS = table.copy(ks);
local check = true;
local ah = getAttachedHwnd();
local fw = foregroundWindow();
if fw ~= getHwnd() and ( ah == 0 or fw ~= ah ) and (__targetWindow and __targetWindow ~= fw) then
check = false;
end
if( check ) then
ks[startKey] = keyPressed(startKey);
ks[stopKey] = keyPressed(stopKey);
ks[key.VK_L] = keyPressed(key.VK_L);
ks[key.VK_CONTROL] = keyPressed(key.VK_CONTROL);
if( not __PErunning and pressed(startKey)) then
script_status = 'start';
elseif( __PErunning and pressed(stopKey) ) then
script_status = 'stop';
elseif( ks[key.VK_CONTROL] and pressed(key.VK_L) ) then
script_status = 'kill';
end
else
ks[startKey] = false;
ks[stopKey] = false;
ks[key.VK_L] = false;
ks[key.VK_CONTROL] = false;
end
return script_status;
end
Line ~641:
Code: Select all
while( true ) do
--lastKS = ks;
--ks = keyboardState();
local script_status = checkGlobalHotkeys();
--[[if( script_status ~= 'ok' ) then
print("Status", script_status);
end]]
Now after these modifications, call targetWindow() outside of main() in your script, like so:
Code: Select all
targetWindow(findWindow("The game"));
function main()
...
end
Who is online
Users browsing this forum: No registered users and 3 guests