Sign in to follow this  
Followers 0
tjyorkshire

MouseClickPlus function modification

9 posts in this topic

#1 ·  Posted (edited)

hey, im new here and to autoit coding. Im not a complete noob ;) , i have had some previous experience with languages such as python.

Currently, i am trying to write a movement control system for the MMORPG game rappelz. Basically, you are only able to move via mouse click on screen - you can't use keyboard keys. What i am trying to acheive is mouse click that are triggered by keyboard events. So far i have had some success in getting a keyboard press to trigger a mouse click on screen. However, due to hackshield (i think) that rappelz uses as an anti-hack measure i am finding it difficult to emulate mouse operations on screen. I cant use mouseclick, controlclick, mousedown, mouseup etc. I am currently only able to make a single click on screen using the MouseClickPlus function:

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

;
; Function Name:  _MouseClickPlus()
; Version added:  0.1
; Description:  Sends a click to window, not entirely accurate, but works
;                minimized.
; Parameter(s):   $Window    =  Title of the window to send click to
;                $Button     =  "left" or "right" mouse button
;                $X       =  X coordinate
;                $Y       =  Y coordinate
;                $Clicks     =  Number of clicks to send
; Remarks:      You MUST be in "MouseCoordMode" 0 to use this without bugs.
; Author(s):      Insolence <insolence_9@yahoo.com>
;
;===============================================================================

Func _MouseClickPlus($Window, $Button = "left", $X = "", $Y = "", $Clicks = 1)
  Local $MK_LBUTTON    =  0x0001
  Local $WM_LBUTTONDOWN   =  0x0201
  Local $WM_LBUTTONUP    =  0x0202
 
  Local $MK_RBUTTON    =  0x0002 
  Local $WM_RBUTTONDOWN   =  0x0204
  Local $WM_RBUTTONUP    =  0x0205

  Local $WM_MOUSEMOVE    =  0x0200
 
  Local $i              = 0
 
  Select
  Case $Button = "left"
     $Button     =  $MK_LBUTTON
     $ButtonDown =  $WM_LBUTTONDOWN
     $ButtonUp   =  $WM_LBUTTONUP
  Case $Button = "right"
     $Button     =  $MK_RBUTTON
     $ButtonDown =  $WM_RBUTTONDOWN
     $ButtonUp   =  $WM_RBUTTONUP
  EndSelect
 
  If $X = "" OR $Y = "" Then
     $MouseCoord = MouseGetPos()
     $X = $MouseCoord[0]
     $Y = $MouseCoord[1]
  EndIf
 
  For $i = 1 to $Clicks
     DllCall("user32.dll", "int", "SendMessage", "hwnd", WinGetHandle($Window), "int", $WM_MOUSEMOVE, "int", 0, "long", _MakeLong($X, $Y))
       
     DllCall("user32.dll", "int", "SendMessage", "hwnd", WinGetHandle($Window), "int", $ButtonDown, "int", $Button, "long", _MakeLong($X, $Y))
       
     DllCall("user32.dll", "int", "SendMessage", "hwnd", WinGetHandle($Window), "int", $ButtonUp, "int", $Button, "long", _MakeLong($X, $Y))
  Next
EndFunc

Func _MakeLong($LoWord,$HiWord)
  Return BitOR($HiWord * 0x10000, BitAND($LoWord, 0xFFFF))
EndFunc

This works well for a single click on screen. However, i now need to do click and drag operations on screen. I was wondering, if anyone with more experience in DLL calls etc could help me to modyify this code in order to produce a mouse click and drag operation.

I have done multiple searches and have not been able to find anything useful yet.

Your help is greatly appreciated. :D

Edited by tjyorkshire

Share this post


Link to post
Share on other sites



:D no one has any ideas then?

ill just have to fiddle around and hope i come up with something then ;)

Share this post


Link to post
Share on other sites

:D no one has any ideas then?

ill just have to fiddle around and hope i come up with something then ;)

You'll need to do another $WM_MOUSEMOVE after the BUTTONDOWN and before the BUTTONUP for the coords you want to drag to.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

something like:

For $i = 1 to $Clicks
     DllCall("user32.dll", "int", "SendMessage", "hwnd", WinGetHandle($Window), "int", $WM_MOUSEMOVE, "int", 0, "long", _MakeLong($X, $Y))
      
     DllCall("user32.dll", "int", "SendMessage", "hwnd", WinGetHandle($Window), "int", $ButtonDown, "int", $Button, "long", _MakeLong($X, $Y))

     DllCall("user32.dll", "int", "SendMessage", "hwnd", WinGetHandle($Window), "int", $WM_MOUSEMOVE, "int", 0, "long", _MakeLong($X, $Y))
      
     DllCall("user32.dll", "int", "SendMessage", "hwnd", WinGetHandle($Window), "int", $ButtonUp, "int", $Button, "long", _MakeLong($X, $Y))

im trying it, it seems to be doing the right type of thing, however it seems to be affected by where the real mouse is positioned on screen. Its like both the emulated mouse and the real mouse are conflicting. Although i seem to be making a work-around using:

DllCall("user32.dll", "int", "SetCursorPos", "int", $X, "int", $Y)

It's all a bit cumbersome but i seem to be getting it working.

Thanks

Edited by tjyorkshire

Share this post


Link to post
Share on other sites

