Disabling windows hotkeys

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
ZZZZZ
Posts: 507
Joined: Sun Oct 21, 2012 1:42 am

Disabling windows hotkeys

#1 Post by ZZZZZ » Fri Jun 05, 2015 7:32 pm

Just wondering, is it possible to change windows shortcut keys with Micromacro? For example, I use F1-F4 as hotkeys in most games and in ArcheAge alt is the self-cast key, which unfortunately becomes an issue when wanting to use alt-F4 to self cast.

I know that it's possible to use autohotkey to disable it but I don't really want to run/install more programs than I have to.

Any info would be great :)

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

Re: Disabling windows hotkeys

#2 Post by Administrator » Fri Jun 05, 2015 11:05 pm

Not at the time it isn't. Can you say how you would disable a hotkey with AHK? I wonder if they are using keyboard hooks, or if they are using the registry to disable everything.

ZZZZZ
Posts: 507
Joined: Sun Oct 21, 2012 1:42 am

Re: Disabling windows hotkeys

#3 Post by ZZZZZ » Sat Jun 06, 2015 4:07 am

Truth be told I havn't actually tried using it myself, I was just going off what was said on a WoW forum, somebody had basically the same issue as I am.

http://us.battle.net/wow/en/forum/topic/2030264429

For now I have downloaded Sharpkeys. I'll try just disabling alt-F4 for now, but ultimately I was hoping I could make it so it was only disabled while playing ArcheAge etc.

http://www.randyrants.com/sharpkeys/

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

Re: Disabling windows hotkeys

#4 Post by Administrator » Sat Jun 06, 2015 11:30 pm

I'm looking into it but having some difficulties. As per usual, the documentation provided by Microsoft is poor. I think I might need to create another fake thread just to respond to some message which would then allow the hook I have in place to work correctly, because as of right now it's timing out and unhooking itself. Basically, it's being a pain and I've got to just guess what the problem is.

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

Re: Disabling windows hotkeys

#5 Post by Administrator » Mon Jun 08, 2015 1:09 am

Got some good news. It was quite a brainteaser trying to figure how to to not lock the input chain and pass information around as it would need to be, but I've got something that seems to work reasonably well.

Your script will need to make use of a callback function. The callback function can then select which keys to ignore and which not to. Keep in mind, once the script terminates, the hook is automatically removed.

So, lets move on with an example. This will disable the Windows keys from doing anything:

Code: Select all

function hook(vk)
	if( vk == key.VK_LWIN or vk == key.VK_RWIN ) then
		return true; -- Ignore the LWIN/RWIN keys
	else
		return false; -- Let the key go through
	end
end

function macro.init()
	keyboard.setHookCallback(hook);
end


function macro.main(dt)
	return true;	-- Keep running until we say otherwise.
end
From the documentation on this new function:

Code: Select all

/*	keyboard.setHookCallback(nil|function callback)
	Returns:	boolean

	Attempt to install a keyboard hook. The callback should be a function
	that accepts a single number: the virtual key code.
	If the callback returns true, the key will be dropped.
	If the callback returns false or nil, the input be left in the queue.

	If you pass nil as the callback, the keyboard hook will instead
	be removed.

	Please note that your callback function should return almost immediately
	so you aren't clogging up the input system.
	Your main function must also execute quickly (so don't use any rests!).
	Failure to execute quickly may lead to dropped or lagged user input.
*/

As of right now, this function is only available on the experimental branch. I'll also attach the binary so that you can test it without having to figure out how to compile it yourself.
Attachments
micromacro.1.92.45_x86.zip
keyboard.setHookCallback() function added; MicroMacro 1.92.45a experimental binary
(744.17 KiB) Downloaded 31 times

ZZZZZ
Posts: 507
Joined: Sun Oct 21, 2012 1:42 am

Re: Disabling windows hotkeys

#6 Post by ZZZZZ » Wed Jun 10, 2015 9:33 am

Ok that's cool. Good to be able to completely disable a key on command.

The problem with it though is not that I want to disable to actual key, but I want to disable the actual alt-f4 windows shortcut that closes applications. I still want to be able to use alt (self-cast) + f4 (spell hotkey) while ingame. Not sure if its at all possible without editing the registry though.

I guess could always make it so while the game is in the foreground, the F4 key could be replaced with a different hotkey instead. Say make it so that when F4 is pressed by the user, MM actually sends SHIFT+ALT+P or something instead.

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

Re: Disabling windows hotkeys

