Jump to content

How can I figure out how long it takes MouseClick() to run? Speed parameter is ambiguous.


Recommended Posts

I don't understand how you can all take his side.. This is indeed a question which is like 95% of the questions posted on these forums.

Do you tell all these people to try to read the source themselves? Sure you can take a look at the source or ask a question that almost any decent user can answer within a few seconds. I think its a pretty valid question, although the answer might be a little obvious. I think for the mouse movement functions it would be good to state that the movement speed is dependent on the system the function is used on. Sure you don't need to discuss every little detail about what affects the speed. If you really need to know one should really try to read the source. I am not defending the words he used after valiks response.. that was terrible.

Link to comment
Share on other sites

I don't understand how you can all take his side.. This is indeed a question which is like 95% of the questions posted on these forums.

Do you tell all these people to try to read the source themselves?

You're looking at one detail too closely and not the important detail. This is like 95% of the questions on this forum because it can be answered by the OP by nothing more than effort and reading. Most people do not expend the effort necessary to read the documentation. In this case the OP did not expend the effort necessary to read 30 lines of source code readily available. There was no need to ask anybody any question because the answer is sitting there waiting to be read. Just like most of the questions asked on this forum which are covered in the documentation (or hell, covered to death on the forum).

I think for the mouse movement functions it would be good to state that the movement speed is dependent on the system the function is used on.

Did you not read what I wrote earlier? I'm not committing to anything with the description of the function. The only guarantee I will state is that as the value increases towards 100 the speed is as slow or slower than the previous number. Nothing more. This thread boils down to a user wanting to know implementation details for the function - which is why I told them to read the source since I doubt that code has changed... ever. I also suggested writing a custom method because ours should not be relied upon since there are only minimal guarantees about behavior.
Link to comment
Share on other sites

In the time it has taken you to argue with Valik, you could have looked through the 99 lines, of which about a third is commented.

POINT ptCur, ptOrigin;
RECT rect;
int xCur, yCur;
int delta;
const int nMinSpeed = 32;


// Convert coords to screen/active window/client
ConvertCoords(m_nCoordMouseMode, ptOrigin);
x += ptOrigin.x;
y += ptOrigin.y;

// Get size of desktop
GetWindowRect(GetDesktopWindow(), &rect);

// Sanity check coords - removed so that it works on multiple monitors where -ve values are OK
/* if (x < 0)
x = 0;
else if (x > rect.right)
x = rect.right;

if (y < 0)
y = 0;
else if (y > rect.bottom)
y = rect.bottom; */

// Convert our coords to mouse_event coords
x = ((65535 * x) / (rect.right-1)) + 1;
y = ((65535 * y) / (rect.bottom-1)) + 1;


// Are we slowly moving or insta-moving?
if (nSpeed == 0)
{
mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, x, y, 0, 0);
Util_Sleep(10); // Hopefully fixes "clicks before moving" bug
return;
}

// Sanity check for speed
if (nSpeed < 0 || nSpeed > 100)
nSpeed = 10; // Default is speed 10


// So, it's a more gradual speed that is needed <img src='http://www.autoitscript.com/forum/public/style_emoticons/<#EMO_DIR#>/smile.png' class='bbc_emoticon' alt=':)' />
GetCursorPos(&ptCur);
xCur = ((ptCur.x * 65535) / (rect.right-1)) + 1;
yCur = ((ptCur.y * 65535) / (rect.bottom-1)) + 1;

while (xCur != x || yCur != y)
{
if (xCur < x)
{
delta = (x - xCur) / nSpeed;
if (delta == 0 || delta < nMinSpeed)
delta = nMinSpeed;
if ((xCur + delta) > x)
xCur = x;
else
xCur += delta;
}
else
if (xCur > x)
{
delta = (xCur - x) / nSpeed;
if (delta == 0 || delta < nMinSpeed)
delta = nMinSpeed;
if ((xCur - delta) < x)
xCur = x;
else
xCur -= delta;
}

if (yCur < y)
{
delta = (y - yCur) / nSpeed;
if (delta == 0 || delta < nMinSpeed)
delta = nMinSpeed;
if ((yCur + delta) > y)
yCur = y;
else
yCur += delta;
}
else
if (yCur > y)
{
delta = (yCur - y) / nSpeed;
if (delta == 0 || delta < nMinSpeed)
delta = nMinSpeed;
if ((yCur - delta) < y)
yCur = y;
else
yCur -= delta;
}

mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, xCur, yCur, 0, 0);

Util_Sleep(10); // 20 ms sleep inbetween moves
}

There, you don't even have to download the source.

Edited by JamesBrooks
Link to comment
Share on other sites

If I wanted to know how long a MouseMove took I'd more than likely test it with something like this.

Sleep(1000) ; give interpreter some time to wind up
MouseMove(0,0,0)
$Speed = 20
$Distance = 100
$Timer = TimerInit()
MouseMove($Distance,0,$Speed)
$TimerDiff = TimerDiff($Timer)
MsgBox(0,"Speed Per pixel at " & $Speed ,Round($TimerDiff / $Distance,2) & " Milliseconds")
Exit

If I wanted to know how it is implemented in Autoit I would consult the last source available.

Also, I don't take sides, right is right and wrong is similar.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Did you not read what I wrote earlier? I'm not committing to anything with the description of the function. The only guarantee I will state is that as the value increases towards 100 the speed is as slow or slower than the previous number. Nothing more. This thread boils down to a user wanting to know implementation details for the function - which is why I told them to read the source since I doubt that code has changed... ever. I also suggested writing a custom method because ours should not be relied upon since there are only minimal guarantees about behavior.

I did read it and i understand your opinion, but i have a different opinion about it. Thats all. I know you get questions like this every day and it must be tiring to help lazy people. Still much worse questions have been asked for which the answers were in the help file. I would give at least some information about it in the help file, but hey, your the DEV and i am just an OK coder.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...