I'm writing an automation script with autoit: http://www.autoitscript.com/autoit3/index.shtml. In the process I need to take a screenshot of a user selected area.
How can I recognize the mouse-drag select operation with Autoit 3? I basically need some way to get the coordinates of the selected rectangle...
rasim from the Autoit forums was kind enough to answer this question of mine with a working example: http://www.autoitscript.com/forum/index.php?showtopic=86894&st=0&gopid=623824&#entry623824
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#include <ScreenCapture.au3>
Global Const $WM_LBUTTONDOWN = 0x0201
Global $hDLL = DllOpen("User32.dll")
Global $Drag = False
Global $aCoord_Start
Global $aCoord_End
Global $iLeft, $iTop, $iRight, $iBottom
Global $sCapture = False
HotKeySet("{Esc}", "_Exit")
Global $pStub_MouseProc = DllCallbackRegister ("_Mouse_Handler", "int", "int;ptr;ptr")
Global $hHookMouse = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($pStub_MouseProc), _WinAPI_GetModuleHandle(0), 0)
While 1
If $sCapture Then
$sCapture = False
_ScreenCapture_Capture(#ScriptDir & "\Capture.jpg", $iLeft, $iTop, $iRight, $iBottom)
EndIf
Sleep(100)
WEnd
Func _Mouse_Handler($nCode, $wParam, $lParam)
If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hHookMouse, $nCode, $wParam, $lParam)
Switch $wParam
Case $WM_LBUTTONDOWN
$aCoord_Start = MouseGetPos()
Case $WM_MOUSEMOVE
If _IsPressed("01", $hDLL) Then $Drag = True
Case $WM_LBUTTONUP
$aCoord_End = MouseGetPos()
If $Drag = True Then
$Drag = False
If $aCoord_Start[0] < $aCoord_End[0] Then
$iLeft = $aCoord_Start[0]
$iRight = $aCoord_End[0]
Else
$iLeft = $aCoord_End[0]
$iRight = $aCoord_Start[0]
EndIf
If $aCoord_Start[1] < $aCoord_End[1] Then
$iTop = $aCoord_Start[1]
$iBottom = $aCoord_End[1]
Else
$iTop = $aCoord_End[1]
$iBottom = $aCoord_Start[1]
EndIf
$sCapture = True
Return 0
EndIf
EndSwitch
Return _WinAPI_CallNextHookEx($hHookMouse, $nCode, $wParam, $lParam)
EndFunc
Func _Exit()
DllCallbackFree($pStub_MouseProc)
_WinAPI_UnhookWindowsHookEx($hHookMouse)
DllClose($hDLL)
Exit
EndFunc
Related
Yeah So, I'm coding a Roblox game and this script gets an error every time, I even restarted roblox studio to try fixing it but it didn't work and I tried messing around with the code but I couldn't figure it out, can someone please help?
Script:
local PetModule = require(ServerModules.PetModule)
Module Code:
local module = {}
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Pet = ReplicatedStorage.Pet
function module.EquipPet(Player, PetName)
local PetModel = Pet:FindFirstChild(PetName)
if PetModel then
PetModel = PetModel:Clone()
PetModel.Parent = workspace.Pet:FindFirstChild((Player.Name))
if Player then
local Character = Player.Character
if Character then
if not Character.HumanoidRootPart:FindFirstChild("PetAttachments") then
local PetAttachments = Instance.new("Folder")
PetAttachments.Name = "PetAttachments"
PetAttachments.Parent = Character.HumanoidRootPart
local PetAttachments = Character.HumanoidRootPart:FindFirstChild("PetAttachments")
if PetAttachments then
local att0 = Instance.new("Attachment")
att0.Name = "Attachment1"
att0.Position = PetModel:FindFirstChild("AttachmentPosition").Value
att0.Parent =Character.HumanoidRootPart
local att1 = Instance.New("Attachment")
att1.Name = "Attachment2"
att1.Parent = PetModel.PrimaryPart
local AlignPosition = Instance.new("AlignPosition")
AlignPosition.Attachment0 = att0
AlignPosition.Attachment1 = att1
AlignPosition.RigidityEnabled = false
AlignPosition.MaxForce = PetModel.MaxForce.Value
AlignPosition.Responsiveness = PetModel.Responsiveness.Value
AlignPosition.Parent = PetModel.PrimaryPart
local AlignOrientation = Instance.new("AlignOrientation")
AlignOrientation.Attachment0 = att0
AlignOrientation.Attachment1 = att1
AlignOrientation.RigidityEnabled = false
AlignOrientation.MaxTorque = PetModel.MaxForce.Value
AlignOrientation.Responsiveness = PetModel.Responsiveness.Value
AlignOrientation.Parent = PetModel.PrimaryPart
game:GetService("RunService").Heartbeat:Connect(function()
att0.Position = PetModel.AttachmentPosition.Value
AlignPosition.MaxForce = PetModel.MaxForce.Value
AlignOrientation.MaxTorque = PetModel.MaxForce.Value
AlignPosition.Responsiveness = PetModel.Responsiveness
end)
end
end
end
end
end
function module.UnequipPet(Player)
end
function module.UnequipAllPet(Player)
end
return module
end
If anyone could help me fix this it would be great.
make sure to put "return module" at the end!
return module
is within the function. Try to put it free at the end of the code and...
I'm not sure, but I think it's because you're creating an event connection within module, I had this problem right now. I just stopped creating events within the Module and the problem stopped.
Try removing this from de Code.
game:GetService("RunService").Heartbeat:Connect(function()
att0.Position = PetModel.AttachmentPosition.Value
AlignPosition.MaxForce = PetModel.MaxForce.Value
AlignOrientation.MaxTorque = PetModel.MaxForce.Value
AlignPosition.Responsiveness = PetModel.Responsiveness
end)
I have this code:
If $choixListAction == "ACTION1" Then
HotKeySet("{ENTER}", "_getPos")
EndIf
Func _getPos()
Global $posSouris = MouseGetPos()
$posX = MouseGetPos(0)
$posY = MouseGetPos(1)
Return $posX & ":" & $posY
EndFunc
I press ENTER but any action work.
Maybe your script isn't running anymore to process the hotkey. The following code works for me:
HotKeySet("{ENTER}", "_MyFunc")
While True
Sleep(150)
WEnd
Func _MyFunc()
MsgBox(0, "MyFunc", "Hello :)")
EndFunc ;==>_MyFunc
I am trying to automate drag and drop between two File Explorers on windows OS. I could find online help to drag and drop implementation for Browsers.
But no help for drag and drop for file to another File Explorer.
Use for this the Shell.Application object. To get the selection from the explorer you can use the following function:
;===============================================================================
; Function Name....: _ActiveExplorer_GetSelected
; Description......: Creates an array with
; - Count of selected files/folder
; - Path of active Explorer window and
; - the path/es of selected file/s /folder
; Requirement(s)...: Opened Explorer window
; Return Value(s)..: Array with data, $a[0] = Count, $a[1] = Folderpath, $a[2..] = File/Foldername
; .................: ATTENTION! Last index $a[0]+1 !!
; Author(s)........: BugFix ( AutoIt#bug-fix.info )
;===============================================================================
Func _ActiveExplorer_GetSelected()
Local $oShell = ObjCreate("Shell.Application")
Local $oExplorer, $sPath, $oFolderView, $iCount = 0, $sSelectedFiles = '', $n = 2
Local $oShellWindows = $oShell.Windows
For $i = 0 To $oShellWindows.Count -1
$oExplorer = $oShellWindows($i)
$sPath = StringReplace(StringReplace(StringTrimLeft($oExplorer.LocationURL, 8), '%20', ' '), '/', '\')
If WinGetTitle('[ACTIVE]') = $sPath Then ExitLoop
Next
$oFolderView = $oExplorer.Document.SelectedItems()
$iCount = $oFolderView.Count
Local $aOut[$iCount +2]
$aOut[0] = $iCount
$aOut[1] = $sPath
If $iCount = 0 Then
Return ''
Else
For $oFolderItem In $oFolderView
$aOut[$n] = $oFolderItem.Name
$n += 1
Next
Return $aOut
EndIf
EndFunc ; ==>_ActiveExplorer_GetSelected
This script does not pause until the button is enabled:
While Not ControlCommand('Network config', '','QWidget1', 'IsEnabled', '')
Sleep(500)
WEnd
The button is grayed out initially.
Windows title: Network config
CLassnameNN: QWidget1
How can I fix this?
Local $cE = 0
AdlibRegister("enControl", 1000)
While 1
WEnd
Func enControl()
Local $wActive = WinActivate("Network config")
Local $isActive = WinActive($wActive)
If $isActive = 0 Then
ConsoleWrite("Could not make window active")
Return
EndIf
$cE = ControlEnable("Network config", ", "QWidget1")
If $cE = 0 Then
ConsoleWrite("Could not enable the control")
Else
ConsoleWrite("Succesfully enabled the control")
Sleep(500)
EndIf
EndFunc
Making sure the window is active and using ControlEnable function should help.
I'm trying to read PDF' page size eg.height X weight. Page size can be found in
File -> Properties -> Page Size
I used the code below to fetch the property value:
$path = FileOpenDialog("Select a file to read attributes",#ScriptDir,"All (*.*)")
$prop = _GetExtProperty($path,-1)
_ArrayDisplay($prop,"Property Array")
Func _GetExtProperty($sPath, $iProp)
Local $iExist, $sFile, $sDir, $oShellApp, $oDir, $oFile, $aProperty, $sProperty
$iExist = FileExists($sPath)
If $iExist = 0 Then
SetError(1)
Return 0
Else
$sFile = StringTrimLeft($sPath, StringInStr($sPath, "\", 0, -1))
$sDir = StringTrimRight($sPath, (StringLen($sPath) - StringInStr($sPath, "\", 0, -1)))
$oShellApp = ObjCreate ("shell.application")
$oDir = $oShellApp.NameSpace ($sDir)
$oFile = $oDir.Parsename ($sFile)
If $iProp = -1 Then
Local $aProperty[35]
For $i = 0 To 34
$aProperty[$i] = $oDir.GetDetailsOf ($oFile, $i)
Next
Return $aProperty
Else
$sProperty = $oDir.GetDetailsOf ($oFile, $iProp)
If $sProperty = "" Then
Return 0
Else
Return $sProperty
EndIf
EndIf
EndIf
EndFunc ;==>_GetExtProperty
By using above code i managed to get file size in MB, Created date , Modified date, Location and so on, but not Page Size. Appreciated, if anyone could advice how I can get page size. Any reference, advice or sample code is highly appreciated.
Nearly the same, but maybe it helps.
#include <Array.au3>
;===============================================================================
; Function Name.....: _FileGetProperty
; Description.......: Returns a property or all properties for a file.
; Version...........: 1.0.2
; Change Date.......: 2008-07-28
; AutoIt Version....: 3.2.12.1
;
; Parameter(s)......: $S_PATH - String containing the file path to return the property from.
; $S_PROPERTY - [optional] String containing the name of the property to return. (default = "")
; Requirements(s)...: None
; Return Value(s)...: Success: Returns a string containing the property value.
; If $S_PROPERTY is empty, an two-dimensional array is returned:
; $av_array[0][0] = Number of properties.
; $av_array[1][0] = 1st property name.
; $as_array[1][1] = 1st property value.
; $av_array[n][0] = nth property name.
; $as_array[n][1] = nth property value.
; Failure: Returns 0 and sets #error to:
; 1 = The folder $S_PATH does not exist.
; 2 = The property $S_PROPERTY does not exist or the array could not be created.
; 3 = Unable to create the "Shell.Application" object $objShell.
;
; Author(s).........: - Simucal <Simucal#gmail.com>
; - Modified by: Sean Hart <autoit#hartmail.ca>
; - Modified by: teh_hahn <sPiTsHiT#gmx.de>
; Company...........: None
; URL...............: None
; Note(s)...........: None
;===============================================================================
Global $re = _FileGetProperty(#ScriptDir & '\1Tutorial - AutoItWiki1.pdf')
If #error Then MsgBox(16, 'ERROR', 'Error: ' & #error & #CRLF & '1 = The folder $S_PATH does not exist.' & #CRLF & _
'2 = The property $S_PROPERTY does not exist or the array could not be created.' & #CRLF & _
'3 = Unable to create the "Shell.Application" object $objShell.')
_ArrayDisplay($re)
Func _FileGetProperty(Const $S_PATH, Const $S_PROPERTY = "")
If Not FileExists($S_PATH) Then Return SetError(1, 0, 0)
Local Const $S_FILE = StringTrimLeft($S_PATH, StringInStr($S_PATH, "\", 0, -1))
Local Const $S_DIR = StringTrimRight($S_PATH, StringLen($S_FILE) + 1)
Local Const $objShell = ObjCreate("Shell.Application")
If #error Then Return SetError(3, 0, 0)
Local Const $objFolder = $objShell.NameSpace($S_DIR)
Local Const $objFolderItem = $objFolder.Parsename($S_FILE)
If $S_PROPERTY Then
For $i = 0 To 99
If $objFolder.GetDetailsOf($objFolder.Items, $i) = $S_PROPERTY Then Return $objFolder.GetDetailsOf($objFolderItem, $i)
Next
Return SetError(2, 0, 0)
EndIf
Local $av_ret[1][2] = [[1]]
For $i = 0 To 99
If $objFolder.GetDetailsOf($objFolder.Items, $i) Then
ReDim $av_ret[$av_ret[0][0] + 1][2]
$av_ret[$av_ret[0][0]][0] = $objFolder.GetDetailsOf($objFolder.Items, $i)
$av_ret[$av_ret[0][0]][1] = $objFolder.GetDetailsOf($objFolderItem, $i)
$av_ret[0][0] += 1
EndIf
Next
If Not $av_ret[1][0] Then Return SetError(2, 0, 0)
$av_ret[0][0] -= 1
Return $av_ret
EndFunc ;==>_FileGetProperty