You need an $XStart, $YStart, and an XEnd and $YEnd for parameters. All you have is X (Start) and Y (Start), so you keep clicking the same spot over and over.

Func _MouseClickDragPlus($Window, $Button = "left", $X = 0, $Y = 0, $i_x_end = 0, $i_y_end = 0, $Clicks = 1)
  Local $MK_LBUTTON       =  0x0001
  Local $WM_LBUTTONDOWN   =  0x0201
  Local $WM_LBUTTONUP     =  0x0202

  Local $MK_RBUTTON       =  0x0002
  Local $WM_RBUTTONDOWN   =  0x0204
  Local $WM_RBUTTONUP     =  0x0205

  Local $WM_MOUSEMOVE     =  0x0200

  Local $i                = 0

  Select
  Case $Button = "left"
     $Button     =  $MK_LBUTTON
     $ButtonDown =  $WM_LBUTTONDOWN
     $ButtonUp   =  $WM_LBUTTONUP
  Case $Button = "right"
     $Button     =  $MK_RBUTTON
     $ButtonDown =  $WM_RBUTTONDOWN
     $ButtonUp   =  $WM_RBUTTONUP
  EndSelect

  If $X = 0 OR $Y = 0 Then
     $MouseCoord = MouseGetPos()
     $X = $MouseCoord[0]
     $Y = $MouseCoord[1]
  EndIf

  For $i = 1 to $Clicks
     DllCall("user32.dll", "int", "SendMessage", "hwnd", WinGetHandle($Window), "int", $WM_MOUSEMOVE, "int", 0, "long", _MakeLong($X, $Y))
      
     DllCall("user32.dll", "int", "SendMessage", "hwnd", WinGetHandle($Window), "int", $ButtonDown, "int", $Button, "long", _MakeLong($X, $Y))
     
     DllCall("user32.dll", "int", "SendMessage", "hwnd", WinGetHandle($Window), "int", $WM_MOUSEMOVE, "int", 0, "long", _MakeLong($i_x_end, $i_y_end))
      
     DllCall("user32.dll", "int", "SendMessage", "hwnd", WinGetHandle($Window), "int", $ButtonUp, "int", $Button, "long", _MakeLong($X, $Y))
  Next
EndFunc
Something like that (Mind you, I've no idea if it will work)... I probably would have used PostMessage() for this function myself.


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

that script dont works for me at all I dunno what i wrong

Share this post


Link to post
Share on other sites

You need an $XStart, $YStart, and an XEnd and $YEnd for parameters. All you have is X (Start) and Y (Start), so you keep clicking the same spot over and over.

CODE: AutoIt

Func _MouseClickDragPlus($Window, $Button = "left", $X = 0, $Y = 0, $i_x_end = 0, $i_y_end = 0, $Clicks = 1)

Local $MK_LBUTTON = 0x0001

Local $WM_LBUTTONDOWN = 0x0201

Local $WM_LBUTTONUP = 0x0202

Local $MK_RBUTTON = 0x0002

Local $WM_RBUTTONDOWN = 0x0204

Local $WM_RBUTTONUP = 0x0205

Local $WM_MOUSEMOVE = 0x0200

Local $i = 0

Select

Case $Button = "left"

$Button = $MK_LBUTTON

$ButtonDown = $WM_LBUTTONDOWN

$ButtonUp = $WM_LBUTTONUP

Case $Button = "right"

$Button = $MK_RBUTTON

$ButtonDown = $WM_RBUTTONDOWN

$ButtonUp = $WM_RBUTTONUP

EndSelect

If $X = 0 OR $Y = 0 Then

$MouseCoord = MouseGetPos()

$X = $MouseCoord[0]

$Y = $MouseCoord[1]

EndIf

For $i = 1 to $Clicks

DllCall("user32.dll", "int", "SendMessage", "hwnd", WinGetHandle($Window), "int", $WM_MOUSEMOVE, "int", 0, "long", _MakeLong($X, $Y))

DllCall("user32.dll", "int", "SendMessage", "hwnd", WinGetHandle($Window), "int", $ButtonDown, "int", $Button, "long", _MakeLong($X, $Y))

DllCall("user32.dll", "int", "SendMessage", "hwnd", WinGetHandle($Window), "int", $WM_MOUSEMOVE, "int", 0, "long", _MakeLong($i_x_end, $i_y_end))

DllCall("user32.dll", "int", "SendMessage", "hwnd", WinGetHandle($Window), "int", $ButtonUp, "int", $Button, "long", _MakeLong($X, $Y))

Next

EndFunc

Something like that (Mind you, I've no idea if it will work)... I probably would have used PostMessage() for this function myself.

yes, sorry, i didnt make it clear in my post - am am using a script similar to the one you have provided. It still seems as though the real mouse is interfering. It's strange seeing as i have never seen this SendMessage function used to control the mouse like this before. I would have normally done this via SendInput or one of the built in autoit functions, but this seems the only way to do it without HackShield blocking it.

Share this post


Link to post
Share on other sites

how to use your program?

If I want to click 902, 402

Share this post


Link to post
Share on other sites

thang8843126,

Welcome to the AutoIt forum. :)

But did you notice that the last post in this thread dates from over 5 years ago? Please do not necro-post like this again - just start a new thread and add a link if you feel it is really necessary to do so. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  
Followers 0