kevin_ketchum has asked for the wisdom of the Perl Monks concerning the following question:

While running a perl script, I need to be able to determine if the mouse pointer is showing busy and, if so, pause the script until the pointer changes back to normal. Suggestions?
  • Comment on Need to determine state of mousepointer

Replies are listed 'Best First'.
Re: Need to determine state of mousepointer
by Joost (Canon) on Jun 24, 2004 at 19:06 UTC
    Two questions:

    What operating system are you using?

    Why would you want to do this? On my system (linux, but I guess this is valid for most operating systems) the mouse pointer status changes depending on which window is selected, so it doesn't really give you much information without knowing the active window too.

    I'm guessing you want to wait for some process or other to finish, and depending on the program, there might be a better way of determining that than watching the mouse pointer.

    Joost

      I suppose I should have pointed that out right away.

      I am running the Win32:GUITest module against a series of Delphi 1 apps.

      These apps have some textboxes that are wired to 'on exit' events.

      If the textbox is blank when the cursor leaves it (via a hot key, tab, mouse click or whatever), the application (which is connected to a server via tcp/ip) asks a program on the server for a value to place in the field.

      During the communication phase, the mouse pointer is set to busy.

      My problem is that I need to suspend interaction with the application until the program receives the number and populates the field.

      I believe the easiest way is to watch the state of the mouse pointer and only resume once it returns to normal.
Re: Need to determine state of mousepointer
by pbeckingham (Parson) on Jun 24, 2004 at 19:09 UTC

    If you are trying to determine the state of some process, then the mouse pointer is not the way to do it. Can you communicate with the process? Is there some other completion indicator?

Re: Need to determine state of mousepointer
by PodMaster (Abbot) on Jun 25, 2004 at 05:40 UTC
Re: Need to determine state of mousepointer
by EdwardG (Vicar) on Jun 25, 2004 at 14:03 UTC
    # Use this to monitor the shape of mouse cursor use strict; use warnings; use Win32::API; Win32::API::Struct->typedef( POINT => qw{ LONG x; LONG y; }); Win32::API::Struct->typedef( PCURSORINFO => qw{ DWORD cbSize; DWORD flags; HCURSOR hCursor; POINT ptScreenPos; }); my $pci = Win32::API::Struct->new('PCURSORINFO'); $pci->{cbSize} = 20; #$pci->sizeof(); # ? sizeof doesn't work for nest +ed struct ? Win32::API->Import("user32", "BOOL GetCursorInfo(PCURSORINFO pci)"); while (1) { my $result = GetCursorInfo($pci) or die $^E; print "Current mouse shape is $pci->{hCursor}\n"; $pci->{cbSize} = 20; sleep 1; }

    With thanks to dfaure for helping find that bug with Win32::API::Struct.

     

      This has solved my problem. Thanks for the help.
Re: Need to determine state of mousepointer
by Anonymous Monk on Jun 26, 2004 at 01:06 UTC
    You could send a WM_GETTEXT to the Editfields. If there is text, you take the next step.