in reply to Re: Mouse Position in Desktop
in thread Mouse Position in Desktop

Thank you. It is indeed in Windows. I tried it and it went well. But if I wanted to move my mouse and show its current position at the same time, how would you do it?

The code below seems to work for me, but it seems that the script is not fast enough to capture the mouse position.
while (1) { my ($x, $y) = GetCursorPos(); print "X is at $x, Y is at $y\n"; }

Replies are listed 'Best First'.
Re^3: Mouse Position in Desktop
by GrandFather (Saint) on Dec 28, 2010 at 00:06 UTC

    What's the application? print will slow your loop down lot, but even without the I/O it may well be that Perl is not suitable for fast enough response for interactive tasks.

    True laziness is hard work
Re^3: Mouse Position in Desktop
by Anonymous Monk on Dec 28, 2010 at 00:05 UTC
    You need to yield to other processes by sleeping some amount of time each loop. Time::HiRes's version of sleep will help here.

      Why? Windows is a pre-emptive multi-tasking operating system and mouse handling is essentially independent of applications. Inserting sleeps will not speed anything up and there is no need for a yield as the OS already asynchronously handles mouse position.

      True laziness is hard work
        That's fine if you don't expect the process to be able to print anything to a window.