AutoIt's ControlCommand does not pause while a button is grayed out - while-loop

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.

Related

Autoit HotKeySet bug

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

python - win32com -> powerpoint.application: skip password pop up dialogue

I have a lot of powerpoint file need to open. Some of the files require password, and I need to skip the pop up dialog. How can I skip this dialogue, and jump to the next path?
Example:
I'm using win32com method to use powerpoint.application.
This is my code:
filename = 'test.pptx'
PPTApplication = win32com.client.Dispatch("PowerPoint.Application")
PPTApplication.DisplayAlerts = False
PPTApplication.Presentations.Open(filename,ReadOnly=True,WithWindow=False)
This is the function that I've checked:
https://msdn.microsoft.com/en-us/vba/powerpoint-vba/articles/presentations-open-method-powerpoint
DisplayAlert is set to False and ReadOnly is set to True, but the dialogue still pops up.
Solved,
import win32gui
import win32con
import win32com
import threading
flag = False
def terminate():
global flag
while (1):
hwnd = win32gui.FindWindow(None, 'Password')
if hwnd != 0:
win32gui.PostMessage(hwnd,win32con.WM_CLOSE,0,0)
break
if flag == True:
break
...
t = threading.Thread(target=terminate)
t.start()
try:
PPTApplication = win32com.client.Dispatch("PowerPoint.Application")
PPTApplication.Presentations.Open(filename,ReadOnly=True,WithWindow=False)
except:
t.join()
None
if t.is_alive():
flag = True
t.join()
...

How to implement Automation for Drag and drop between two file explorers on Windows

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

Autoit PixelGetColor not working

