There is no need to make sure it is the active window initially because the purpose of the hot key is to pop-up a GUI window...

That's incorrect I'm afraid.

My guess was that there is something inherently different at the bit level between SendKeys and someone physically typing the characters.

Yes there is. When you type the characters at the keyboard, they are placed on the system input queue, when you use SendKeys(), they are placed directly into the queue of the application that currently has the keyboard focus (the active window).

Roughly, the way hot-keys work, is the application registers the hotkeys with the system through one of several mechanisms that establishes a "hook" onto the system input queue. When the registered key sequence is seen by the hook, the characters are removed from the system input key and the hook routine for the registered application is called. Thus bypassing the active window.

When you use SendKeys(), the sequence bypasses the system input queue (and any registered handlers).

You might try using the SendRawKey() function that Win32::GuiTest exports. Failing that, you could try setting the desktop to be the active window something like:

# Remember who has the focus # Maybe unnecessary. my $hwndActive = GetActiveWindow(); ## Give focus to the desktop to force the key sequence through the sys +tem input queue SetFocus( GetDesktopWindow() ); ## Send the sequence SendKeys( ... ); ## Set the focus back to where it was... SetFocus( $hwndActive );

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco.
Rule 1 has a caveat! -- Who broke the cabal?

In reply to Re^5: hot key not accepted by BrowserUk
in thread hot key not accepted by kcella

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.