Jump to content

Problem with MouseClick() while _MouseTrap()ed


Recommended Posts

For some reason speed is different, not sure why. Also there is nothing to stop the user from clicking or using the mouse wheel. I use this instead of Blockinput() because that also blocks keyboard input. Can someone help? I got most of the script from the autoit src for "MouseMoveExecute".

CODE
; Examples

MouseClick("left", 525, 525, 1, 100)

MouseTrapClick("left", 25, 25, 1, 100)

Func MouseTrapClick($button, $x = "", $y = "", $clicks = 1, $nSpeed = 10)

If $x == "" Then $x = MouseGetPos(0)

If $y == "" Then $y = MouseGetPos(1)

If $nSpeed < 0 Or $nSpeed > 100 Then $nSpeed = 10

$pos = MouseGetPos()

$xCur = $pos[0]

$yCur = $pos[1]

$nMinSpeed = 32

While $xCur <> $x Or $yCur <> $y; Taken from AutoIt 3.1.1 (MouseMoveExecute) src

If $xCur < $x Then

$delta = ($x - $xCur) / $nSpeed

If $delta == 0 Or $delta < $nMinSpeed Then $delta = $nMinSpeed

If ($xCur + $delta) < $x Then

$xCur = $x

Else

$xCur += $delta

EndIf

ElseIf $xCur > $x Then

$delta = ($xCur - $x) / $nSpeed

If $delta == 0 Or $delta < $nMinSpeed Then $delta = $nMinSpeed

If ($xCur - $delta) < $x Then

$xCur = $x

Else

$xCur -= $delta

EndIf

EndIf

If $yCur < $y Then

$delta = ($y - $yCur) / $nSpeed

If $delta == 0 Or $delta < $nMinSpeed Then $delta = $nMinSpeed

If ($yCur + $delta) > $y Then

$yCur = $y

Else

$yCur += $delta

EndIf

ElseIf $yCur > $y Then

$delta = ($yCur - $y) / $nSpeed

If $delta == 0 Or $delta < $nMinSpeed Then $delta = $nMinSpeed

If ($yCur - $delta) > $y Then

$yCur = $y

Else

$yCur -= $delta

EndIf

EndIf

_MouseTrap($xCur, $yCur)

Sleep(10)

WEnd

MouseClick($button, Default, Default, $clicks)

EndFunc

; From Misc.au3

;===============================================================================

;

; Description: _MouseTrap

; Parameter(s): $i_left - Left coord

; $i_top - Top coord

; $i_right - Right coord

; $i_bottom - Bottom coord

; User CallTip: _MouseTrap([$i_left = 0[, $i_top = 0[, $i_right = 0[, $i_bottom = 0]]]]) Confine the Mouse Cursor to specified coords. (required: <Misc.au3>)

; Author(s): Gary Frost (custompcs@charter.net)

; Note(s): Use _MouseTrap() with no params to release the Mouse Cursor

;

;===============================================================================

Func _MouseTrap($i_left = 0, $i_top = 0, $i_right = 0, $i_bottom = 0)

Local $av_ret

If @NumParams == 0 Then

$av_ret = DllCall("user32.dll", "int", "ClipCursor", "int", 0)

Else

If @NumParams == 2 Then

$i_right = $i_left + 1

$i_bottom = $i_top + 1

EndIf

Local $Rect = DllStructCreate("int;int;int;int")

If @error Then Return 0

DllStructSetData($Rect, 1, $i_left)

DllStructSetData($Rect, 2, $i_top)

DllStructSetData($Rect, 3, $i_right)

DllStructSetData($Rect, 4, $i_bottom)

$av_ret = DllCall("user32.dll", "int", "ClipCursor", "ptr", DllStructGetPtr($Rect))

; DllStructDelete($Rect)

EndIf

Return $av_ret[0]

EndFunc ;==>_MouseTrap

Edited by gamerman2360
Link to comment
Share on other sites

Well, what do you expect, you trap the mouse, then expect the mouseclick to be able to move to certain coords....

If your going to trap the mouse, try another click method, such as send, controlsend... etc...

Edit: Feeling froggy, I thought this one deserved a note

http://www.autoitscript.com/fileman/users/gafrost/heresyoursign.jpg

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

I trap the mouse then use _MouseTrap() to move the mouse like autoit ususally would. I can't get the speed right tho...

All kidding aside why not something like

BlockInput(1)
MouseClick("left", 525, 525, 1, 100)
BlockInput(0)

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

MouseTrapClick("left", 525, 525, 1, 100)
Sleep ( 500 )
MouseTrapClick("left", 100, 100, 1, 10)
Func MouseTrapClick($button, $x = "", $y = "", $clicks = 1, $nSpeed = 10)
    _MouseTrap()
    If $x == "" Then $x = MouseGetPos(0)
    If $y == "" Then $y = MouseGetPos(1)
    If $nSpeed < 0 Or $nSpeed > 100 Then $nSpeed = 10
    MouseClick($button, $x, $y, $clicks, $nSpeed)
    _MouseTrap($x, $y)
EndFunc

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Let me explane, I feel like your running my words through google transulator a few times before reading them...

; Examples
MouseClick("left", 525, 525, 1, 100)
MouseTrapClick("left", 25, 25, 1, 100)
This part was to demonstrate the difference between the speed set at 100 on both functions.

I wanted to have _MouseTrap() move the mouse like MouseClick() would, gradually, not instantly. So I took the script that AutoIt uses to calculate the mouse's position, then had it move the mouse using MouseTrap() since if you fix the mouse into 1 spot the program will move the mouse there anyway. Just like the MouseEvent thing autoit has except it will lock the mouse in place. It works and all. It just dosn't get the speed right.

I was thinking about some of the requests for a BlockInput() for the mouse only when I made this. I have found out the reason there is no way to BlockInput() for the mouse only is because BlockInput() uses a .dll to block it. "user32.dll" I believe... Anyway, .dlls are not my thing so instead I thought of this.

It also has another problem. It dosn't stop all mouse events. Sure the curser dosn't move but mouse click events are still sent. Unless there is a HotKeySet() way to block mouse buttons 1 to however many they can have, and the mouse wheel, I don't see how it can be done. Does anyone know if the "BlockInput" function in 'user32.dll' can be recreated?

Edited by gamerman2360
Link to comment
Share on other sites

It also has another problem. It dosn't stop all mouse events. Sure the curser dosn't move but mouse click events are still sent. Unless there is a HotKeySet() way to block mouse buttons 1 to however many they can have, and the mouse wheel, I don't see how it can be done. Does anyone know if the "BlockInput" function in 'user32.dll' can be recreated?

Sounds like a fun project to me... I'm tired though and it's bedtime. Maybe tomorrow I suppose. ANYHOW, truly locking down the mouse would be playing with fire here... Idk. Can you give more details on what you're trying to do? Game, application, etc and the purpose of it. Might help us help you...
Link to comment
Share on other sites

Basically I wanted to disable user input so you can't accidently bump into the mouse when normal MouseClick() is running. There is a 10ms space between the time the mouse gets to its destination and the time it actually clicks. I'm not sure if that makes a big diference or not. The programs I may (or may not) be using it on include things like using MouseClick() to click on little pixles in MSPaint or click on small buttons in some game.

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...