Jump to content

Minimized clicking -- Great for game-bots


Insolence
 Share

Recommended Posts

Hi All

was hoping for a little help, (warning i am very new at this and have done no windows programming before so i am probably making a simple mistake)

I am trying to get _MouseClickPlus to work to no avail

I have gone through and tried everything in this post and every other post refering to this function

and cannot get it to work, have even tried to just use the SendMessage Dllcall to do basic stuff but it is not working

I have even tried to get use a dllcall to do a sendmessage to the current window ( Internet explorer window is what i am trying to send the message to)

I am pretty sure that :

I am getting a handle HWND

I have tried every combination i can think of Msg and wParam just to click or move mouse and cannot get it to work in current open window let alone a minimised one

32-bit lParam appears succesfully made of two 16-bit parameters (X,Y co-ords) using _MakeLong function,

I am positive i m not useing SendMessage properly so any help would be appreciated

I have gone through MSDN WIN32 and Com development area trying everything i can think off

SendMessage Doco

and tried various mouse combos messages from

Window Messages

have been looking at this for ages but just can't seem to get it to work

any help would be greatly appreciated.

code trying

(please note alot of these things are prob wrong but i have been trying every combo i can think of)

#include <IE.au3>

#include <GuiConstants.au3>

#include <mouseclickplus.au3>

$o_IE = _IECreate (1)

_IELoadWait($o_IE)

Opt("MouseCoordMode", 0)

AutoItSetOption("WinTitleMatchMode", 4)

$handle = WinGetHandle("classname=IEFrame")

If @error Then

MsgBox(4096, "Error", "Bugger")

Else

$winsize = WinGetPos("classname=IEFrame")

EndIf

$borderwidth = ($winsize[2] - 1024) / 2 ; testing change back to 800 ,600

$titleheight = $winsize[3] - 768 - (2 * $borderwidth)

;testing

$X=500;

$Y=300;

$Button = 0x0001 ; have tried '0x01'

$ButtonDown = 0x0201 ; '0x201'

$ButtonUp = 0x0202 ; '0x202'

$WM_MOUSEMOVE = 0x0200

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

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

DllCall("user32.dll", "int", "SendMessage", "hwnd", $handle, "int", $ButtonDown, "int", $Button,"long",0)

DllCall("user32.dll", "int", "SendMessage", "hwnd", $handle, "int", $ButtonUp, "int", $Button,"long",0)

_MouseClickPlus("IEFrame", "left", 500 - $borderwidth , 300 - $titleheight, 5)

$aR = DllCall("user32.dll", "int", "GetAsyncKeyState", "int", $Button)

MsgBox(1,"",$aR[0])

;_IEAction($o_IE, "invisible")

;_IEAction($o_IE, "visible")

;WinSetState("Microsoft Internet Explorer" , "", @SW_MAXIMIZE)

also a couple of questions

anyone good tutorials on how to find out what is available in a dll and how to use?

any programs i should have or use to track errors like this more easily ,i am currently returning GetAsyncKeyState to see if is clicked as well as checking on html page in javascript but something to track what the sendmessage is doing would be better.

Thanks for your time

Regards

Link to comment
Share on other sites

  • Moderators

MouseClickPlus() doesn't work with every type of window/game/application.

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.

Link to comment
Share on other sites

So Does send message mouse messages not work on an Internet Explorer?

What is the best way to track what is happening with the DLL call

i have tried to see what it is passing (from manual DllCall)

$test = DllCall("user32.dll", "int", "SendMessage", "hwnd", $handle, "int", $WM_MOUSEMOVE, "int",0, "long", _MakeLong($X, $Y))

MsgBox(1,"Result","Return " & $test[0] & " P1:" & $test[1] & " P2:" & $test[2] & " P3:" & $test[3] & " P4:" & $test[4])

it returns (p1,p2,p3 just labels to seperate paramaeters)

the results are

"Return 0 P1:0x008203DC P2:512 P3:0 P4:19661300"

should Param 2 (P2) = 512 as i have assgined $WM_MOUSEMOVE to equal 0x0200

Please excuse my ignorance as this is all new to me

Edited by rqmedes
Link to comment
Share on other sites

Think you could give some kind of a hint as to HOW we use this.... it doesn't say anything except a code you made, doesn't say where to put the code, how to get the code to work, or anything..... I took a wild guess and made "MouseClickPlus.au3" in the includes file, then used #include<MouseClickPlus.au3 and tried using this func, didn't work at all.... "Error reading the file: MouseClickPlus.au3"

Link to comment
Share on other sites

might i ask: is there a website somewhere that has those hex values ur using for mousemove & click...that may show the value to use to send keys

--best

~cdkid

AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide!
Link to comment
Share on other sites

  • 2 months later...

;===============================================================================
;
; 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

I think Larry made the _MakeLong function, so credit goes to him on that. I got a lot of help on the entire thing, I just threw it into a function.

I'll have to figure out how to get the actual area size of the window excluding the title bar for some games, atleast in Diablo II.

EDIT: To get D2 offsets use this code:

$winsize = WinGetPos("Diablo II")
$borderwidth = ($winsize[2] - 800) / 2
$titleheight = $winsize[3] - 600 - (2 * $borderwidth)

msgbox("", "", $borderwidth & " " & $titleheight)

And use it like so:

_MouseClickPlus( "Diablo II", "left", 525 - $borderwidth, 585 - $TitleHeight )
;=================================================================

Hi, great place for lot a good tricks. Thanks to all.

I've not been able to make this smart mouse click work at all.

Any solution or answer would be appreciated.

Rgds.

Link to comment
Share on other sites

  • 1 month later...

Alright I don't know if this was already answered but I came into a conclusion about the window border and title height.

$borderwidth = ($winsize[2] - 800) / 2
$titleheight = $winsize[3] - 600 - (2 * $borderwidth)

Basicly in this the 800and 600 stand for the actualy width and height of the Diablo II window without the border and title bar.

The problem is that not all games are run at 800 by 600 and sometimes you need to resize the game window to fit your needs so you need a different value then 800 and 600. Therefore to make this work you either make the size of the game window 800 by 600(not the whole window such as the command winmove(...) which would include the border and title but just the size of the game, this I would assume could be a pain in the behind if the game doesn't run at that already or doesn't have such option) or you could find the varibles in a different way.

Heres alittle script that will find those varibles(hopefully it works, worked for me).

#include <GUIConstants.au3>
$Win1 = GUICreate("My GUI",318, 70, 192, 125)  
$winsize = WinGetPos($Win1)
GUIDelete($Win1)
$Win2 = GUICreate("My GUI",318, 70, 192, 125, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
$winsize2 = WinGetPos($Win2)
GUIDelete($Win2)
$border = ($winsize[2] - $winsize2[2]) / 2
$title = $winsize[3]  - $winsize2[3] - (2 * $border)
msgbox("", "", $border & " " & $title)

This code gets the border and titleheight for your specific desktop layout or whatever you want to call it.

Basicly that gives you the varibles for whatever window you use unless the window doesn't have a border or title which could cause a problem (I guess running the game in windowed mode would solve that).

This works for me hopefuly it will work for others and if there are any questions anyone is welcome to ask I can't promise that I will know the answer xD.

BTW Sorry for reviving a pretty old post.

Link to comment
Share on other sites

  • 1 month later...

I tried this script on another game (not diablo 2).

And it ran perfect.

But it created another problem:

I made a GUI for my bot 1 button for starting the bot, and another button for closing it.

So lets say my bot function is

Func mybot()

While 1

_MouseClickPlus( $windowname, "left", 622, 44)

sleep(1000)

WEnd

EndFunc

And my close function is:

Func CLOSEClicked()

Exit

EndFunc

My bot can't exit when its running, and all the other functions didn't work either.

With normal mouseclicks i didn't have this problem, is there any way to fix this? Cause i can't make it exit the loop since i can't add any commands to do so since it won't do anything if the bot is enabled.

Anybody else with this problem?

Link to comment
Share on other sites

  • Moderators

I tried this script on another game (not diablo 2).

And it ran perfect.

But it created another problem:

I made a GUI for my bot 1 button for starting the bot, and another button for closing it.

So lets say my bot function is

Func mybot()

While 1

_MouseClickPlus( $windowname, "left", 622, 44)

sleep(1000)

WEnd

EndFunc

And my close function is:

Func CLOSEClicked()

Exit

EndFunc

My bot can't exit when its running, and all the other functions didn't work either.

With normal mouseclicks i didn't have this problem, is there any way to fix this? Cause i can't make it exit the loop since i can't add any commands to do so since it won't do anything if the bot is enabled.

Anybody else with this problem?

Well it's hard to say "For Sure" without seeing the GUI and how you created it, but my guess would be that if your not using GUI Events that your script is not getting the GUIGetMsg() information needed to tell what you want you have done to the GUI while your stuck in that loop if that is all that loop has in it (MouseClick()).

P.S., that has nothing to do with this thread since it was working before the GUI was made... I would suggest that going into the Support Forum or GUI Forum if your going to ask questions outside the actual UDF that your using.

Edited by SmOke_N

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.

Link to comment
Share on other sites

  • 4 weeks later...

So is there any good scripts for minimized clicking?

Or where i have to put my script?

I just want that it clicks and i can surf on forums...

I also wanted to know about "Remarks: You MUST be in "MouseCoordMode" 0 to use this without bugs."

What is MouseCoordMode "0"?

Edited by kanakukk
Link to comment
Share on other sites

  • 2 months later...

;) Just a passing thought. Rather than trying to work it out on a Minimized window it would be cool if you could stimulate a very small window of the same application (game) and work the mouse clicks on it.

Call me crazy but, all i can think of why to minimize a window would be to run some other appliation at same time indirectly hoping that the minimized game takes up less resources which inturn available for the second application to run. Which i hope could be achieved by minimizing the game and instead running a video stream or screen shot slides in a very small windows and sending the relative mouse clicks /commands to the minimized game window. :whistle: (it hurts my brain me no thinky no more)

[quote]I am so clever that sometimes I don't understand a single word of what I am saying.[/quote]

Link to comment
Share on other sites

  • 3 months later...

Alright then. From looking at this topic it doesn't look like a lot of people have had successes with this so I'm posting an example of what I think the script should look like.

The best way of showing if the script has worked or not would be to test the script in MS Paint. That way if the click works then there's a large area of Paint where the effect can be seen. First you click on Paint's Fill button then run the script.

Theoretically the script should click a certain part of the screen and then fill it in a different colour from that of the original (typically white). The script below doesn't work but I'm interested in why it doesn't and I'm sure that if an answer can be found to make it work, it'd make it easier for other people to solve their own minimised windows click scripts.

Opt("MouseCoordMode", 0)

$winsize = WinGetPos("untitled - Paint")
$borderwidth = ($winsize[2] - 1024) / 2
$titleheight = $winsize[3] - 768 - (2 * $borderwidth)

_MouseClickPlus("untitled - Paint","left",500-$borderwidth,200-$TitleHeight)


;===============================================================================
;
; 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
Link to comment
Share on other sites

  • 3 weeks later...
Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

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