2
votes

I have an application that uses a low level keyboard hook to capture the user's choice of keyboard shortcuts at a global level to activate the application's main window. Because I want to allow sometimes "odd" shortcuts, like F12 or Ctrl+Ctrl (double tap), I use the hook instead of the RegisterHotkey API function. Until Windows 8, this feature worked great. In Windows 8, some windows prevent my application from receiving the event but only while those windows are in the foreground. The Windows 8 Task Manager is one such offender.

Note that, because the problem only occurs while the offending window is in the foreground, I know that my hook is still registered with the system, just temporarily not reaching my application.

The current code base is C# Framework 4.0; however, I tested the previous code base, which was unmanaged C++ and the problem is the same.

Version of Windows is 8.1 Pro with Media Center

One thing I have not yet tried is moving the hook procedure to a separate DLL. I think I read that the low level keyboard hook procedure must be in a DLL but I have never found this to be true. Before I go to the trouble of trying that, I wanted to ask whether I am missing something easier and more obvious.

1
You cannot snoop on the keystrokes entered into an elevated app. Like Task Manager, it has the <autoElevate> element in its manifest. Basic UAC at work.Hans Passant
Is this new in Windows 8? I did not find this to be the case in Windows 7. I can very much appreciate the measures that Windows takes to prevent keystroke snooping because of its potential maliciousness; however, for users who wish a specific application to have a global keyboard shortcut, is it not possible to have it globally and all the time? Note that my UAC setting is currently dialed back to "Never" yet the "no-snoop" behaviour persists. (Apologies if this is starting to become a superuser question instead of a stackoverflow question.)Craig Silver
No. Google "how to bypass uipi" to learn more.Hans Passant
I'm having this problem on Windows 7. I'm looking for a press of Shift+A, but the state of the shift button is inaccessible whenever notepad has focus. Notepad is not elevated. Does this go both ways? And why is it that only the modifier state is inaccessible?Triynko

1 Answers

0
votes

Now I understand. Although my application runs under a Windows account that is in the Administrators group, it needs to be launched with "Run as Administrator" in order to avoid being blocked by UIPI.

The solution, at least for me, is to ask a Windows 8 end user to launch my application as Administrator, if s/he wants to use "fancy" global keyboard shortcuts like the ones I mention in the question. (I also allow the user to use "simple" shortcuts, which are implemented with RegisterHotkey() instead of with WH_KEYBOARD_LL and therefore do not suffer from UIPI.)