Re: Hooking Keyboard
"Ben Menashe" <BenMenashe@discussions.microsoft.com> wrote in message
news:994D6257-1096-44A0-8A89-C4A609F87EFB@microsoft.com...
Interesting... I thought it was ok to use it to trap keys.
When used sparingly. :-)
FWIW: "Best practice" guidance out of MS for some time has been that
services should not be able to interact with the desktop. Look up "Shatter
Attack" for background on some exploits used by malware authors for the
rationale for the advice.
IIUC, with Vista, a service will still be allowed to interact with "a
desktop" - just not the interactive one. When that happens, your approach
will fail on the local session as it does now with remote sessions.
You may want to consider getting your hook to be launched from the Startup
group or one of the registry's Run keys.
Other suggested methods for doing what I need ? the
service needs to 1) sense if there's keyboard/mouse activity
(so it can pause it's heavy operation in case a user
is logged on) 2) detect keystrokes so it can bring up a GUI
with a password that will allow the user to shut it down.
In general, and IMO, polling is evil and to be avoided. But it is not so
evil as a system-wide hook because it should impact performance less and it
doesn't serve to bulk up innocent bystander applications. For that reason, I
might try to address your point #1 by occaisionally polling for keystrokes
info with GetLastInputInfo().
I'm not sure I understand your point #2, but if you need some magic
keystroke to launch a dialog you might want to take a look at
RegisterHotKey().
The only issue left is that it does not work for terminal sessions. Any
ideas on that ?
Each of the sessions gets its own desktop. You'd have to plant the hook on
each of those desktops, no?
Regards,
Will