MM doesn't react on Start-Key

Discuss, ask for help, share ideas, give suggestions, read tutorials, and tell us about bugs you have found with MicroMacro in here.

Do not post RoM-Bot stuff here. There is a subforum for that.
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.
Post Reply
Message
Author
aliex
Posts: 12
Joined: Thu Feb 10, 2011 6:54 am

MM doesn't react on Start-Key

#1 Post by aliex » Wed Aug 14, 2013 2:16 pm

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?

User avatar
Administrator
Site Admin
Posts: 5307
Joined: Sat Jan 05, 2008 4:21 pm

Re: MM doesn't react on Start-Key

#2 Post by Administrator » Wed Aug 14, 2013 2:42 pm

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?

aliex
Posts: 12
Joined: Thu Feb 10, 2011 6:54 am

Re: MM doesn't react on Start-Key

#3 Post by aliex » Wed Aug 14, 2013 11:57 pm

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?
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.
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.

User avatar
Administrator
Site Admin
Posts: 5307
Joined: Sat Jan 05, 2008 4:21 pm

Re: MM doesn't react on Start-Key

#4 Post by Administrator » Thu Aug 15, 2013 6:08 pm

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:

Code: Select all

	if fw ~= getHwnd() and ( ah == 0 or fw ~= ah ) then
Removing "ah == 0 or" from that line should do the trick.

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: MM doesn't react on Start-Key

#5 Post by rock5 » Fri Aug 16, 2013 4:42 am

Administrator wrote:Removing "ah == 0 or" from that line should do the trick
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.

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

User avatar
Administrator
Site Admin
Posts: 5307
Joined: Sat Jan 05, 2008 4:21 pm

Re: MM doesn't react on Start-Key

#6 Post by Administrator » Fri Aug 16, 2013 4:28 pm

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.

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: MM doesn't react on Start-Key

#7 Post by rock5 » Sat Aug 17, 2013 1:39 am

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

User avatar
Administrator
Site Admin
Posts: 5307
Joined: Sat Jan 05, 2008 4:21 pm

Re: MM doesn't react on Start-Key

#8 Post by Administrator » Sat Aug 17, 2013 2:31 pm

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.

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: MM doesn't react on Start-Key

#9 Post by rock5 » Sat Aug 17, 2013 4:13 pm

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

aliex
Posts: 12
Joined: Thu Feb 10, 2011 6:54 am

Re: MM doesn't react on Start-Key

#10 Post by aliex » Mon Aug 19, 2013 2:37 pm

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:

Code: Select all

	if fw ~= getHwnd() and ( ah == 0 or fw ~= ah ) then
Removing "ah == 0 or" from that line should do the trick.
Line 492 reads now:

Code: Select all

if fw ~= getHwnd() and ( fw ~= ah ) then
as mentioned above but i still need to focus the MM command-window to stop the script. :?

User avatar
Administrator
Site Admin
Posts: 5307
Joined: Sat Jan 05, 2008 4:21 pm

Re: MM doesn't react on Start-Key

#11 Post by Administrator » Wed Aug 21, 2013 2:05 pm

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:

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
function targetWindow() added and function checkGlobalHotkeys() replaced.

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]]
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:

Code: Select all

targetWindow(findWindow("The game"));
function main()
...
end

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests