Func MakeLong($LoWord, $HiWord)
Return BitOR($HiWord * 0x10000, BitAND($LoWord, 0xFFFF))
EndFunc
; send mouse events to non active window
; button = left, right, none
; event = down, up, click, dclick, move
Func MouseSend($btn, $evt, $xpos, $ypos)
$user32 = DllOpen("user32.dll")
if $user32 = -1 Then
ConsoleWrite("MouseSend: cannot open user32.dll")
Exit
EndIf
;define missing constans
$MK_LBUTTON = 0x0001
$WM_LBUTTONDOWN = 0x0201
;$WM_LBUTTONUP = 0x0202 -> defined in WindowsConstants.au3
$WM_LBUTTONDBLCLK = 0x0203
$MK_RBUTTON = 0x0002
$WM_RBUTTONDOWN = 0x0204
$WM_RBUTTONUP = 0x0205
$WM_RBUTTONDBLCLK = 0x0206
;$WM_MOUSEMOVE = 0x0200 -> defined in WindowsConstants.au3
;map button to event
If $btn = "left" Then
$button = $MK_LBUTTON
$btdown = $WM_LBUTTONDOWN
$btup = $WM_LBUTTONUP
$btdbl = $WM_LBUTTONDBLCLK
ElseIf $btn = "right" Then
$button = $MK_RBUTTON
$btdown = $WM_RBUTTONDOWN
$btup = $WM_RBUTTONUP
$btdbl = $WM_RBUTTONDBLCLK
ElseIf $btn = "none" Then
If Not ($evt = "move") Then
ConsoleWrite(StringFormat("MouseSend: bad call: %s , %s",$btn, $evt))
Exit
EndIf
Else ;error
ConsoleWrite(StringFormat("MouseSend: bad button: %s",$btn))
Exit
EndIf
;send messages
$pos = MakeLong($xpos, $ypos)
Select
Case $evt = "move"
DllCall($user32, "int", "PostMessage", "hwnd", $hwnd, "int", $WM_MOUSEMOVE, "int", 0, "long", $pos)
Case $evt = "down"
DllCall($user32, "int", "PostMessage", "hwnd", $hwnd, "int", $btdown, "int", $button, "long", $pos)
Case $evt = "up"
DllCall($user32, "int", "PostMessage", "hwnd", $hwnd, "int", $btup, "int", 0, "long", $pos)
Case $evt = "click"
DllCall($user32, "int", "PostMessage", "hwnd", $hwnd, "int", $WM_MOUSEMOVE, "int", 0, "long", $pos)
DllCall($user32, "int", "PostMessage", "hwnd", $hwnd, "int", $btdown, "int", $button, "long", $pos)
DllCall($user32, "int", "PostMessage", "hwnd", $hwnd, "int", $btup, "int", 0, "long", $pos)
Case $evt = "dclick"
DllCall($user32, "int", "PostMessage", "hwnd", $hwnd, "int", $WM_MOUSEMOVE, "int", 0, "long", $pos)
DllCall($user32, "int", "PostMessage", "hwnd", $hwnd, "int", $btdown, "int", $button, "long", $pos)
DllCall($user32, "int", "PostMessage", "hwnd", $hwnd, "int", $btup, "int", 0, "long", $pos)
Sleep(10)
DllCall($user32, "int", "PostMessage", "hwnd", $hwnd, "int", $btdbl, "int", $button, "long", $pos)
DllCall($user32, "int", "PostMessage", "hwnd", $hwnd, "int", $btup, "int", 0, "long", $pos)
EndSelect
DllClose($user32)
EndFunc
; send single keyboard event to non active window
; event = pressed, down, up
; kdown = key down delay
; note: supports only lower case keys + NUMx, Fx, some special keys and @
Func KeySend($inkey, $evt ="pressed", $kdown = 50)
$user32 = DllOpen("user32.dll")
if $user32 = -1 Then
ConsoleWrite("KeySend: cannot open user32.dll")
Exit
EndIf
; handling for special keys
Switch StringUpper($inkey)
Case "@"
$skey = 0x40
$lparam = 0x00100001
DllCall($user32, "int", "PostMessage", "hwnd", $hwnd, "int", $WM_KEYDOWN, "int", 0x71, "long", $lparam)
DllCall($user32, "int", "PostMessage", "hwnd", $hwnd, "int", $WM_CHAR, "int", $skey, "long", $lparam)
Sleep(20)
DllCall($user32, "int", "PostMessage", "hwnd", $hwnd, "int", $WM_KEYUP, "int", 0x71, "long", BitOR($lparam, 0xC0000000))
Case "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12"
$skey = 0x6f + Int(StringMid($inkey, 2))
ContinueCase
Case "NUM0", "NUM1", "NUM2", "NUM3", "NUM4", "NUM5", "NUM6", "NUM7", "NUM8" , "NUM9"
if StringUpper(StringLeft($inkey, 3)) = "NUM" Then
$skey = 0x60 + Int(StringMid($inkey, 4))
EndIf
ContinueCase
Case "RETURN", "SPACE", "TAB", "BACK", "END", "HOME", "SNAPSHOT", "INSERT", "DELETE", "LEFT", "RIGHT", "UP", "DOWN"
Switch StringUpper($inkey)
Case "RETURN"
$skey = 0x0D
Case "SPACE"
$skey = 0x20
Case "TAB"
$skey = 0x09
Case "BACK"
$skey = 0x08
Case "END"
$skey = 0x23
Case "HOME"
$skey = 0x24
Case "SNAPSHOT"
$skey = 0x2c
Case "INSERT"
$skey = 0x2d
Case "DELETE"
$skey = 0x2e
Case "LEFT"
$skey = 0x25
Case "RIGHT"
$skey = 0x27
Case "UP"
$skey = 0x26
Case "DOWN"
$skey = 0x28
EndSwitch
$ret = DllCall($user32, "int", "MapVirtualKey", "int", $skey, "int", 0)
$lparam = BitShift($ret[0], -16)
$lparam = BitOr($lparam, 1)
DllCall($user32, "int", "PostMessage", "hwnd", $hwnd, "int", $WM_KEYDOWN, "int", $skey, "long", $lparam)
Sleep($kdown)
DllCall($user32, "int", "PostMessage", "hwnd", $hwnd, "int", $WM_KEYUP, "int", $skey, "long", BitOR($lparam, 0xC0000000))
Case Else ; default lower case key handling
$key = DllCall($user32, "int", "VkKeyScan", "int", Asc(StringLower($inkey)))
$skey = $key[0]
$ret = DllCall($user32, "int", "MapVirtualKey", "int", $skey, "int", 0)
$lparam = BitShift($ret[0], -16)
$lparam = BitOr($lparam, 1)
Select
Case $evt = "pressed"
DllCall($user32, "int", "PostMessage", "hwnd", $hwnd, "int", $WM_KEYDOWN, "int", $skey, "long", $lparam)
Sleep($kdown)
DllCall($user32, "int", "PostMessage", "hwnd", $hwnd, "int", $WM_KEYUP, "int", $skey, "long", BitOR($lparam, 0xC0000000))
Case $evt = "down"
DllCall($user32, "int", "PostMessage", "hwnd", $hwnd, "int", $WM_KEYDOWN, "int", $skey, "long", $lparam)
Case $evt = "up"
DllCall($user32, "int", "PostMessage", "hwnd", $hwnd, "int", $WM_KEYUP, "int", $skey, "long", BitOR($lparam, 0xC0000000))
EndSelect
EndSwitch
DllClose($user32)
EndFunc
; ---------------------------------------
; Function _FileGetNewest()
; Call with: _FileGetNewest($sDirPath [, $iDateType [, $iRecurse [, $sPattern]]])
; Where: $sDirPath is the directory to search
; $iDateType (0ptional) is the type of date to use:
; -3 = (oldest) Modified
; -2 = (oldest) Created
; -1 = (oldest) Accessed
; 0 = Newest Modified (default)
; 1 = Newest Created
; 2 = Newest Accessed
; $iRecurse (Optional): If non-zero causes the search to be recursive.
; $sPattern (Optional): Wildcard pattern for matching
; On success returns a 2-element array where:
; [0] = the full path to the newest file found
; [1] = the date/time stamp of the file "YYYYMMDDhhmmss" [from FileGetTime()]
; On failure returns 0, sets @error and @extended (see code below).
; Author: PsaltyDS
; ---------------------------------------
Func _FileGetNewest($sDirPath, $iDateType = 0, $iRecurse = 0, $sPattern = '*.*')
Local $avNewest[2] = ["", 0]; [0] = file path, [1] = time stamp
Local $flagNewest = True, $iModDateType = $iDateType
Local $hFirst, $sFound, $iFileTime
Local $hSubDirs, $sSubdir, $avFoundRecurse
If StringRight($sDirPath, 1) <> '\' Then $sDirPath &= '\'
If Not FileExists($sDirPath) Then Return SetError(1, 0, 0)
If $iDateType < -3 Or $iDateType > 2 Then Return SetError(1, 1, 0)
If $iDateType < 0 Then
$iModDateType = $iDateType + 3
$flagNewest = False
EndIf
; Start search for files in this dir
$hFirst = FileFindFirstFile($sDirPath & $sPattern)
If ($hFirst <> -1) And (@error = 0) Then
While 1
$sFound = FileFindNextFile($hFirst)
If @error Then ExitLoop
$iFileTime = FileGetTime($sDirPath & $sFound, $iDateType, 1)
If ($avNewest[1] = 0) Or _
(($flagNewest = True) And ($iFileTime > $avNewest[1])) Or _
(($flagNewest = False) And ($iFileTime < $avNewest[1])) Then
$avNewest[0] = $sDirPath & $sFound
$avNewest[1] = $iFileTime
EndIf
WEnd
EndIf
FileClose($hFirst)
; Search subdirectories, if $iRecurse is set
If $iRecurse Then
$hSubDirs = FileFindFirstFile($sDirPath & '*.*')
If ($hSubDirs <> -1) And (@error = 0) Then
While 1
; Start search for subdirectories
$sSubdir = FileFindNextFile($hSubDirs)
If @error = 0 Then
; Only recurse to directories
If StringInStr(FileGetAttrib($sDirPath & $sSubdir), "D") Then
; Search a subdirectory
$avFoundRecurse = _FileGetNewest($sDirPath & $sSubdir, $iDateType, $iRecurse, $sPattern)
If @error Then
; Nothing found
ContinueLoop
Else
; Check if newest
If $avFoundRecurse[1] > $avNewest[1] Then $avNewest = $avFoundRecurse
If ($avNewest[1] = 0) Or _
(($flagNewest = True) And ($avFoundRecurse[1] > $avNewest[1])) Or _
(($flagNewest = False) And ($avFoundRecurse[1] < $avNewest[1])) Then
$avNewest = $avFoundRecurse
EndIf
EndIf
EndIf
Else
; Done looking for subdirs
ExitLoop
EndIf
WEnd
EndIf
EndIf
If $avNewest[1] = 0 Then
Return SetError(2, 0, 0); None found
Else
Return $avNewest
EndIf
EndFunc ;==>_FileGetNewest
Func _SendMinimizedMessage($winhandle,$msgstring,$raw = 0)
If $winhandle = "" Then
;; illegal number of parameters?
;~ MsgBox(32, "KCH: Problem", "SendMinimizedMessage() called with bad number of params?")
Return
EndIf
Local $i = 0
while $i < StringLen($msgstring)
$i = $i + 1
Local $var = StringMid($msgstring,$i,1)
if $raw = 1 Then
_SendMinimizedVK($winhandle,StringMid($msgstring,$i,1))
Else
if $var = "{" Then
Local $var2 = StringInStr(StringMid($msgstring,$i+1),"}",2)
_SendMinimizedVK($winhandle,StringMid($msgstring,$i+1,$var2-1))
$i = $i + $var2
Else
_SendMinimizedVK($winhandle,StringMid($msgstring,$i,1))
EndIf
EndIf
Sleep(50)
WEnd
Return
EndFunc
Func _SendMinimizedVK($winhandle,$vkstring)
Local $var = _GetHexByKey_Switch($vkstring)
if Not ($var = -1) Then
DllCall("user32.dll", "int", "SendMessage", _
"hwnd", $winhandle, _
"int", $WM_KEYDOWN, _
"int", _GetHexByKey_Switch($vkstring), _
"long", 0)
DllCall("user32.dll", "int", "PostMessage", _ ;SendMessage only works ingame, not in lobby
"hwnd", $winhandle, _
"int", $WM_KEYUP, _
"int", _GetHexByKey_Switch($vkstring), _
"long", 0)
;~ ConsoleWrite(1 & @CRLF) ;debug Success
Return 1
EndIf
;~ ConsoleWrite(0 & @CRLF) ;debug Failed
Return 0
EndFunc
Func _GetHexByKey_Switch($sKey)
Switch $sKey
Case "LeftMouse"
Return 0x01
Case "RightMouse"
Return 0x02
Case "MiddleMouse"
Return 0x04
Case "X1Mouse"
Return 0x05
Case "X2Mouse"
Return 0x06
Case "BACKSPACE"
Return 0x08
Case "TAB"
Return 0x09
Case "CLEAR"
Return 0x0C
Case "ENTER"
Return 0x0D
Case "SHIFT"
Return 0x10
Case "CTRL"
Return 0x11
Case "ALT"
Return 0x12
Case "PAUSE"
Return 0x13
Case "CAPSLOCK"
Return 0x14
Case "ESC"
Return 0x1B
Case " "
Return 0x20
Case "SPACE"
Return 0x20
Case "PAGE UP"
Return 0x21
Case "PAGE DOWN"
Return 0x22
Case "END"
Return 0x23
Case "HOME"
Return 0x24
Case "LEFT"
Return 0x25
Case "UP"
Return 0x26
Case "RIGHT"
Return 0x27
Case "DOWN"
Return 0x28
Case "SELECT"
Return 0x29
Case "PRINT"
Return 0x2A
Case "EXECUTE"
Return 0x2B
Case "PRINT SCREEN"
Return 0x2C
Case "INS"
Return 0x2D
Case "DEL"
Return 0x2E
Case "0"
Return 0x30
Case "1"
Return 0x31
Case "2"
Return 0x32
Case "3"
Return 0x33
Case "4"
Return 0x34
Case "5"
Return 0x35
Case "6"
Return 0x36
Case "7"
Return 0x37
Case "8"
Return 0x38
Case "9"
Return 0x39
Case "A"
Return 0x41
Case "B"
Return 0x42
Case "C"
Return 0x43
Case "D"
Return 0x44
Case "E"
Return 0x45
Case "F"
Return 0x46
Case "G"
Return 0x47
Case "H"
Return 0x48
Case "I"
Return 0x49
Case "J"
Return 0x4A
Case "K"
Return 0x4B
Case "L"
Return 0x4C
Case "M"
Return 0x4D
Case "N"
Return 0x4E
Case "O"
Return 0x4F
Case "P"
Return 0x50
Case "Q"
Return 0x51
Case "R"
Return 0x52
Case "S"
Return 0x53
Case "T"
Return 0x54
Case "U"
Return 0x55
Case "V"
Return 0x56
Case "W"
Return 0x57
Case "X"
Return 0x58
Case "Y"
Return 0x59
Case "Z"
Return 0x5A
Case "LWin"
Return 0x5B
Case "RWin"
Return 0x5C
Case "NUMPAD0"
Return 0x60
Case "NUMPAD1"
Return 0x61
Case "NUMPAD2"
Return 0x62
Case "NUMPAD3"
Return 0x63
Case "NUMPAD4"
Return 0x64
Case "NUMPAD5"
Return 0x65
Case "NUMPAD6"
Return 0x66
Case "NUMPAD7"
Return 0x67
Case "NUMPAD8"
Return 0x68
Case "NUMPAD9"
Return 0x69
Case "Multiply"
Return 0x6A
Case "Add"
Return 0x6B
Case "Separator"
Return 0x6C
Case "Subtract"
Return 0x6D
Case "Decimal"
Return 0x6E
Case "Divide"
Return 0x6F
Case "F1"
Return 0x70
Case "F2"
Return 0x71
Case "F3"
Return 0x72
Case "F4"
Return 0x73
Case "F5"
Return 0x74
Case "F6"
Return 0x75
Case "F7"
Return 0x76
Case "F8"
Return 0x77
Case "F9"
Return 0x78
Case "F10"
Return 0x79
Case "F11"
Return 0x7A
Case "F12"
Return 0x7B
Case "F13"
Return 0x7C
Case "F16"
Return 0x7F
Case "F17"
Return 0x80
Case "F18"
Return 0x81
Case "F19"
Return 0x82
Case "F20"
Return 0x83
Case "F21"
Return 0x84
Case "F22"
Return 0x85
Case "F23"
Return 0x86
Case "F24"
Return 0x87
Case "NUM LOCK"
Return 0x90
Case "SCROLL LOCK"
Return 0x91
Case "LSHIFT"
Return 0xA0
Case "RSHIFT"
Return 0xA1
Case "LCTRL"
Return 0xA2
Case "RCTRL"
Return 0xA3
Case "LMENU"
Return 0xA4
Case "RMENU"
Return 0xA5
Case "="
Return 0x92
Case ";"
Return 0xBA
Case ":"
Return 0xBA
Case "+"
Return 0xBB
Case ","
Return 0xBC
Case "-"
Return 0xBD
Case "."
Return 0xBE
Case "/"
Return 0xBF
Case "?"
Return 0xBF
Case "`"
Return 0xC0
Case "~"
Return 0xC0
Case "["
Return 0xDB
Case "{"
Return 0xDB
Case "\"
Return 0xDC
Case "|"
Return 0xDC
Case "]"
Return 0xDD
Case "}"
Return 0xDD
Case "'"
Return 0xDE
Case '"'
Return 0xDE
Case "<"
Return 0xE2
Case ">"
Return 0xE2
EndSwitch
Return -1
EndFunc ;==>_GetHexByKey_Switch
;===============================================================================
;
; Function Name: _MouseClickMinimized()
; 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 (cpf: or 2???) to use this without bugs.
; Author(s): Insolence <[email protected]>
;
;===============================================================================
Func _MouseClickMinimized($Window, $Button = "left", $X = "", $Y = "", $Clicks = 1, $handle = 0)
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
if $handle = 1 Then
Local $winhandle = $Window
Elseif $handle = 0 Then
Local $winhandle = WinGetHandle($Window)
EndIf
Select
Case $Button = "right"
$Button = $MK_RBUTTON
$ButtonDown = $WM_RBUTTONDOWN
$ButtonUp = $WM_RBUTTONUP
Case $Button = "left"
$Button = $MK_LBUTTON
$ButtonDown = $WM_LBUTTONDOWN
$ButtonUp = $WM_LBUTTONUP
Case Else ;; CPF
;; illegal number of parameters?
;~ MsgBox(32, "KCH: Problem", "_MouseClickPlus() called with bad number of params?")
Return
EndSelect
;; makes no sense to send click to minimized window with current mouse coordinates
If $X = "" Or $Y = "" Then
;; illegal number of parameters?
;~ MsgBox(32, "KCH: Problem", "_MouseClickPlus() called with bad number of params?")
Return
EndIf
For $i = 1 To $Clicks
DllCall("user32.dll", "int", "SendMessage", _
"hwnd", $winhandle, _
"int", $WM_MOUSEMOVE, _
"int", 0, _
"long", _MakeLong($X, $Y))
DllCall("user32.dll", "int", "SendMessage", _
"hwnd", $winhandle, _
"int", $ButtonDown, _
"int", $Button, _
"long", _MakeLong($X, $Y))
Sleep(10)
DllCall("user32.dll", "int", "SendMessage", _
"hwnd", $winhandle, _
"int", $ButtonUp, _
"int", $Button, _
"long", _MakeLong($X, $Y))
Next
EndFunc ;==>_MouseClickMinimized
;===============================================================================
;
; Function Name: _MouseMoveMinimized()
; Version added: 0.1
; Description: Sends a move message to window, works minimized.
; Parameter(s): $Window = Title of the window to send click to
; $X = X coordinate
; $Y = Y coordinate
; Remarks: You MUST be in "MouseCoordMode" 0 (cpf: or 2???) to use this without bugs.
; Author(s): Cris Fuhrman (based on code by Insolence <[email protected]>)
;
;===============================================================================
Func _MouseMoveMinimized($Window, $X = "", $Y = "", $handle = 0)
Local $WM_MOUSEMOVE = 0x0200
Local $i = 0
if $handle = 1 Then
Local $winhandle = $Window
Elseif $handle = 0 Then
Local $winhandle = WinGetHandle($Window)
EndIf
If $X = "" Or $Y = "" Then
;~ MsgBox(32, "KCH: Problem", "_MouseMovePlus() called with bad number of params?")
Return
EndIf
DllCall("user32.dll", "int", "SendMessage", _
"hwnd", $winhandle, _
"int", $WM_MOUSEMOVE, _
"int", 0, _
"long", _MakeLong($X, $Y))
EndFunc ;==>_MouseMoveMinimized
Func _MakeLong($LoWord, $HiWord)
Return BitOR($HiWord * 0x10000, BitAND($LoWord, 0xFFFF))
EndFunc ;==>_MakeLong