Author Topic: Alt key stuck when alt-tab out of TeamViewer in Windows - workaround/fix  (Read 7015 times)

lorddamax

  • Newbie
  • *
  • Posts: 6
So this has been bothering me for a year. I've asked everywhere, with no answers.

I just sat down this morning and messed with this for 2 hours. First, some findings, then a "solution".

When alt-tabbing out of a windows based teamviewer session back to my local windows based teamviewer, very often the Alt key will get stuck 'down'. It's as if you pressed and released alt, yet, the OS is unaware that you did. It's odd.

Try this:

Open notepad. Press and release alt.
Now, press 'E' - The Edit menu opens.
Press and release Alt a second time. Menu closes.
 
Pressing Alt puts you in this 'menu' state. Ok. Got it. Alt again closes it. Cool.

Now, try it in chrome. Press and release Alt. Then press E. Nothing happens. Chrome does not 'keep' the Alt key pressed. But if you press Alt-E then the menu opens.

When you are in a remote TV window, and press Alt, then tab, to tab back to a local window, TV sends the alt press, then as you hit tab, TV realizes, oh, you're not doing an alt-combo, so lets release the alt key. It sends an Alt keyup event.

But something breaks. Something does not work right. Not 100% of the time (I'm sure it's some odd timing issue), the guest OS keeps that Alt key stuck down. Like as you alt-tabbed away, TV is keeping the alt key down on the guest.

So when you alt-tab BACK, and start to type 'edward' - E opens the Edit menu, D activates whatever Alt-D is, W closes the window (alt-W closes a lot of apps), and suddenly you're going nuts.

The best part? If you alt-tab back, and notice that the menu is activated by the alt, and you press and release Alt once to 'release' the menu, that does NOT release the held alt on the guest. It's like there are two alt-states... the state the OS knows Alt is in, and the Alt state TV thinks the guest is in.

If you tab back, and you're in stuck-Alt mode, and hit Alt once to get out of that mode, you actually just re-activate alt mode again. You need to double tap alt to get out of that mode. It's the most bizzare thing.

Using AutoHotKey and some keystate reading tools, at no time does the software actually report that the key is being physically held down.

Here's the interesting part:

I used autohotkey to make a hotkey for Alt, that told me the LOGICAL status of the key (what the OS thinks the state is, regardless of actual presses or key state). By default, when using the Keyboard hooks, an Alt hotkey will not fire until AFTER the alt key is released.

So I made a script that was this:
#InstallKeybdHook
#UseHook

Alt::
KeyWait Alt
MsgBox Alt Key Released
return

Ran it. Id press and release Alt, and I'd get the message box. Cool.

Then, I alt-tabbed out of the guest back to my local PC, and clicked back into the guest. I could see from the menu that the alt key was stuck down. I hit 'e'. The edit menu opened, and autohotkey said "Alt Key Released". What?

I clicked the Ok to get rid of the box. Pressed another key. Alt Key Released popped up.

That should ONLY happen when I actually PRESS alt, and I was not. I repeat: I was not holding down Alt. My keywatch program was reporting that alt was not being held down. But when I pressed any key, "Aly Key Released" was popping up as if I HAD held and released Alt. I think maybe TV was sending an Alt keyup event when I alt-tabbed out, but somewhere inside TV, it thought alt was still down, so every time I pressed a key, it sent the alt-key combo.

Anyway. Why did it do all this? No idea. Just posting my findings in the hops that the TV guys see this and it helps them fix the damn bug.

So, the solution?

#InstallKeybdHook
#UseHook

~Alt::
KeyWait Alt, L T3
if ErrorLevel {
  Send {Alt}{Alt}
}
return

What this script does is it fires when the alt key is PRESSED (the ~ in front) instead of released. It then waits for the logical state of Alt to be released, with a timeout of 3 seconds. If it is NOT released within 3 seconds, it sets ErrorLevel to 1.

If the alt key is logically released, it does nothing. If it is NOT released, the error level is set. The If statement checks the errorlevel, and if set, double-taps the alt key to released the weird alt-lock.

I've no idea why TV behaves this way. This did not happen before version 9, and it persists in version 10. Researching this issue, I also saw it happening to people alt-tabbing out of VirtualBox VM's - so it, in a way has to do with windows - but - there are threads online from an Ubuntu user using TV having the same problem. I truly do think that TV has its own internal alt-state and windows does as well. Windows thinks Alt is not being pressed. Thats because when you alt-tab out, windows gets an alt keyup and says ok, we're not pressing alt anymore. But TV DOES think it's still pressed. I'm not sure. No way to tell but to start a TV session, alt-tab, get the alt-lock, CLOSE the session, kill TV on the remote end, and see how the remote end behaves. Too much work for now ;)

So who knows. But, running that AHK script will remove the alt-lock if AHK notices the alt-key being pressed for more than 2 seconds. Cool part, if you're really holding down alt, the double Alt it sends has no effect, since you're actually holding the key down.

Hope this helps someone.
« Last Edit: November 10, 2014, 10:53:42 AM by lorddamax »

 

anything