Leaderboard
Popular Content
Showing content with the highest reputation on 02/08/2021 in all areas
-
Getting started example step 4: Navigation eventsWebView2-2.au3: #AutoIt3Wrapper_Au3Check_Parameters=-d -w- 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #AutoIt3Wrapper_UseX64=y Opt( "MustDeclareVars", 1 ) #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <WinAPICom.au3> #include <WinAPI.au3> Global $hGui ; Project includes #include "..\Includes\WV2Interfaces.au3" WebView2() Func WebView2() ; Create WebView2 GUI $hGui = GUICreate( "WebView2 Sample", 1200, 900, -1, -1, $WS_OVERLAPPEDWINDOW ) ; Initialize COM _WinAPI_CoInitialize( $COINIT_APARTMENTTHREADED ) ; Create callback interface and functions CoreWebView2CreateCoreWebView2EnvironmentCompletedHandlerCreate( True ) ; Forces CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke() below to be executed ; Create callback interface and functions CoreWebView2CreateCoreWebView2ControllerCompletedHandlerCreate( True ) ; Create callback interface and functions CoreWebView2NavigationStartingEventHandlerCreate( True ) ; DllCall CreateCoreWebView2EnvironmentWithOptions Local $hWebView2Loader = DllOpen( @AutoItX64 ? "WebView2Loader-x64.dll" : "WebView2Loader-x86.dll" ) Local $aRet = DllCall( $hWebView2Loader, "long", "CreateCoreWebView2EnvironmentWithOptions", "wstr", "", "wstr", "", _ "ptr", NULL, "ptr", $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler ) If @error Or $aRet[0] Then Return ConsoleWrite( "CreateCoreWebView2EnvironmentWithOptions ERR" & @CRLF ) ConsoleWrite( "CreateCoreWebView2EnvironmentWithOptions OK" & @CRLF & @CRLF ) ; Show WebView2 GUI GUISetState( @SW_SHOW ) ; Loop While 1 Switch GUIGetMsg() Case $GUI_EVENT_MAXIMIZE, $GUI_EVENT_RESIZED, $GUI_EVENT_RESTORE Local $tRect = _WinAPI_GetClientRect( $hGui ) $oCoreWebView2Controller.put_Bounds( $tRect ) Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd ; Cleanup CoreWebView2CreateCoreWebView2ControllerCompletedHandlerDelete() CoreWebView2CreateCoreWebView2EnvironmentCompletedHandlerDelete() DllClose( $hWebView2Loader ) EndFunc ; Copied from WV2Interfaces.au3 ; Executed automatically when the callback interface is created Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke( $pSelf, $long, $ptr ) ; Ret: long Par: long;ptr* ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke" & @CRLF ) ; Create CoreWebView2Environment object $oCoreWebView2Environment = ObjCreateInterface( $ptr, $sIID_ICoreWebView2Environment, $dtag_ICoreWebView2Environment ) ConsoleWrite( "IsObj( $oCoreWebView2Environment ) = " & IsObj( $oCoreWebView2Environment ) & @CRLF & @CRLF ) ; Set $pCoreWebView2CreateCoreWebView2ControllerCompletedHandler callback pointer for the WebView2 GUI $oCoreWebView2Environment.CreateCoreWebView2Controller( $hGui, $pCoreWebView2CreateCoreWebView2ControllerCompletedHandler ) ; Forces CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Invoke() below to be executed Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $long EndFunc ; Copied from WV2Interfaces.au3 ; Executed as a consequence of $oCoreWebView2Environment.CreateCoreWebView2Controller() above Func CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Invoke( $pSelf, $long, $ptr ) ; Ret: long Par: long;ptr* ConsoleWrite( "CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Invoke" & @CRLF ) ; Create CoreWebView2Controller object $oCoreWebView2Controller = ObjCreateInterface( $ptr, $sIID_ICoreWebView2Controller, $dtag_ICoreWebView2Controller ) ConsoleWrite( "IsObj( $oCoreWebView2Controller ) = " & IsObj( $oCoreWebView2Controller ) & @CRLF ) $oCoreWebView2Controller.AddRef() ; Prevent the object from being deleted when the function ends ; Set bounds for the CoreWebView2 object Local $tRect = _WinAPI_GetClientRect( $hGui ) $oCoreWebView2Controller.put_Bounds( $tRect ) ; Create CoreWebView2 object $oCoreWebView2Controller.get_CoreWebView2( $pCoreWebView2 ) $oCoreWebView2 = ObjCreateInterface( $pCoreWebView2, $sIID_ICoreWebView2, $dtag_ICoreWebView2 ) ConsoleWrite( "IsObj( $oCoreWebView2 ) = " & IsObj( $oCoreWebView2 ) & @CRLF & @CRLF ) ; Add NavigationStarting event handler Local $tEventRegistrationToken = DllStructCreate( "uint64" ) $oCoreWebView2.add_NavigationStarting( $pCoreWebView2NavigationStartingEventHandler, $tEventRegistrationToken ) ConsoleWrite( "DllStructGetData( $tEventRegistrationToken, 1 ) = " & DllStructGetData( $tEventRegistrationToken, 1 ) & @CRLF & @CRLF ) ; Forces CoreWebView2NavigationStartingEventHandler_Invoke() below to be executed ; Navigate to web page $oCoreWebView2.Navigate( "https://www.bing.com/" ) Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $long EndFunc ; Copied from WV2Interfaces.au3 ; Executed as a consequence of $oCoreWebView2.add_NavigationStarting() above Func CoreWebView2NavigationStartingEventHandler_Invoke( $pSelf, $ptr1, $ptr2 ) ; Ret: long Par: ptr*;ptr* ConsoleWrite( "CoreWebView2NavigationStartingEventHandler_Invoke()" & @CRLF ) ; Create CoreWebView2NavigationStartingEventArgs object $oCoreWebView2NavigationStartingEventArgs = ObjCreateInterface( $ptr2, $sIID_ICoreWebView2NavigationStartingEventArgs, $dtag_ICoreWebView2NavigationStartingEventArgs ) ConsoleWrite( "IsObj( $oCoreWebView2NavigationStartingEventArgs ) = " & IsObj( $oCoreWebView2NavigationStartingEventArgs ) & @CRLF & @CRLF ) $oCoreWebView2NavigationStartingEventArgs.AddRef() ; Prevent the object from being deleted when the function ends ; Get navigation information Local $bIsUserInitiated, $bIsRedirected $oCoreWebView2NavigationStartingEventArgs.get_IsUserInitiated( $bIsUserInitiated ) $oCoreWebView2NavigationStartingEventArgs.get_IsRedirected( $bIsRedirected ) ; Confirm navigation If $bIsUserInitiated And Not $bIsRedirected Then Local $sUri $oCoreWebView2NavigationStartingEventArgs.get_Uri( $sUri ) If MsgBox( $MB_YESNO+$MB_ICONWARNING, "Navigation warning", "You are about to navigate to: " & $sUri & @CRLF & @CRLF & "Do you want to continue?" ) = $IDNO Then $oCoreWebView2NavigationStartingEventArgs.put_Cancel( True ) $oCoreWebView2.NavigateToString( "<h1>Navigation Canceled</h1><p>You chose to cancel navigation to the following URL: " & $sUri & "</p>" ) EndIf EndIf Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $ptr1, $ptr2 EndFunc The code is translated to AutoIt from the C++ code in the Getting started example step 4, from the C++ code in ICoreWebView2.add_NavigationStarting() and from the AutoHotkey code in WebView2.ahk. In case of a CreateCoreWebView2EnvironmentWithOptions ERR in the SciTE console then the cause of the problem and the solution is described by Chimp in this post above. WebView2.h, HelloWebView.cpp and the three dll-files contained in the 7z-file are copied from the NuGet package needed to compile the C++ Getting started example. Examples: WebView2-1.au3: Getting started example step 3: WebView window WebView2-2.au3: Getting started example step 4: Navigation events (this example) WebView2-3.au3: AutoIt implementation of the AutoHotkey example WebView2-4.au3: Scripting example based on code by Chimp WebView2-5.au3: Getting started example step 5: Scripting WebView2-6.au3: Getting started example step 6: Communication (doesn't work) WebView2.7z2 points
-
Majority of users of AutoIt language likes it because it's easy to learn and very powerful when it comes to automating some basically very complicated stuff on windows. AutoIt often does it in just one line of code while doing it in other languages would be writing a full book of code. How to use AutoIt with other languages? One way would be to use AutoItX. Dll version of AutoIt. In this case you can access it through COM or exported functions. Downside surely is limited number of available functions and user rights for COM option. Other way is... no wait, there is no other way. But, what If I add some magic salt to the soup? Let's say I use some of the code from (thanks Manadar) and, yes you guessed AutoItObject, and make a simple (the most basic) COM server that exports almost the whole AutoIt functionality to anyone wanting to use it. AutoItObject 1.2.8.0 makes objects published to ROT (running object table) more accessible than ever. Accessing the object is as easy as GetObject(...) in any scripting language and CoGetObject() through Windows API. An example of VBS would be: Javascript could be: C# PowerShell (based on ptrex's example) Python (AdmiralAlkex) ...and so on. Server script is really minimalistic: All packed in ZIP: AccessAutoIt.zip What you'll find there is folder named AccessAutoIt. Unzip it somewhere and inside there will be five files: AutoItObject.au3 (1.2.8.0), AutoItServer.au3, Csharp.cs, JS.js and VBS.vbs. Run AutoItServer.au3 and then either vbs or js script or compile Csharp.cs and run resulting executable. I have chosen AutoIt.Application object moniker for no particular reason. Can be anything. Latest AutoItObject, if you want the whole thing, is here. AutoIt on your palm. edit: Added c# example. Don't mind about my usage of other languages. I'm not quite familiar with them.1 point
-
@Chantaro welcome to the forum, the problem is that you used the same variable to identify the input and to read its content, use another name to get the link. #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $ytdl_path = (@ScriptDir & "\youtube-dl.exe") Global $argsmp3 = (' --extract-audio --format=bestaudio --audio-format mp3 --audio-quality=320k --output "%(title)s.%(ext)s" --cookies .\cookies.txt') Global $argsmp4 = (' --format=bestaudio --output "%(title)s.%(ext)s" --cookies .\cookies.txt') Global $link = "https://youtu.be/HQnC1UHBvWA" #region GUI YoutubeDL() Func YoutubeDL() Local $empty = "" ; Create a GUI with various controls. Local $hGUI = GUICreate("YouTube Downloader", 400, 200, 1000, 500) Local $Label1 = GUICtrlCreateLabel("Insert Youtube link here", 10, 45, 461, 24) GUICtrlSetFont(-1, 10, 200, 0, "Arial") Local $Pic1 = GUICtrlCreatePic(@ScriptDir & "\eXLs5Hw.jpg", 10, 10, 120, 30) Local $video_url = GUICtrlCreateInput($link, 10, 70, 370, 20) Local $idConvertMP3 = GUICtrlCreateButton("Convert to MP3", 10, 100, 85, 25) ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) ; Loop until the user exits. While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $idConvertMP3 $link = GUICtrlRead($video_url) If $link = $empty Then MsgBox(0, "Error", "Please insert a Link") Else ConvertMP3() EndIf EndSwitch WEnd ; Delete the previous GUI and all controls. GUIDelete($hGUI) EndFunc ;==>YoutubeDL #endregion GUI ;Run Conversion Func ConvertMP3() Run($ytdl_path & " " & $link & $argsmp3) EndFunc ;==>ConvertMP31 point
-
Mouse Position
FrancescoDiMuro reacted to Jos for a topic
@YuChan, You have quite some nerves to open a new thread while I asked you for an explanation in your previous thread: https://www.autoitscript.com/forum/topic/205094-one-gui-who-follow-mouse/?do=findComment&comment=1474619 Let it be clear there are some common rules one stick to, so this topic is locked and you are now on mod preview until you have made ultimately clear what you are doing with all these PixelSearch BS. Jos1 point -
Added the /DR option -- thanks! The usage has changed slightly. You must specify at least one path on the command line. ListZero with no arg shows help.1 point
-
One gui who follow mouse
Somerset reacted to JockoDundee for a topic
Ok, three gui’s walk in to a menu bar...1 point -
"One gui to rule all these pixels, one gui to find them, one gui to bring them all and in an array bind them"1 point
-
Start with this thread from @LarsJ as I feel your server looks logically similar to whats done with iuiautomation events. Clients in python seem to exist so no reason to believe it cannot be done with Autoit https://github.com/brotchie/pyrtd/blob/master/rtd/client.py https://www.cin.ufpe.br/~cfms/graduacao/2007-2/Projeto_Desenvolvimento/Software-PC/python/Lib/site-packages/win32com/demos/excelRTDServer.py I think there are only a dozen of people max in the forum that can help in detail. My advice make a c# server with visual studio that works with excel. Share that so we have a reproducer for working with an rtd server. From there we could look to make an RTD client similar as excel would do. Probably easier is just to use a different api to the server thats less complicated.1 point
-
Its a little fuzzy but I remember having to go through hoops to make a callback function that was compatible with autoit and my COM object I still think you should try setting the interval and try calling the update function directly to see if it works Butttttttttttttt as referenced here: https://weblogs.asp.net/kennykerr/Rtd8 so it might be that you have to jump through hoops like creating a shared piece of memory in the excel process and then monkey patch in some asm to act as an intermediary maybe I'm just making it complicated..1 point
-
AutoIT vs Python question
junkew reacted to JockoDundee for a topic
Disagree. You’re right to point out that python has a mutex restricting the interpreter to service just a single thread at a time. This is a weak threading model for sure. But it is still superior to AutoIt model. Why? Because it allows you to write multiple, lightweight threads each with their own Instruction pointer. So you can create a thread just to wait for some output or condition, and still have access to the memory space. Unless you are creating threads that are purely crunching numbers or otherwise running at a high CPU%, you’re unlikely to know the difference. But for me, and IMHO, threading is usually about being in two places at the same time, and less about doing two things at the same time. Edit: oh damn - I replied to a reply of a zombie thread...👎0 points