mzomparelli / zVirtualDesktop

Windows 10 Virtual Desktop Hotkeys, System Tray Icon, Wallpapers, and Task View replacement
461 stars 45 forks source link

Keyboard hooks doesn't work if VmWare workstation app is in focus #214

Open 77cc33 opened 6 years ago

77cc33 commented 6 years ago

Hello,

I'am using your app to switch between desktops with Cntr + F1 & Cntr + F2, everything works fine - until I don't have vmware workstations opened with running OS inside at second desktop.

As soon as vmware in focus (active window + running OS inside) I can't return with Cntr + F1 back to the first desktop, whenever windows shortcuts works fine, as well as my mouse side wheel works fine for this switch). I tried to change Cntrl +F1 to something like Win + Shift + Cntr + F1 just to be sure there are no conflict with VmWare - but no luck.

Is there anyway I may help you to trace, why zVD can't catch Cntr + F1 shortcuts if VmWare Workstation app is active - to fix this issue?

mzomparelli commented 6 years ago

This is because VM ware takes your keyboard input. You need to move focus back to your host computer. You can do this by clicking the taskbar in the host OS.

This is the way it should work so that you can use zVD in a VMware hosted OS if you wanted.

mzomparelli commented 6 years ago

I'll look into this to see what I can do. I don't use VMware, but I do use VirtualBox so I should be able to test using that.

77cc33 commented 6 years ago

VMware has 2 input modes:

"Grabbed" - when all mouse & keyboard events sent directly to the running inside virtual OS and "Un-Grabbed" - when all mouse & keyboards events sent to the VMware GUI & Host OS

So usually when I work inside Virtual OS (Grabbed mode) - I'm using ALT + CNTR to exit this mode (set mode to Un-Grabbed), after that I can hit WIN + CNTL + LEFT to return to the previous desktop, or to use mouse wheel to scroll to to previous desktop (hooked with Logitech Option driver tool), both these trick doesn't require me to tick task bar first, whenever vZD requires hitting taskbar first.

By the way, right now I just found that if I open PowerShell in Admin mode (Win + X - A), desktop switch hotkeys doesn't work too - so I have to alt tab to some other window or hit taskbar. Default Windows shortcuts works fine. Can you check it maybe it has the same source of issue.

77cc33 commented 6 years ago

Hmm the same powershell window started in user mode - works just fine.

I started vZD in admin mode and now powershell admin works fine, but vmware still has issue.

mzomparelli commented 6 years ago

Windows opened with admin privileges can only be interacted with by zVD if zVD has been run with admin privileges too. That should fix the issue with PowerShell. It might also affect VMWare issue. Let me know if it works.

So if an admin window has focus then for some reason no hotkeys make it through the chain unless zVD is admin too.

mzomparelli commented 6 years ago

I'll look into the VMware issue. If there is an "un-grabbed" mode then it should work as expected. I'll report back after my testing.

77cc33 commented 6 years ago

Thank you, just few tips for you what maybe helpful.

In VMware preferences I have these settings.

image

This allows to enter in Grab mode only with Mouse Click, this way we can go to Ungrabbed mode and switch to another desktop - with keyboard shortcuts or mouse wheel (as it will not grab virtual os again).

  1. So you may start any Virtual OS.
  2. Go full screen Grabbed mode [Control + Alt + Enter] - just to be sure it work
  3. Exit grabbed mode with [Cntrl + Alt] (your mouse pointer will change)
  4. Hit your vZD shortcut to switch to another desktop (fail for me) or hit default windows Cntrl + Win + Left (works for me)
77cc33 commented 5 years ago

Maybe I can help investigate this issue, so it could be easier/faster for you to fix it?

Bought license and using your app daily, but it's the only thing what makes experience not perfect )

mzomparelli commented 5 years ago

Sorry I haven't gotten to this yet. I've been really busy with my day job.

Is there a free version of VMware I can test with? I use VirtualBox and hotkeys are working as expected.

77cc33 commented 5 years ago

You can go with VmWare player, it's free for personal use, and I just tried it - it has the same issue.

  1. Download and install VMware player here https://www.vmware.com/no/products/workstation-player/workstation-player-evaluation.html image
  2. Download & Unpack ready VmWare image with Windows 10 here https://developer.microsoft.com/en-us/microsoft-edge/tools/vms/ image
  3. Open vmware image from VmWare player: File > Open (unpacked directory location) image
  4. Press green Play button to start vmware machine. image
  5. Skip any updates if asked image
  6. Windows started image

After machine is started grab it by clicking mouse inside, your mouse pointer will be changed from hand to arrow.

To return back to host press Alt + Enter, your mouse pointer will be changed from arrow to hand.

Now try to use your software shortcuts to switch to specific desktop, it doesn't work for me, while builtin windows shortcut Win + Control + Arrows - works fine for me.

mzomparelli commented 5 years ago

Thanks for that info. I will test tonight and this weekend. Hopefully, I can get it figured out before the weekend is over.

mzomparelli commented 5 years ago

I've observed the behavior you describe using VMware. It's the same thing that happens with VirtualBox.

I'm not sure what I can do about this. For some reason those windows are taking the key presses even if they aren't being sent to the client OS.

A simple solution that works for me is to click the taskbar so that focus is taken away from the VM window.

Can you do me a favor and test if AutoHotKey has this issue?

77cc33 commented 5 years ago

Yes it works fine. I just created this simple AHK Script what starts Calculator with Win + Control + 5

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
^#5::Run calc.exe

And it works fine for me.

77cc33 commented 5 years ago

I'am using full screen mode of VM machine usually, so taskbar is usually not visible to me, anyway - to move mouse out of VM window to click taskbar doesn't look so productive, as I don't touch mouse usually while switching between desktops.