Hello there everyone,
I have recently downloaded a bot for a game that I play, this bot uses Autoit to automate movements on screen, alongside Autoit I downloaded some scripts that allow me to automate in-game movements. I downloaded these scripts on my main pc and my laptop so I can run them on 2 accounts if need be. The download is exactly the same and although the bot works perfectly on my PC, it does something weird on my laptop:
The cursor seems to be able to go to places I have specificly told it to go but once it needs to imagesearch or pixelsearch it simply stops. The program doesnt stop running and will continue performing the actions that it can perform, at the right timing, however all imagesearching functions get left out.
The only major diference between the pc and laptop is that the laptop is running windows 8.
Things Iv tried by searching prior to asking here:
I have read that imagesearch.dll should be in sysWOW64 in order for it to work and I beleive I have done that by copying the DLL files and pasting them in syswow64. That did not help.
I also tried adding #requireadmin to the top of the script which did not help either.
this is happening with ALL the scripts I downloaded. They all work on pc and none work on laptop. I dont have alot of understanding with this code as I did not write it myself. However I have familirized myself with it a little as I do edit it for my personal uses on my pc and make it work very well. So I thought that it not functioning on my laptop must be some amateur mistake about windows 8 or similar.
here is an example script.
#RequireAdmin
#include <Misc.au3>
HotKeySet("{[}", "MakeLock")
HotKeySet("{z}", "Start")
HotKeySet("{ESC}", "_Exit")
HotKeySet("{x}", "Shafts")
HotKeySet("{c}", "Heads")
HotKeySet("{v}", "bsb")
$handle = WinGetHandle("Wurm Online", "")
Global $running=0
Global $shaftLoc
Global $headLoc
Global $shaft=0
Global $head=0
Global $bsb=0
Global $bsbloc
Func _Exit()
Exit
EndFunc ;==>_Exit
Func Getfrombsb()
MouseMove($bsbloc[0], $bsbloc[1], 5)
MouseDown("left")
Sleep(100)
MouseMove($shaftloc[0], $shaftloc[1], 5)
Sleep(100)
MouseUp("left")
sleep(2500)
send ("4")
sleep(250)
Send("{Enter}")
sleep(3000)
EndFunc
Func Shafts()
MsgBox(0, "", "title of items")
$shaft=1
EndFunc
Func Drop()
MouseMove($shaftloc[0], $shaftloc[1], 5)
MouseDown("left")
Sleep(250)
MouseMove($bsbloc[0], $bsbloc[1], 5)
MouseUp("left")
EndFunc
Func bsb()
MsgBox(0, "", "item in bsb")
$bsb=1
EndFunc
Func Heads()
MsgBox(0, "", "Click on what ur continuing")
$head=1
EndFunc
Func continue()
MouseMove($shaftloc[0], $shaftloc[1], 5)
MouseClick("left")
Sleep(100)
MouseMove($shaftloc[0], $shaftloc[1], 5)
MouseClick("right")
Sleep(1000)
$line = GetLine()
If IsArray($line) Then
Local $random2 = Random(200, 250, 1)
MouseMove($line[0], $line[1]+3*16-8, 5)
Sleep($random2-51)
MouseMove($line[0]+120, $line[1]+3*16-8, 5)
Sleep($random2+38)
MouseMove($line[0]+120, $line[1]+3*16-8+2*16, 5)
Sleep(500)
MouseMove($line[0]+200, $line[1]+3*16-8+2*16, 5)
Sleep($random2+161)
MouseMove($line[0]+200, $line[1]+3*16-8+2*16+44, 25)
Sleep($random2)
MouseClick("left")
EndIf
EndFunc
Func Start()
if $running==0 Then
$running=1
TrayTip("", "Macro started", 5)
ElseIf $running==1 Then
$running=0
TrayTip("", "Macro stopped", 5)
EndIf
EndFunc
Func GetLine()
$pos = MouseGetPos()
$samp = $pos
For $i = 0 To 48 Step 1
$samp[0] = $pos[0]+32
$samp[1] = $pos[1]+$i
$s0 = PixelGetColor($samp[0], $samp[1], $handle)
If $s0 == 0xFFFFFF Then
$s1 = PixelGetColor($samp[0]+1, $samp[1], $handle)
If $s1 == 0xFFFFFF Then
$s2 = PixelGetColor($samp[0]+2, $samp[1], $handle)
$s3 = PixelGetColor($samp[0]+3, $samp[1], $handle)
If $s2 == 0xFFFFFF AND $s3 == 0xFFFFFF Then
$line = $samp
ExitLoop
EndIf
EndIf
EndIf
$line = 0
Next
Return $line
EndFunc
While (1)
if _IsPressed("01") And $shaft==1 Then
$shaftloc = MouseGetPos()
$shaft=0
MsgBox(0, "", "shaft loc loaded")
endif
if _IsPressed("01") And $head==1 Then
$headloc = MouseGetPos()
$head=0
MsgBox(0, "", "head loc loaded")
EndIf
if _IsPressed("01") And $bsb==1 Then
$bsbloc = MouseGetPos()
$bsb=0
MsgBox(0, "", "bsb loc loaded")
EndIf
if $running==1 Then
Getfrombsb()
Local $random = Random(24000, 25000, 1)
continue()
Sleep($random)
sleep(500)
Drop()
sleep(2000)
Drop()
sleep(2000)
EndIf
Sleep(10)
WEnd
After watching exactly what it does and does not do, I can see that problem arrises with the section of code below it does everything up until; $line = GetLine()
$line = GetLine()
If IsArray($line) Then
Local $random2 = Random(200, 250, 1)
MouseMove($line[0], $line[1]+3*16-8, 5)
Sleep($random2-51)
MouseMove($line[0]+120, $line[1]+3*16-8, 5)
Sleep($random2+38)
MouseMove($line[0]+120, $line[1]+3*16-8+2*16, 5)
Sleep(500)
MouseMove($line[0]+200, $line[1]+3*16-8+2*16, 5)
Sleep($random2+161)
MouseMove($line[0]+200, $line[1]+3*16-8+2*16+44, 25)
Sleep($random2)
MouseClick("left")
EndIf
EndFunc
Any help would be appreciated. And although I am not familiar with code that much I do know how to use stack overflow well as my brother is a .net developer. I will mark the question that helps me and upvote and such.
Kind regards.
I know what your problem is.. I think. Try turning the output of PixelGetColor() into Hex.
Also, when it outputs, it doesnt include the "0x" at the beginning of the color tag.
So, you could say:
#Include <Misc.au3> ;for the _ispressed() function
Do
Until _IsPressed("01") ;wait for click
$mouse = MouseGetPos() ;Get cursor info
$color = Hex(PixelGetColor($mouse[0], $mouse[1]), 6) Get info on the pixel under the mouse.
;Lets just say the color is white
If $color == "FFFFFF" Then
MsgBox(0, "Success", "Colors match!")
EndIf
As for the ImageSearch not working, that could be a problem with AutoHotKey's compatability with Windows 8. Because of AutoIt not having a ImageSearch function, developers use AutoHotKey's ImageSearch function, and wrap it up in an AutoIt library. That may be where the problem is cominh

How do I recognize a drag-select with autoit

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