#7 Post by Administrator » Wed Jun 10, 2015 11:56 am

You can do that. Just need to put the logic into the callback.

Code: Select all

function keyboardHook(vk)
    if( window.getFocusHwnd() == _game_client_window ) then
        if( vk == key.VK_F4 and keyboard.isDown(key.VK_ALT) ) then
            return true;
        end
    end

    return false;
end
This should only ignore the F4 key (and hence disabling the ALT+F4 combo) when the client window is selected and the user is holding ALT.

ZZZZZ
Posts: 507
Joined: Sun Oct 21, 2012 1:42 am

Re: Disabling windows hotkeys

#8 Post by ZZZZZ » Thu Jun 11, 2015 8:34 pm

Administrator wrote: This should only ignore the F4 key (and hence disabling the ALT+F4 combo) when the client window is selected and the user is holding ALT.
I knew I would be able to do that. What i'm wondering is, would MM be able to disable the shortcut function, not the actual keys? I want to be able to use the ALT key with the F4 key while in game, but I don't want the windows alt-f4 function kicking in and trying to close the client when I do.
I'm just going to use the hook to make F4 send a different set of keys in its place. Will have the same effect.

User avatar
lisa
Posts: 8330
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: Disabling windows hotkeys

#9 Post by lisa » Thu Jun 11, 2015 8:52 pm

from what I can gather you don't actually want to use alt and f4 at the same time, it just happens from time to time. So in the hook if MM detects that Alt is pressed when F4 is pressed tell it to release Alt and then press F4 for you.
Remember no matter you do in life to always have a little fun while you are at it ;)

wiki here http://www.solarstrike.net/wiki/index.php?title=Manual

ZZZZZ
Posts: 507
Joined: Sun Oct 21, 2012 1:42 am

Re: Disabling windows hotkeys

#10 Post by ZZZZZ » Thu Jun 11, 2015 9:26 pm

lisa wrote:from what I can gather you don't actually want to use alt and f4 at the same time, it just happens from time to time. So in the hook if MM detects that Alt is pressed when F4 is pressed tell it to release Alt and then press F4 for you.
No no. In ArcheAge the 'self-cast' key is Alt. So in order to self cast, say, Resurgence (the main healing spell) I have to hold Alt and press the hotkey related to the skill I want to cast.
In MMO's I got into a habit of using F1 - F4 for primary healing spells. Which becomes an issue when I try to self cast the skill on F4 (I have put the least used skill on F4, but it would be great to be able to use it without the game trying to close).

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

Re: Disabling windows hotkeys

#11 Post by Administrator » Fri Jun 12, 2015 12:55 am

Oh. I see. In that case, I think that would be a limitation of the game itself, in which case there's nothing I can do to help you. It would require modification of the game's files.

ZZZZZ
Posts: 507
Joined: Sun Oct 21, 2012 1:42 am

Re: Disabling windows hotkeys

#12 Post by ZZZZZ » Fri Jun 12, 2015 1:51 am

Uhh what? I'm still not sure you understand what I was saying. In the original question I was asking if you can actually disable the windows OS hotkey (Alt-F4) that closes applications. I'm not asking to change or adjust anything in game, i'm simply wondering if you can actually disable or modify the OS hotkey with MicroMacro.

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

Re: Disabling windows hotkeys

#13 Post by Administrator » Fri Jun 12, 2015 7:13 pm

No, I understood you. The issue is that that's not entirely a Windows thing. Or, at least, not in the way you're thinking. It typically sends that message to the event queue of the receiving application to process, and that handles it accordingly.

So the problem here is that the game's code is what checks to see if you're using those hotkeys and then closes the game. Not Windows. So, you would have to interrupt one of those keys to get the other to go through without triggering the close command.

ZZZZZ
Posts: 507
Joined: Sun Oct 21, 2012 1:42 am

Re: Disabling windows hotkeys

#14 Post by ZZZZZ » Sat Jun 13, 2015 1:03 am

Ahh ok, my apologies :) I was assuming it was a windows OS function in itself because pretty much everything can be closed with it.

In regards to the keyboard hook, the function only accepts true false or nil. Is it possible to instead use it to return a key or set of keys to press rather than, in my case, F4?

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

Re: Disabling windows hotkeys

#15 Post by Administrator » Sat Jun 13, 2015 10:35 am

Well, yes and no. You can use keyboard.press() or virtualPress() inside of it and return true so it eats the original key. You could not modify the key inside the hook though, as you would be working with a copy of the data and not the original.