Right now as workaround, i'am just using windows shortcut keys to switch desktops, when I have to move back from desktop with VMware opened, but if it's possible to fix it will be great.

mzomparelli commented 5 years ago

Thanks for checking AutoHotkey. I'll keep digging around for a solution.

mzomparelli commented 5 years ago

I've tried a few things and can't get the expected behavior. I'm not sure I can do anything about this. It seems my keyboard hook isn't triggered. Maybe if written in C++ it would have better results. I can test that, but I certainly can't rewrite zVD in c++. It might be possible to implement the hooks in a c++ dll considering the testing with c++ keyboard hook is successful.

77cc33 commented 5 years ago

Maybe you could take hook from AutoHotkey and use it as .dll in your app?

https://github.com/Lexikos/AutoHotkey_L/blob/master/source/hook.cpp

mzomparelli commented 5 years ago

I'm pretty sure that would violate the AutoHotkey license.

However, I did take a look at the hook and decided it would be easier to recreate my hook first. If that fails I could try compiling a modified AHK hook.

nicolasdejong commented 5 years ago

@77cc33 as a workaround you can try to press alt+tab before you press the zVirtualDesktop key combination. This moves focus away from your VMWare windows. That works for me when using VirtualBox. Not perfect since you still need an extra key press, but perhaps faster if you want to move several desktops away.

77cc33 commented 5 years ago

Hello @nicolasdejong , strange but it doesn't work for me for VmWare, even I see that focus is changed (moved to new app what was in background), even after that it doesn't work of mouse is still in area of VmWare app window.

It works for me only if I'll mouse click on desktop, even mouse clicking on another window doesn't work for me, as well as alt tab to another win.

mzomparelli commented 5 years ago

On VirtualBox you can press Ctrl+Home to bring the mouse and keyboard focus back to the host. After that you should be able to use zVD hotkeys on the host. It works for me like this.

If I'm using the mouse then I simply click on the host's taskbar to bring mouse and keyboard focus back to the host.

brainbarker commented 4 years ago

I've been having this issue as well, but only since upgrading VMWare Workstation from 12 Pro to 15 Pro. I use Logitech SetPoint with a custom configuration to get it to send the WIndows Key.

Under version 12, I was able to switch desktops with the mouse regardless of whether VMWare was in focus (unless the guest OS was Windows) . I did have the same issue with PowerShell windows though.

Hope that helps.

mzomparelli commented 4 years ago

Maybe I'm not understanding the issue correctly. This is expected behavior as far as I can tell. It also happens with RDP. If I'm using RDP or VM then I want that computer to handle my key presses and mouse clicks instead of the host regardless if the key presses are a hotkey on the host. This allows you to use zVD on the client machines as well which I do.

brainbarker commented 4 years ago

I can see how that would be useful. The way it worked in the previous version of VMWare was that if the mouse was outside of the VM's window, mouse and keyboard events went to the host. So for a Windows guest (in fullscreen mode), you'd have to move the mouse to the top of the screen where the drop-down VMWare menu bar was hidden, before hitting the key/mouse event. In the latest version, this no longer works.

If VMWare changed back to the old behavior, it would be fine.

brainbarker commented 4 years ago

OK, one more data point for you. I just started a Windows 2012r2 guest on one desktop. With the mouse inside the VM's window, I tried to switch host desktops with the standard Windows keys (Win+Ctrl+RightArrow). and it did not work (since the Windows guest got the hotkey instead). Then when I moved the mouse to the drop-down VMWare menu bar, the standard windows key sequence DID switch the host's desktop.

However, neither SetPoint nor AutoHotKey sequences worked in or out of the VM's window. The only way to get those tools to work is to unfocus the VMWare window (click on the desktop or bring another windows forward).

brainbarker commented 4 years ago

Sorry, last one, I promise :-)

All hotkey apps seem to work fine when the VMWAre "Home" tab is selected, regardless of where the mouse is, even if the window is in focus.

gaasedelen commented 4 years ago

While this doesn't solve the underlying issue with zVirtualDesktop, it has been disruptive enough to my workflow over the past year that I finally sat down to hack around this issue.

It seems like vmware hooks keyboard input at a stupid low-level which I guess is fair, it's a virtualization application. But I noticed that any accelerators (hotkeys, basically) defined by vmware.exe do not get trapped to the system, and make it down through to usermode.

Using resource hacker, I modified the accelerator table for vmware.exe and added ALT+0/ALT+1/ALT+2 ... eg, the hotkey sequences I use to swap between virtual desktops:

image

I then added the following to a persistent AHK script that I have run on boot, and stores other hotkeys & workflow helpers I use frequently. AHK seems capable of capturing these hotkeys I added to vmware.exe where w10 vd enhancer (what I still use) and and probably zVirtualDesktop cannot.

If AHK sees my 'switch desktop' key, and the VMWare process is active, it will re-emit the hotkey sequence (after changing focus) to explorer.exe so that the virtual desktop hotkey hooks can hear it:

#SingleInstance force
#WinActivateForce
#NoTrayIcon
DetectHiddenWindows, On

; snipped ...

vmware_key() {
  if !WinActive("ahk_class VMUIFrame") {
    return
  }
  Sleep 10
  WinActivate ahk_exe Explorer.exe
  Sleep 10
  SendLevel, 2
  Send %A_ThisHotKey%
  SendLevel, 0
}

Loop % 5
{
   Hotkey, !%A_Index%, vmware_key          ; ALT+0 / ALT+1 / ALT+2
}

With this, I can hit CTRL+ALT to break from the VM as I normally would, and then ALT+0 to switch to desktop 0.

Note, it may not be necessary to activate Explorer.exe. I only do it because I usually leave my VM's full screened on a dedicated virtual desktop. YMMV.