Archive: Control+Shift via GetAsyncKeyState() on Vista?


Control+Shift via GetAsyncKeyState() on Vista?
I have an installer that needs to detect whether both the Control and Shift keys are being pressed as it launches so as to enable certain advanced features. I use GetAsynchKeyState() under XP to do this, and it works fine.

However, I've just tried doing this under Vista and discovered that it doesn't work. GetAsynchKeyState() returns the expected result if one or the other key is held down, but if both are down, it returns 0 in both cases.

I tried substituting both GetKeyState() and GetKeyboardState() instead, but the result is the same.

Anyone seen this before?

The code is pretty straightforward:

System::Call "user32::GetAsyncKeyState(i 0x11) i .r0 ? !e"

IntOp $0 $0 & 0x8000

${If} 0 <> $0
System::Call "user32::GetAsyncKeyState(i 0x10) i .r0 ? !e"

IntOp $0 $0 & 0x8000

${If} 0 <> $0
IntOp $0 1 +
${EndIf}
${EndIf}


Seems you're not the only one with this problem. A quick Google search didn't find any answers but it did find your post in the third spot.


Did a little more testing, and found that if I run a test app that does the same thing on Vista as Administrator, it only saw one key or the other, but if I ran it normally, it worked fine. The obvious difference was the UAC dialog that popped up when I tried to run it as Admin; when I disabled UAC using MSCONFIG, and ran the app as Admin, it worked fine again.

So the UAC dialog screws up the results of ::GetAsyncKeyState() such that it only ever sees one of the two keys, never both. Now, *why* that happens is another question. Any ideas?