문제

When I register a hot key in C++ (the PrtScn key in this case), I noticed that the original functionality is lost. The key does not capture an image of the screen any more. IS there a way to register the hot key without breaking its existing bindings?

The Problem Context: I am trying to create an application to help our testing team automate their task of taking screenshots. When the user clicks PrtScn / Alt+PrtScn keys, I want to run a small application that picks the image on the clipboard and pushes it into a document. Most of this application is in Java, but I had to come to C++ for registering a hot key.

Thanks for your help!!

This is the code I used to register the hot key:

RegisterHotKey(NULL, 1, MOD_ALT | MOD_NOREPEAT, VK_SNAPSHOT);
RegisterHotKey(NULL, 2, MOD_NOREPEAT, VK_SNAPSHOT);

while (GetMessage(&msg, NULL, 0, 0) != 0)
{
    if (msg.message == WM_HOTKEY)
    {
        WinExec(" The Java Application ", SW_SHOWNORMAL);
    }
} 
도움이 되었습니까?

해결책

I don't think there's any documented way to trigger the OS's Print Screen functionality programmatically. I do have a few ideas you could try:

  1. Implement the copy-to-clipboard functionality yourself, or
  2. Once your hotkey has been triggered, temporarily unregister the hotkey and use SendInput() to resend the key press (this is admittedly a bit kludgy), or
  3. Drop the hotkey method altogether and instead register a clipboard viewer using SetClipboardViewer() etc.

To me the last idea seems the best - you'll get notified when the clipboard contents change and then it's easy to see if the format on the clipboard is an image or not.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top