views:

146

answers:

2

BACKGROUND

  • I wrote an app in C# that registers windows hotkeys (it takes a screenshot when I press PRINTSCREEN)
  • My code to register the hotkey, capture screen , etc all works. No issues there.

THE PROBLEM

  • IF my app is running (and successfully has registered the hotkey) and then I do something that causes a UAC prompt - usually this is caused when, for example, I launch some setup program - then the hotkey is lost. Lost = afterwards when I hit printscreen the event never comes back to my app. I have to close the app and restart.

THE QUESTIONS

  • Why is the hotkey lost?
  • What can and should I be doing different differently when registering the hotkey?

NOTES

  • I've seen this behavior with other applications that register hotkeys - running the app with the hotkey using admin privileges prevents the hotkey from being lost
  • What can and should I be doing different differently when registering the hotkey?
  • Avoiding apps like setup.exes that cause the UAC prompt is not a viable solution - the entire purpose of my taking screenshots is to document a setup experience over a number of applications
  • I have a workaround in that I can launch the app with admin rights - but I would rather avoid having to do make users do that

CODE

My code is very similar to this: http://www.codekeep.net/snippets/ea68475b-c33e-4a71-8008-90f63d7e918d.aspx

+1  A: 

Given that Print Screen already takes a screenshot and puts it on the clipboard, have you considered monitoring the clipboard for changes instead?

Look at the SetClipboardViewer API function. For example.

Roger Lipscombe
I agree. I’ve made an entire app that's based on clipboard monitoring (though not for images) and it works wonderfully.
Allon Guralnek
A: 

When you do something that may cause an UAC - why not unregister the hotkey first and then register it again afterwards?

danbystrom
That specific techqinue will work if my app is causing the UAC. My app is not the source of the the UAC prompt - so there is no way for my to unregister the hotkey just before the UAC prompt appears. A user is launching my app and may be taking screenshots of any application - some of them will cause a UAC prompt - it can't predict this programmtically. Perhaps a related technique I could try is to detect if a UAC prompt has occured since my app started and then unregister/register the hotkey.
namenlos
You should be able to detect a UAC dialog with a CBT-Hook, I guess - if you can't find a more direct way. Another approach could be just to keep registering your hotkey on a timer. Indeed ugly - but if it works...
danbystrom