Programs like Virtual Machines stealing my hook

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
XShayanX
Posts: 83
Joined: 16 Sep 2018, 04:48

Programs like Virtual Machines stealing my hook

Post by XShayanX » 19 May 2021, 08:47

Hello.
  • I'm running my script as Administrator.
  • Keybd hook and Mouse hook are installed on the sciprt.
But even with this config, VMWare Virtual Machines steal my hook, that means when a Virtual Machine window is active, my hotkey does not trigger anymore. I DO NOT want to run the script inside a Virtual Machine. I googled this and found a lot of questions that wanted to run a script inside the VM, I do not want that, my purpose is, I want my hotkeys to KEEP WORKING even when a VM window has grabbed the focus.

Now obviously, in Windows the latest hook takes precedence over other hooks, so I took note of this and I run the script after I run the VM. But still my hotkeys are not working.

Now I really thought this is impossible, I thought VMWare is not using hooks and probably works different, but actually, a program called XMBC (x-mouse button control) which I use for making hotkeys for my mouse, bypasses the VM hook. I'm saying that my XMBC mouse hotkeys STILL WORK when a VM window is active. So I want to know, if there are any solutions or directives out there than can help me with this.

Thanks for reading and thanks very much in advance.
lexikos
Posts: 9690
Joined: 30 Sep 2013, 04:07
Contact:

Re: Programs like Virtual Machines stealing my hook

Post by lexikos » 20 May 2021, 02:47

I do not use VMware, but Microsoft Remote Desktop causes similar issues when it is set to send keyboard shortcuts to the remote computer. I presume the keyboard hook is installed when the VM window is activated, and uninstalled when the window is deactivated. To work around it, you must reload the script or reinstall the script's hook (which you might do by suspending hotkeys temporarily) after the VM window is activated.

It's unlikely that XMBC "bypasses" the VMware hook. More likely, VMware is only hooking the keyboard, and XMBC is only hooking the mouse. These are two separate procedures.
XShayanX
Posts: 83
Joined: 16 Sep 2018, 04:48

Re: Programs like Virtual Machines stealing my hook

Post by XShayanX » 20 May 2021, 05:41

lexikos wrote:
20 May 2021, 02:47
I do not use VMware, but Microsoft Remote Desktop causes similar issues when it is set to send keyboard shortcuts to the remote computer. I presume the keyboard hook is installed when the VM window is activated, and uninstalled when the window is deactivated. To work around it, you must reload the script or reinstall the script's hook (which you might do by suspending hotkeys temporarily) after the VM window is activated.

It's unlikely that XMBC "bypasses" the VMware hook. More likely, VMware is only hooking the keyboard, and XMBC is only hooking the mouse. These are two separate procedures.
Hello. Thanks very much for replying.
I tried both a keyboard hotkey and a mouse hotkey, and both don't work. And I also tried reinstalling the hooks as you suggested. Here's the script I wrote:

Code: Select all

#SingleInstance Force
#InstallKeybdHook
#InstallMouseHook

SetTimer, Reinstall, 1000

Reinstall:
Suspend
Sleep,1
Suspend
Return

MButton::
MsgBox, Hello.
Return

x::
MsgBox, Hello.
Return
But it still doesn't work when VM window is active.

When I test XMBC, the host can see the hotkey which means if I have a hotkey that does something on the host, it still works, and also, if I want to send a hotkey to the VM, it still works as well.

You can see in this GIF I created which explains my issue very well:
https://imgur.com/a/3UsWu0v

Please let me know what you think. Thanks again.
lexikos
Posts: 9690
Joined: 30 Sep 2013, 04:07
Contact:

Re: Programs like Virtual Machines stealing my hook

Post by lexikos » 20 May 2021, 19:23

Another theory:
Nextron wrote:
31 Dec 2016, 10:26
I've got a few host hotkeys that do transfer to the guest, but VMware probably uses a filter driver which doesn't see artificial input for HID's to intercept their input, since it can also assign specific devices directly to the host.

XMBC uses a mouse hook, most likely WH_MOUSE_LL (the same type as AutoHotkey), since WH_MOUSE requires a DLL to be loaded into each process (and afaik, offers no advantages).
XMBC is not a mouse driver, it uses windows mouse hooks to capture buttons and therefore it is only capable of responding to the messages sent (by the mouse driver) through the Windows mouse hook.
...
I found all the info required to build XMBC in MSDN (look for SetWindowsHookEx())
Source: XMBC Frequently Asked Questions [FAQ] - Highrez
XMBC uses the equivalent of Run with UI Access.
Why should I/shouldn't I use Program Files for During installation, what difference does it make?
In Windows Vista and later, XMBC operates as an accessibility tool in order to interact with elevated (UAC) windows and send certain simulated keystrokes.
Source: XMBC Frequently Asked Questions [FAQ] - Highrez
Since you are already running the script as administrator, I can think of no way that XMBC could work where AutoHotkey does not.

See what the developer of XMBC says about VMware:
XMBC has never worked with VMWare. VMWare operates with the mouse at a lower level, and either does not intercept the buttons or you get both the default (original) action and the new action sent at the same time. hence you get a left and right click at the same time in this case. This is not new, and the only way to get XMBC working with VMWare (since vmware 7 sometime I think) has been to have a VMWare profile setup that does nothing except keep everything "same as default") so I'm confused as to how you ever had any success with XMBC and VMWare?!
Source: XMBC 2.11 Beta - Highrez
Oddly enough, in another topic someone reported that AutoHotkey works but XMBC does not.
User avatar
ibieel
Posts: 216
Joined: 17 Oct 2021, 23:30

Re: Programs like Virtual Machines stealing my hook

Post by ibieel » 13 Sep 2023, 20:42

XShayanX wrote:
20 May 2021, 05:41
lexikos wrote:
20 May 2021, 02:47
any solution? i have the same problem.
viewtopic.php?f=76&t=121383
Post Reply

Return to “Ask for Help (v1)”