Hello fellow Monks,

I'm trying to write a simple macro program to record and playback user input (keystrokes, mouse movements and button clicks). I'm having trouble reading keystrokes and button clicks that are not in the perl window. Specifically, I'd like to run the perl progam from a command prompt, then move over to another window (losing focus on the command prompt), but still read the mouse movements, button clicks, and keystrokes. I plan to run this on a Win32 XP box, so my target modules are either Win32::GUI or PerlTk.

Here's what I've discovered so far:

  • Win32::GUI::GetCursorPos works great for reading the location of the mouse at the root level, regardless of which window has the focus.
  • There doesn't seem to be a way to read keystroke events in Win32::GUI.
  • I've avoided using Term:ReadKey, as this module says it won't work in a Windows environment.
  • Term::Getch works okay, but it won't work once focus is lost from the execution window. Also, it only returns ASCII characters, so it can't read function keys.
  • PerlTK has a nice binding interface for recognizing keystrokes and mouse button presses, but it only works when the Tk main window has focus.
  • Win32::GuiTest works great for simulating mouse movement and button presses, and does not require focus.

    Can anyone recommend a technique for reading user input when focus is lost?

    Thanks,
    TROGDOR

    In reply to Reading root-level (unfocused) mouse and keyboard input by TROGDOR

    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.