And to clarify what I said before, it's not that each process checks for the ALT+F4 hotkeys, but rather that Windows detects that and sends a close event message to the process. The process then accepts the close event and triggers the process of cleaning up and closing itself. To trap and ignore the close event message would require modification in a way that would likely get you caught by GameGuard.

ZZZZZ
Posts: 507
Joined: Sun Oct 21, 2012 1:42 am

Re: Disabling windows hotkeys

#16 Post by ZZZZZ » Sat Sep 16, 2017 5:35 am

Hey Admin,

Sorry for reviving an old topic! I was just wondering if you could also add a similar hook for mouse keys? I tried transplanting the keyboard hook function into the mouse_lua.cpp file and attempted to change all the necessary stuff... but yeh, obviously I have no idea what I am doing haha.

Reason: I have been playing a lot of PUBG lately and to use iron sights you have to click to enter, click again to exit. I am so used to games like CoD and Battlefield where I hold down the key to iron sights that I keep stuffing it up in tense situations... usually resulting in me missing everything :roll:

So basically just want to make it so when I hold right mouse button, MM will send a click instead and when I release the key, it'll send another click.

Thanks

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

Re: Disabling windows hotkeys

#17 Post by Administrator » Sun Oct 01, 2017 2:41 pm

ZZZZZ wrote:Hey Admin,

Sorry for reviving an old topic! I was just wondering if you could also add a similar hook for mouse keys? I tried transplanting the keyboard hook function into the mouse_lua.cpp file and attempted to change all the necessary stuff... but yeh, obviously I have no idea what I am doing haha.

Reason: I have been playing a lot of PUBG lately and to use iron sights you have to click to enter, click again to exit. I am so used to games like CoD and Battlefield where I hold down the key to iron sights that I keep stuffing it up in tense situations... usually resulting in me missing everything :roll:

So basically just want to make it so when I hold right mouse button, MM will send a click instead and when I release the key, it'll send another click.

Thanks
Sorry about the late reply!

I've took your recommendation into consideration and spent the last two days coding this. It's now in MicroMacro 1.95.1
You can find the documentation on it here: http://solarstrike.net/wiki/index.php?t ... okCallback
You can downloaded MicroMacro 1.95.1 here: https://solarstrike.net/project/micromacro

The explanation might be a bit wordy, but hopefully the example clears things up.

ZZZZZ
Posts: 507
Joined: Sun Oct 21, 2012 1:42 am

Re: Disabling windows hotkeys

#18 Post by ZZZZZ » Fri Oct 13, 2017 9:30 am

Hey Admin! No need to apologise for late reply's, i'm notorious for them myself! Thanks for all the work you do here!

I finally got around to setting this up for PUBG and it is awesome! It actually feels comfortable to play now ^.^

There were only 2 issues I ran into,

1: If you have quick edit enabled on MM and left click on it then proceed to utalise the hook, it causes MM to hang and the mouse either stops working or is really laggy. Usually resulted in MM not responding or me force quitting it. Easy to avoid of course, just figured I would mention it.

2: If you try to replace a button with the same button (eg, mouse down causes mouse click like I did with PUBG), Micromacro also reads its own inputs as an input from the user (which makes sense, its only simulating a physical click). I got around this by just sending a virtual click, but I would imagine if somebody wanted to do something similar with an application/game that has virtual inputs blocked, it could cause issues. I wouldn't know if there is a way to differentiate the real and simulated clicks.

Once again thank you!

p.s Add mouse_hook to the mouse.setHookCallback(hook); line in the setHookCallBack example just for clarity's sake. :)

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

Re: Disabling windows hotkeys

#19 Post by Administrator » Fri Oct 13, 2017 10:05 am

The first issue you described is not something I can fix as it is an issue within Windows itself. Quick edit actually pauses execution of the console's thread(s) when in edit mode; this means the hook thread is unable to do any processing, which means Windows waits for the time-out before giving up and slowly regurgitating the input.

As for the second, I suppose you could use a simple variable to flag; set it before you push artificial input, unset it when done. That works in theory. There might be a better way to accomplish it so I'll have to give it a try. I likely won't be able to get around to it for a few days as my partner and I will be quite busy. Lets see, we've got to visit family tonight, wedding shower and bachlorette party to attend tomorrow, furniture coming Monday and baking a massive cake for the birthday party on Tuesday, then hiking, and then I've got another modeling shoot. So, yep, busy week coming up.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests