Jump to content

send mouseclick to specified (minimized) window


Recommended Posts

hi,

i wrote a little scritp to let autoit do some work in a game.

Once activated it "presses" a key, followed by a mouseclick again and again until i stop/pause it

however, if i alt+tab or just minimize the window, the mousclicks+keystrokes points to the desktop.

- Is there a way to send the keystrokes+mouseclicks to the windows named XYZ or something, so i can surf/work/whatever in the meantime?

- somehow the script stops working after 20-30 minutes - is there a way to bypass this?

here is the code:

; Place at the top of your script
$g_szVersion = "precast version 0.1"
If WinExists($g_szVersion) Then Exit; It's already running
AutoItWinSetTitle($g_szVersion)
; Rest of your script goes here

; Press Esc to terminate script, Pause/Break to "pause"

sleep(2000);
Global $Paused
Global $lov
Global $delay
#delay=1000
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{PGUP}", "kurzercast")
HotKeySet("{PGDN}", "langercast")

HotKeySet("{HOME}", "ToggleCast")
HotKeySet("{END}", "Terminate")
HotKeySet("+!d", "ShowMessage") ;Shift-Alt-d
#HotKeySet("{HOME}", "Linksklick")
#HotKeySet("{END}", "Cast")


;;;; Body of program would go here;;;;
While 1
    while NOT $lov
        Sleep($delay)
        ControlSend("Ragnarok", "", "", "{l}")
        MouseClick("left")
    wend

    while $lov
        Sleep($delay)
        ControlSend("Ragnarok", "", "", "{F2}")
        MouseClick("left")
    wend

#   Sleep(1000)
#   ControlSend("Ragnarok", "", "", "{F1}")
#   MouseClick("left")
WEnd
;;;;;;;;

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

Func ToggleCast()
    $lov = NOT $lov

    ToolTip("")
EndFunc

Func Terminate()
    Exit 0
EndFunc

Func ShowMessage()
    MsgBox(4096,"","This is a message.")
EndFunc

Func Linksklick()
    MouseClick("left")
EndFunc


#WinKill("", "")


Func Cast()
    ControlSend("Ragnarok", "", "", "{F1}")
    MouseClick("left")
EndFunc

Func kurzercast()
    $delay=1000
EndFunc

Func langercast()
    $delay=10000
EndFunc

thx in advance for any help :)

Link to comment
Share on other sites

hi and thanks for your help.

i tried _MouseClickPlus, but somehow it does not even work for me with notepad.

i am sure i got the right window name (its "Unbenannt - Editor", german for "Untitled - Notepad"), because the WinActivate() works

here is the slightly modified code:

Opt("WinTitleMatchMode", 2)
Opt("MouseCoordMode", 0)

sleep(3000);
WinActivate("Unbenannt - Editor");
MouseX()

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

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

Func MouseX()
_MouseClickPlus("Unbenannt - Editor", "right")
#//_MouseClickPlus("Unbenannt - Editor", "right",  X, Y, CLICKS)
EndFunc ;==>MouseX
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...