#78 Send alt-tab to the vnc server

Heiner Eichmann

Attached is a patch, which sends Alt-Tab from the viewer on windows nt or above to the server. This is crucial if working remote on a windows or KDE server, as these use alt-tab to switch between the windows. So far, alt tab just switches away from the tight vnc viewer to another application.

This patch works on windows nt - xp. It does not work (but does not seem to harm) on windows 98 and below. I have not tested it under vista.

It activates, if the vnc windows gets the focus AND is in full screen mode. It deactivates, if loosing the focus. As the consequence, just disabling the full screen mode keeps this patch turned on, which might be anoying. If someone cares about this patch, I will eventually modify it to turn the patch on and off if fullscreen is turned on and off.

Note, that if connected to a windows server, "poll full screen" in the "hook" tab should be turned on. Otherwise the small borderless window with icons of all available windows will not show up on the client (but alt tab will still work, off course).

Testing: I have tested the patch on the following os':

Server Client result
w2000 nt4.0 ok
nt4.0 w2000 ok
w2000 w98 ok, but alt tab not send to server
KDE (FreeBSD) xp ok

If the user presses alt, WM_KEYDOWN is sent to the application and to every WH_KEYBOARD_LL window hook. If next tab is pressed, WM_SYSKEYDOWN is sent to the WH_KEYBOARD_LL window hooks only. If alt and tab is released WM_SYSKEYUP is sent to all WH_KEYBOARD_LL window hooks, if tab is released first. WM_KEYUP is sent to all WH_KEYBOARD_LL window hooks, if alt is released first. The WM_KEYUP for the alt key reaches the application in any case.

Therefore this patch adds a WH_KEYBOARD_LL window hook. This listenes to tab key events only, as the alt keys are processed correctly. If tab is pressed or released, a WM_KEYDOWN is simmulated and sent to the vnc viewer window, which sends it to the server.

Some remarks:
- the hwnd of the tight vnc windows is calculated by calling GetFocus(). For some reason, GetForegroundWindow() did work on xp only. If this fails on some occasions as well, the main windows hwnd should be stored in a static variable. There is no need to keep it local, as a vnc viewer process just has one main window.
- the key press event is passed to the main window via PostMessage. This will be processed in the vnc viewer windows main thread (and not in the thread, processing the hooks) and this will not block the hook. This approach should work in any case.




  • patch