Jump to content

fraizor

Active Members
  • Posts

    50
  • Joined

  • Last visited

Reputation Activity

  1. Like
    fraizor reacted to MrCreatoR in ControlSend faster alternative?   
    Using clipboard (the smart/safe way ):


    _ControlSendEx("Title", "", "Edit1", "New Data") Func _ControlSendEx($hWnd, $sText, $iCtrlID, $sString) ControlFocus($hWnd, $sText, $iCtrlID) Local $sOldClip = ClipGet() ClipPut($sString) Send("+{Insert}") ClipPut($sOldClip) EndFunc
    Or you can use ControlSetText(), or if you need to append the text, then use ControlCommand() with EditPaste:


    ControlCommand("Title", "", "Edit1", "EditPaste", "New Data")
  2. Like
    fraizor reacted to JohnOne in Info tool and Firefox control   
    Indeed it does work.

    The thing is, I cannot get information about the controls of the window, Specifically the WebBrowser control.
    The following msgbox from the given code says 27. It would normally say 1400, the width of the browser control (if it were available to me to pass in as a parameter)


    $hwnd = WinActivate("[CLASS:MozillaWindowClass; TITLE:Google - Mozilla Firefox]") If Not IsHWnd($hwnd) Then MsgBox(16, "Error", "$hwnd is not a handle", 3) Exit EndIf Sleep(1000) WinSetState($hwnd, "", @SW_MINIMIZE) Sleep(1000) $c = ControlGetPos($hwnd, "", "") If @error Then MsgBox(0, "ControlGetPos", @error) Else MsgBox(0, 0, $c[3]) EndIf WinSetState($hwnd, "", @SW_MAXIMIZE) Its looking more and more like I will just have to drop firefox for the time being, in favour of IE or Chrome. I dont dislike those browsers, I'm just more comfortable with FF.

    Anyway Thanks for your attention PsaltyDS.
  3. Like
    fraizor reacted to ioa747 in array sort issue --- "natural sort"   
    just in case
    #include <Array.au3> Local $aArray[101] $aArray[0] = 100 For $i = 1 To $aArray[0] $aArray[$i] = "InventorySave_" & $i & ".lvs" Next ;~ _ArrayShuffle($aArray, 1) _ArraySort($aArray, 0, 1, 0, 1) _ArrayDisplay($aArray, "BEFORE") _SortInventoryArray($aArray) _ArrayDisplay($aArray, "AFTER") Func _SortInventoryArray(ByRef $Array) _ArrayColInsert($Array, 1) ; Now a 2D array For $i = 1 To $Array[0][0] $Array[$i][1] = StringFormat("%010s", StringTrimLeft($Array[$i][0], 14)) Next _ArraySort($Array, 0, 1, 0, 1) ;~ _ArrayDisplay($Array, "2D array") _ArrayColDelete($Array, 1) EndFunc ;==>_SortInventoryArray more: forum/topic/209849
  4. Like
    fraizor reacted to water in Rename Excel sheet 1   
    $oWorkbook.Sheets(1).Name = "xyz"
  5. Like
    fraizor reacted to jugador in Is there a way to send copy , no matter what language I have active?   
    Send(Chr(094) & "{"& Chr(097) &"}") ;~ send: ctrl + a (select all) Send(Chr(094) & "{"& Chr(099) &"}") ;~ send: ctrl + c (copy) ConsoleWrite(ClipGet() & @CRLF)  
  6. Like
    fraizor reacted to bogQ in How to check if string is also number?   
    StringIsDigit
    for stringregexp i dono
  7. Like
    fraizor reacted to Ward in A Non-Strict JSON UDF (JSMN)   
    Introduction
    JSON (Javascript Object Notation) is a popular data-interchange format and supported by a lot of script languages. On AutoIt, there is already a >JSON UDF written by Gabriel Boehme. It is good but too slow, and not supports unicode and control characters very well. So I write a new one (and of course, fast one as usual).

    I use a machine code version of JSON parser called "jsmn". jsmn not only supports standard JSON, but also accepts some non-strict JSON string. See below for example.
     
    Important Update!!
    I rename the library from jsmn.au3 to json.au3. All function names are changed, too.
     
    Decoding Function
    Json_Decode($Json) $Json can be a standard or non-standard JSON string. For example, it accepts:
    { server: example.com port: 80 message: "this looks like a config file" } The most JSON data type will be decoded into corresponding AutoIt variable, including 1D array, string, number, true, false, and null. JSON object will be decoded into "Windows Scripting Dictionary Object" retuned from ObjCreate("Scripting.Dictionary"). AutoIt build-in functions like IsArray, IsBool, etc. can be used to check the returned data type. But for Object and Null, Json_IsObject() and Json_IsNull() should be used.

    If the input JSON string is invalid, @Error will be set to $JSMN_ERROR_INVAL. And if the input JSON string is not finish (maybe read from stream?), @Error will be set to $JSMN_ERROR_PART.

    Encoding Function
    Json_Encode($Data, $Option = 0, $Indent = "\t", $ArraySep = ",\r\n", $ObjectSep = ",\r\n", $ColonSep = ": ") $Data can be a string, number, bool, keyword(default or null), 1D arrry, or "Scripting.Dictionary" COM object. Ptr will be converted to number, Binary will be converted to string in UTF8 encoding. Other unsupported types like 2D array, dllstruct or object will be encoded into null.

    $Option is bitmask consisting following constant:
    $JSON_UNESCAPED_ASCII ; Don't escape ascii charcters between chr(1) ~ chr(0x1f) $JSON_UNESCAPED_UNICODE ; Encode multibyte Unicode characters literally $JSON_UNESCAPED_SLASHES ; Don't escape / $JSON_HEX_TAG ; All < and > are converted to \u003C and \u003E $JSON_HEX_AMP ; All &amp;amp;amp;amp;s are converted to \u0026 $JSON_HEX_APOS ; All ' are converted to \u0027 $JSON_HEX_QUOT ; All " are converted to \u0022 $JSON_PRETTY_PRINT ; Use whitespace in returned data to format it $JSON_STRICT_PRINT ; Make sure returned JSON string is RFC4627 compliant $JSON_UNQUOTED_STRING ; Output unquoted string if possible (conflicting with $JSMN_STRICT_PRINT) Most encoding option have the same means like PHP's json_enocde() function. When $JSON_PRETTY_PRINT is set, output format can be change by other 4 parameters ($Indent, $ArraySep, $ObjectSep, and $ColonSep). Because these 4 output format parameters will be checked inside Jsmn_Encode() function, returned string will be always accepted by Jsmn_Decode(). $JSON_UNQUOTED_STRING can be used to output unquoted string that also accetped by Jsmn_Decode().

    $JSON_STRICT_PRINT is used to check output format setting and avoid non-standard JSON output. So this option is conflicting with $JSON_UNQUOTED_STRING.

    Get and Put Functions
    Json_Put(ByRef $Var, $Notation, $Data, $CheckExists = False) Json_Get(ByRef $Var, $Notation) These functions helps user to access object or array more easily. Both dot notation and square bracket notation can be supported. Json_Put() by default will create non-exists objects and arrays. For example:
    Local $Obj Json_Put($Obj, ".foo", "foo") Json_Put($Obj, ".bar[0]", "bar") Json_Put($Obj, ".test[1].foo.bar[2].foo.bar", "Test") Local $Test = Json_Get($Obj, '["test"][1]["foo"]["bar"][2]["foo"]["bar"]') ; "Test" Object Help Functions
    Json_ObjCreate() Json_ObjPut(ByRef $Object, $Key, $Value) Json_ObjGet(ByRef $Object, $Key) Json_ObjDelete(ByRef $Object, $Key) Json_ObjExists(ByRef $Object, $Key) Json_ObjGetCount(ByRef $Object) Json_ObjGetKeys(ByRef $Object) Json_ObjClear(ByRef $Object) These functions are just warps of "Scripting.Dictionary" COM object. You can use these functions if you are not already familiar with it.
     
    == Update 2013/05/19 ==
     
    * Add Jsmn_Encode() option "$JSMN_UNESCAPED_ASCII". Now the default output of Json_Encode() is exactly the same as PHP's json_encode() function (for example, chr(1) will be encoded into u0001).
    $JSON_UNESCAPED_ASCII ; Don't escape ascii charcters between chr(1) ~ chr(0x1f)  
    == Update 2015/01/08 ==
    * Rename the library from jsmn.au3 to json.au3. All function names are changed, too.
    * Add Json_Put() and Json_Get()
    * Add Null support
    * Using BinaryCall.au3 to loading the machine code.
     
    == Update 2018/01/13==   (Jos)
    * Add JsonDump() to list all Json Keys and their values to easily figure out what they are.
    == Update 2018/10/01==  (Jos)
    * Fixed JsonDump() some fields and values were not showing as discussed here  - tnx @TheXman .
    == Update 2018/10/01b==   (Jos)
    * Added Json_ObjGetItems, Tidied source and fixed au3check warnings - tnx @TheXman .
    == Update 2018/10/28==   (Jos)
    * Added declaration for $value to avoid au3check warning - tnx @DerPensionist
    == Update 2018/12/16==   (Jos)
    * Added another declaration for $value to avoid au3check warning  and updated the version at the top - tnx @maniootek
    == Update 2018/12/29==   (Jos)
    * Changed Json_ObjGet() and Json_ObjExists() to allow for multilevel object in string.
    == Update 2019/01/17==   (Jos)
    * Added support for DOT notation in JSON functions.
    == Update 2019/07/15==   (Jos)
    *  Added support for reading keys with a dot inside when using a dot as separator (updated)
    == Update 2021/11/18==   (TheXman)
    * Update details in below post:  
    == Update 2021/11/20==   (TheXman)
    * Minor RegEx update, no change to the functionality or result._Json(2021.11.20).zip
     
  8. Like
    fraizor reacted to SOLVE-SMART in AutoFox Control Firefox without dependencies [Noob friendly] !   
    Thanks for your use case example. I understand and would agree in case I would not know about WebDriver 😅 - but yes, fair enough.
    Not really, no. Sorry. Neither I would have the time nor I am interested in. Anyways best of luck @fraizor 🤝 .
    Best regards
    Sven
  9. Like
    fraizor got a reaction from SOLVE-SMART in AutoFox Control Firefox without dependencies [Noob friendly] !   
    Thank you for your review dear  SOLVE-SMART
    1- Sure will take a look at the recommended UDF methods later , thanks 
    2- Yes it is not very suitable for complex browser automation, I would say the best use case for the UDF is doing simple tasks, like filling/submitting forms and doing bulk changes for a group of pages ...
    in fact i had multiple annoying tasks before that i need to do a simple checkbox click on a page then save the page (i had 100 pages) the task was stuck in the middle as it was not worth the trouble to install and learn about wedrivers and yet i cannot do them manually ... 
    3- Yes i agree that ControlSend is not the most reliable function, i believe that ControlSetText  will be faster and more efficient , however i was not able to find the developer tool input box ControlID can you help me with that ? 
     
  10. Like
    fraizor reacted to SOLVE-SMART in AutoFox Control Firefox without dependencies [Noob friendly] !   
    Hi @fraizor 👋 ,
    first of all, thanks for sharing your approach. Second of all, there is a recommended way to write UDFs (see here) - maybe you could improve your UDF to be more standardized.
    In aspects of what your _AF* UDF can do and how it handles possible requirements for the browser (firefox) I have to say it's not very promising, sorry. I mean the approach use ControlSend which can not as much as it should do. Also the user have to understand javascript in depth in case of more complex tasks which he probably wants to achieve. Frameworks like Selenium, WebdriverIO or the AutoIt variant "au3WebDriver" communicate with the " JSON Wire Protocol" and use several abstractions to avoid deep intervention for the browser communication.
    So please let us know which use cases you think of would be the best for your UDF.
    But: Please don't be sad about this sober assessment. Every beginning is difficult and it's good that you found a way and took it 👌 .
    Best regards
    Sven
  11. Like
    fraizor reacted to JohnOne in Info tool and Firefox control   
    The whole browser is a control, and could be used for instance with controlsend or controlclick.

    With IE a non active window


    $hwnd = WinActivate("Google - Windows Internet Explorer") If Not IsHWnd($hwnd) Then MsgBox(0,0,"Fail") Exit EndIf Sleep(1000) WinSetState($hwnd,"",@SW_MINIMIZE) Sleep(1000) ControlSend($hwnd,"","[CLASS:Internet Explorer_Server; INSTANCE:1]","Search String") Sleep(1000) WinSetState($hwnd,"",@SW_MAXIMIZE) Will minimize it, send string, maximize.

    If the title was Mozilla Firefox and control ID were changed to "[CLASS:MozillaWindowClass; INSTANCE:2]" the same would occur.

    But just not any more, with this new gecko control and its broken a fair few of my scripts
  12. Like
    fraizor reacted to borup in How to add text to image   
    Finally.... he he.

    But how do i center the text???
    The $sString will be replaced with a automatic pull from the system...





    #include <GDIPlus.au3> Global $hBitmap, $hImage, $hGraphic, $hFamily, $hFont, $tLayout, $hFormat, $aInfo, $hBrush1, $hBrush2, $iWidth, $iHeight, $hPen Global $sString="SERVERNAME" ; Initialize GDI+ library _GDIPlus_StartUp() ; Load image and emboss text $hImage = _GDIPlus_ImageLoadFromFile('C:\Temp\1.jpg') $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage) $hFamily = _GDIPlus_FontFamilyCreate("Arial") $hFont = _GDIPlus_FontCreate($hFamily, 38, 1) $hFormat = _GDIPlus_StringFormatCreate(0x4000) $hBrush2 = _GDIPlus_BrushCreateSolid(0xff000000) $hPen = _GDIPlus_PenCreate(0xC4000000, 1) $tLayout = _GDIPlus_RectFCreate (150, 250 ) $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $sString, $hFont, $tLayout, $hFormat) _GDIPlus_GraphicsDrawStringEx($hGraphic, $sString, $hFont, $aInfo[0], $hFormat, $hBrush2) ; Save image _GDIPlus_ImageSaveToFile($hImage, @MyDocumentsDir & '\AutoItImage2.bmp') ; Free resources _GDIPlus_PenDispose ($hPen ) _GDIPlus_BrushDispose ($hBrush1 ) _GDIPlus_BrushDispose ($hBrush2 ) _GDIPlus_StringFormatDispose($hFormat ) _GDIPlus_FontDispose ($hFont ) _GDIPlus_FontFamilyDispose ($hFamily ) _GDIPlus_GraphicsDispose ($hGraphic) _GDIPlus_ImageDispose ($hImage ) _GDIPlus_ShutDown() ; Show image Run("MSPaint.exe " & '"' & @MyDocumentsDir & '\AutoItImage2.bmp"')
  13. Like
    fraizor reacted to Subz in Pass a variable to another script   
    Just use $CmdLineRaw or $CmdLine[1] in your second script, so for example:
    Script 1
    While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btnYes Global $Reboot = 1 Run(@ScriptDir & "\PatchDelayRed.exe True") Exit Case $btnNo GUISetState(@SW_HIDE) msg3() Exit EndSwitch WEnd Script 2
    AutoItSetOption("TrayIconHide", 1) Global $Reboot = False If $CmdLine[0] >= 1 Then $Reboot = $CmdLine[1] If $Reboot = False Then Do Sleep(5000) ;Sleep for two hours Run(@ScriptDir & "\PatchRebootRed_Eng.exe") Exit Until $Reboot = True ElseIf $Reboot = True Then MsgBox(0, "", "Rebooting Now") Exit EndIf  
  14. Thanks
    fraizor reacted to OverloadUT in HTTP UDF's   
    I am working on a fairly large project and a big part of it is an AutoIt application that uploads a lot of data to a PHP script.

    For a while I was using INetGet and submitting all my data as GET variables in the URL. However, the amount of data to upload got too big (over 1000 characters) and the INetGet function started to fail.

    I also hated that INetGet ONLY works if the webserver responds with "200 OK" - There is no way to tell the difference between a 404 error and simply not being able to connect to the server in the first place.

    So I write this library of UDF's. Basically, it's a fully compliant HTTP/1.1 client. It uses only the TCP functions; no DllCall needed here! I had a blast learning all about the HTTP protocol and how to use it.

    Advantages over INetGet:
    The data is downloaded right in to variables instead of to files. You can of course then write this data to a file if you wish.
    You can read all of the headers supplied by the webserver.
    You can get the HTTP Response Code from the webserver.
    When it failes, you know exactly what failed instead of having to guess.


    ; =================================================================== ; HTTP UDF's ; v0.5 ; ; By: Greg "Overload" Laabs ; Last Updated: 07-22-06 ; Tested with AutoIt Version 3.1.1.131 ; Extra requirements: Nothing! ; ; A set of functions that allow you to download webpages and submit ; POST requests. ; ; Main functions: ; _HTTPConnect - Connects to a webserver ; _HTTPGet - Submits a GET request to a webserver ; _HTTPPost - Submits a POST request to a webserver ; _HTTPRead - Reads the response from a webserver ; ===================================================================
    I consider this UDF package to be a "beta" and that's why I call it version 0.5. However, I would love people to give it a try and tell me how it works for them. I have done extensive testing and I think I have the parser working perfectly.

    I plan on improving this library. It's possible that I might change the way the functions work (I don't think the _HTTPConnect function is necessary; I could move that functionality right in to the Get or Post functions.)

    To Do:
    Add a function that downloads the data right to a file. You might not want to download a 10 meg file in to memory before saving it to a file. Add a method to get the progress of the download. This will probably be in the form of a callback function, if that's possible in AutoIt. Add the ability to automatically follow "Location:" headers. Currently you'd have to do it manually. Other things I can't think of! Post #25 For Updated functions to work with current AutoIt versions.
  15. Like
    fraizor reacted to andybiochem in Binance API UDF   
    Hi All,
    Firstly, I accept no responsibility for how you use the following UDF, use at your own risk!
     
    Below is a very basic UDF that will allow communication with Binance's API (binance.com, not the US version).
    There is no error handling - add this yourself if you are concerned. If you are going to use this UDF in any meaningful way, carefully check the return of every single call, to make sure there is no error in the data you are receiving back from Binance. e.g. if you are pulling ticker prices, and suddenly you get $NULL returned, this could affect how you go on to place orders etc.
     
    I have very intentionally not provided an example of how to place orders using the UDF. If you are technically minded enough to use the UDF and understand how to construct the POST data, this should not be an issue. If you are struggling to work out how to place orders with this, please stop - no good can come from not fully understanding  Binance's API and trying to automate it. In any event, please start with POSTing to "/api/v3/order/test" before commiting to your live account!
     
    The whole UDF calls directly on winhttp.dll, this was the only method I could find that gave a decent reliability, TCP / INET functions I found quite unreliable.
     
    Every UDF return gives you the HTTP Code and API Weight pulled out of the http header. Monitor these carefully if you're making heavy/lots of calls to the API; it's very easy to make a mistake and spam Binance's server, which will lead in a ban.
     
    Lastly, if you get "Timestamp for this request is outside of the recvwindow" errors back from Binance, it is because your computer clock is not synced with an NTP properly. Sync your clock, and the error should go away, try rebooting too - BUT, the error will probably return after a few days/weeks as the sync drops. Monitor for this error, and keep on top of it if you can!
     
    ;----- API Keys ----- Global $sAPI_Key_Access = "enter your access key" Global $sAPI_Key_Secret = "enter your secret key" ;----- Prepare DLL ----- Global $hDll_WinHTTP = DllOpen("winhttp.dll") ;########## EXAMPLE API CALLS ########## ;----- Ping Binance ----- Global $sRet = _BINANCE_API_Call("api/v3/ping") ConsoleWrite($sRet & @CRLF & @CRLF) ;----- Get Binance's Server Time ----- $sRet = _BINANCE_API_Call("api/v3/time") ConsoleWrite($sRet & @CRLF & @CRLF) ;----- Get BTC/USDT Average Price ----- $sRet = _BINANCE_API_Call("api/v3/avgPrice","symbol=BTCUSDT") ConsoleWrite($sRet & @CRLF & @CRLF) ;----- Get ETH/BTC Live Ticker Price ----- For $i = 1 To 5 Sleep(100) $sRet = _BINANCE_API_Call("api/v3/ticker/price", "symbol=ETHBTC") ConsoleWrite($sRet & @CRLF) Next ConsoleWrite(@CRLF) ;----- Get Last 10 ETH/BTC Trades ----- $sRet = _BINANCE_API_Call("api/v3/trades", "symbol=ETHBTC&limit=10") ConsoleWrite($sRet & @CRLF & @CRLF) ;----- Get Your Account Data ----- $sRet = _BINANCE_API_Call("api/v3/account") ConsoleWrite($sRet & @CRLF & @CRLF) Func _BINANCE_API_Call($sEndPoint, $sParameters = "") ;************************************************** ; Performs Binance API Call Via Native WinHTTP dll ;************************************************** ;----- Vars ----- ; Presume GET, assign POST if needed in switch Local $sGETorPOST = "GET" ;----- Check Endpoint Required ----- ; Some endpoints require signing, other endpoints can be ; added as new cases. Switch $sEndPoint Case "api/v3/account" $sParameters &= "&timestamp=" & _TimeStamp() $sParameters &= "&signature=" & _HMAC($sParameters, $sAPI_Key_Secret) Case "api/v3/order" $sGETorPOST = "POST" $sParameters &= "&timestamp=" & _TimeStamp() $sParameters &= "&signature=" & _HMAC($sParameters, $sAPI_Key_Secret) Case "api/v3/myTrades" $sParameters &= "&timestamp=" & _TimeStamp() $sParameters &= "&signature=" & _HMAC($sParameters, $sAPI_Key_Secret) EndSwitch ;----- Start Session ----- Local $hHTTP_Session = DllCall($hDll_WinHTTP, "handle", "WinHttpOpen", "wstr", "Mozilla/4.0", "dword", 0, "wstr", "", "wstr", "", "dword", 0)[0] ;----- Connect To Binance Server ----- Local $hHTTP_Connection = DllCall($hDll_WinHTTP, "handle", "WinHttpConnect", "handle", $hHTTP_Session, "wstr", "api.binance.com", "dword", 443, "dword", 0)[0] ;----- Prepare Request Data ----- If $sParameters <> "" Then $sParameters = "?" & $sParameters Local $hHTTP_Request = DllCall($hDll_WinHTTP, "handle", "WinHttpOpenRequest", "handle", $hHTTP_Connection, "wstr", $sGETorPOST, "wstr", $sEndPoint & $sParameters, "wstr", "HTTP/1.1", "wstr", "", "ptr", 0, "dword", 0x00800000)[0] ;----- Add Request Header ----- ; Adds API key to header even if not specifically needed, inconsequential DllCall($hDll_WinHTTP, "bool", "WinHttpAddRequestHeaders", "handle", $hHTTP_Request, "wstr", "X-MBX-APIKEY: " & $sAPI_Key_Access, "dword", -1, "dword", 0x10000000) ;----- Send Request To Server ----- DllCall($hDll_WinHTTP, "bool", "WinHttpSendRequest", "handle", $hHTTP_Request, "wstr", "", "dword", 0, "ptr", 0, "dword", 0, "dword", 0, "dword_ptr", 0) ;----- Recieve Response ----- DllCall($hDll_WinHTTP, "bool", "WinHttpReceiveResponse", "handle", $hHTTP_Request, "ptr", 0) ;----- Recieve Headers ----- ; Extract HTTP return code and API weight Local $sHeaders = DllCall($hDll_WinHTTP, "bool", "WinHttpQueryHeaders", "handle", $hHTTP_Request, "dword", 22, "wstr", "", "wstr", "", "dword*", 65536, "dword*", 0)[4] Local $sHTTP_ReturnCode = StringMid($sHeaders, StringInStr($sHeaders, "HTTP/1.1 ") + 9, StringInStr($sHeaders, @CR, 0, 1, StringInStr($sHeaders, "HTTP/1.1 ") + 9) - (StringInStr($sHeaders, "HTTP/1.1 ") + 9)) Local $sAPI_Weight = StringMid($sHeaders, StringInStr($sHeaders, "x-mbx-used-weight: ") + 19, StringInStr($sHeaders, @CR, 0, 1, StringInStr($sHeaders, "x-mbx-used-weight: ") + 19) - (StringInStr($sHeaders, "x-mbx-used-weight: ") + 19)) Local $sAPI_IPBan_RetryAfter_Sec = StringInStr($sHeaders, "Retry-After: ") = 0 ? "" : StringMid($sHeaders, StringInStr($sHeaders, "Retry-After: ") + 13, StringInStr($sHeaders, @CR, 0, 1, StringInStr($sHeaders, "Retry-After: ") + 13) - (StringInStr($sHeaders, "Retry-After: ") + 13)) ;----- Get Data ----- Local $sData = "" Local $iBytesToRead, $hBuffer_Data While 1 ;- Get Bytes To Read In This Loop - $iBytesToRead = DllCall($hDll_WinHTTP, "bool", "WinHttpQueryDataAvailable", "handle", $hHTTP_Request, "dword*", 0)[2] ;- Check If No More Data To Read - If $iBytesToRead <= 0 Then ExitLoop ;- Prep Data Buffer - $hBuffer_Data = DllStructCreate("char[" & $iBytesToRead & "]") ;- Read Data To Buffer - DllCall($hDll_WinHTTP, "bool", "WinHttpReadData", "handle", $hHTTP_Request, "struct*", $hBuffer_Data, "dword", $iBytesToRead, "dword*", 0) ;- Get Data From Buffer - $sData &= DllStructGetData($hBuffer_Data, 1) ;- Release - $hBuffer_Data = "" WEnd ;----- Close Handles ----- DllCall($hDll_WinHTTP, "bool", "WinHttpCloseHandle", "handle", $hHTTP_Request) DllCall($hDll_WinHTTP, "bool", "WinHttpCloseHandle", "handle", $hHTTP_Connection) DllCall($hDll_WinHTTP, "bool", "WinHttpCloseHandle", "handle", $hHTTP_Session) ;----- Return Data ----- ; Include HTTP Code and API Weight to check for overuse, and retry period if banned ; HTTP CODES : 429=over request limit, 418=IP banned due to overuse ; API WEIGHT : over 1200 will lead to ban Return '{"HTTPCode":"' & $sHTTP_ReturnCode & '","APIWeight":"' & $sAPI_Weight & ($sAPI_IPBan_RetryAfter_Sec = "" ? "" : '","Retry-After":"' & $sAPI_IPBan_RetryAfter_Sec) & '"}' & $sData EndFunc ;==>_BINANCE_API_Call Func _HMAC($bData, $bKey) ;************************************************** ; Create HMAC SHA256 Signature ;************************************************** Local $oHMAC = ObjCreate("System.Security.Cryptography.HMAC" & "SHA256") $oHMAC.key = Binary($bKey) Local $bHash = $oHMAC.ComputeHash_2(Binary($bData)) Return StringLower(StringMid($bHash, 3)) EndFunc ;==>_HMAC Func _TimeStamp() ;************************************************** ; Create UNIX-style TimeStamp ;************************************************** ; This is 'unix time', aka UTC time in milliseconds Local $aTimeStamp = DllCall("msvcrt.dll", "int:cdecl", "time", "int", 0) Return ($aTimeStamp[0] * 1000) + @MSEC ;convert to miliseconds EndFunc ;==>_TimeStamp  
    An example return would be:
    {"HTTPCode":"200 OK","APIWeight":"4"}{"symbol":"ETHBTC","price":"0.07152900"}  
    The first {} block is the HTTP code and API weight, the second {} block is the full Binance JSON reply.
    The JSON can be queried with a JSON UDF (do a search on the forum), or can be split with regexp.
     
     
    Again, please use with caution!
     
    Feel free to donate if you find this useful!:
    NANO
    nano_1161rm7egfzwgbtckwe8aoicee55897bbgc8apzrp1s3fzyyn7zqobbtkmfh
     
     
  16. Like
    fraizor reacted to Nine in _ArraySort is Not working correctly ?   
    Streamlined :
    #include "C:\Apps\AutoIt\JSON\json.au3" #include <Array.au3> $object = json_decode(FileRead("Test.json")) ;for local testing $Coins = json_get($object, '.data') Local $Chart[UBound($Coins)][2] for $i = 0 to UBound($Coins) -1 $Chart[$i][0] = json_get($object, '.data[' & $i & '].name' ) $Chart[$i][1] = Number(json_get($object, '.data[' & $i & '].quote.USD.percent_change_1h'), 3) Next _ArraySort($Chart, 3, Default, Default, 1) _ArrayDisplay($Chart)  
  17. Like
    fraizor reacted to water in _ArraySort is Not working correctly ?   
    I see. Then I suggest:
    Global $iRow ; Loop starts here $iRow = _ArrayAdd($Chart,$name) $Chart[$iRow][1] = number($change_1h,3)  
  18. Like
    fraizor reacted to ioa747 in _ArraySort is Not working correctly ?   
    #include "json.au3" #include <Array.au3> Dim $Chart[0][5] ; Array size of 2 columns $object = json_decode(FileRead("Test.json")) ;for local testing $Coins = json_get($object, '.data') for $i = 0 to UBound($Coins) -1 $name = json_get($object, '.data[' & $i & '].name' ) $change_1h = json_get($object, '.data[' & $i & '].quote.USD.percent_change_1h') _ArrayAdd($Chart,$name & "|" & number($change_1h,3) ) $Chart[$i][2] = VarGetType ( $Chart[$i][1] ) $Chart[$i][3] = number($change_1h,3) $Chart[$i][4] = VarGetType ( $Chart[$i][3] ) Next _ArraySort($Chart, 1, Default, Default, 3) _ArrayDisplay($Chart)  
  19. Like
    fraizor reacted to water in _ArraySort is Not working correctly ?   
    This code returns a String as AutoIt internally converts your number to a String again to be able to concatenate them.
    $name & "|" & number($change_1h,3) Call _ArrayAdd twice to fill the two columns.
    See the help file for details: "String datatype elements are sorted alphabetically and number datatype elements are sorted numerically - it is important to ensure that elements are of the correct datatype before sorting."
  20. Like
    fraizor reacted to maniootek in Command typed in cmd.exe does not bring same result as Run() in AutoIt   
    Of course!
    #AutoIt3Wrapper_UseX64=Y fixed the problem
  21. Thanks
    fraizor reacted to Yashied in Restart UDF   
    LAST VERSION - 1.0
    07-Mar-10

    This is my very simple and small UDF. Allows you to restart the script from any location with full restoration of the original command line parameters. I use this library in several of my programs, and I was not disappointed. I hope this UDF will be useful for many as for me. I will be glad to any feedback and suggestions.


    Restart UDF Library v1.0
    Previous downloads: 943

    Restart.au3


    Example


    #NoTrayIcon #Include <Misc.au3> #Include <Restart.au3> _Singleton('MyProgram') If MsgBox(36, 'Restarting...', 'Press OK to restart this script.') = 6 Then _ScriptRestart() EndIf
  22. Like
    fraizor reacted to fmendi in Easiest Solution to Browser Automation   
    For those of us on the forum that simply don't have the ability or the time to thoroughly learn programming processes required to implement the current solutions such as selenium, webdriver or the old chrome.au3 (no longer functional), I invite you to try the Automa Extension.  It is a free and open-source project on GitHub.
    https://github.com/AutomaApp/automa With the use of this extension and Autoit, I've managed to do things I could only imagine of doing in the past. I wanted to share this incredible find with the Autoit community especially those who have been frustrated and have failed in their attempts  to automate their browser activities.
  23. Like
    fraizor reacted to JLogan3o13 in Send {Ctrl} key when keyboard layout is not English   
    _WINAPI_SetKeyboardLayout - the help file is your friend.
  24. Thanks
    fraizor reacted to NassauSky in UI Automation (Getting Tab Names)   
    OK Got it. I found some code to guide mere here: https://www.autoitscript.com/forum/topic/197080-using-ui-automation-code-in-autoit/page/3/
     
    I basically replaced the for loop with the following:
    Local $pElement1, $oElement1, $sValue1 For $i = 0 To $iElements - 1 $oUIElementArray.GetElement( $i, $pElement1 ) $oElement1 = ObjCreateInterface( $pElement1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) $oElement1.GetCurrentPropertyValue( $UIA_NamePropertyId, $sValue1 ) ConsoleWrite( "$sValue1 = " & $sValue1 & @CRLF ) Next Now the full code to enumerate through open Chrome Tabs is as so:
    #include "CUIAutomation2.au3" ; Window handle Local $hWindow = WinGetHandle( "[CLASS:Chrome_WidgetWin_1]" ) If Not IsHWnd( $hWindow ) Then Return ConsoleWrite( "$hWindow ERR" & @CRLF ) ConsoleWrite( "$hWindow OK" & @CRLF ) ; Activate window WinActivate( $hWindow ) Sleep( 100 ) ; UI Automation object Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation ) If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF ) ConsoleWrite( "$oUIAutomation OK" & @CRLF ) ; Desktop element Local $pDesktop, $oDesktop $oUIAutomation.GetRootElement( $pDesktop ) $oDesktop = ObjCreateInterface( $pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF ) ConsoleWrite( "$oDesktop OK" & @CRLF ) ; Chrome window Local $pCondition $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "Chrome_WidgetWin_1", $pCondition ) If Not $pCondition Then Return ConsoleWrite( "$pCondition ERR" & @CRLF ) ConsoleWrite( "$pCondition OK" & @CRLF ) Local $pChrome, $oChrome $oDesktop.FindFirst( $TreeScope_Descendants, $pCondition, $pChrome ) $oChrome = ObjCreateInterface( $pChrome, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oChrome ) Then Return ConsoleWrite( "$oChrome ERR" & @CRLF ) ConsoleWrite( "$oChrome OK" & @CRLF ) ; Tab item Local $pCondition1 $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_TabItemControlTypeId, $pCondition1 ) If Not $pCondition1 Then Return ConsoleWrite( "$pCondition1 ERR" & @CRLF ) ConsoleWrite( "$pCondition1 OK" & @CRLF ) ;~ ; Find All tab items Local $pTabs, $oUIElementArray, $iElements, $pFound, $oFound, $value $oChrome.FindAll( $TreeScope_Descendants, $pCondition1, $pTabs ) $oUIElementArray = ObjCreateInterface( $pTabs, $sIID_IUIAutomationElementArray, $dtagIUIAutomationElementArray );Ends in array $oUIElementArray.Length( $iElements ) ConsoleWrite( "$iElements:" & $iElements & @CRLF ) Local $pElement1, $oElement1, $sValue1 For $i = 0 To $iElements - 1 $oUIElementArray.GetElement( $i, $pElement1 ) $oElement1 = ObjCreateInterface( $pElement1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) $oElement1.GetCurrentPropertyValue( $UIA_NamePropertyId, $sValue1 ) ConsoleWrite( "$sValue1 = " & $sValue1 & @CRLF ) Next  
    Hope someone can use this code. I won't need to install Chrome UDF or the webdriver with this code ;-)
     
  25. Like
    fraizor reacted to Nine in DLL callback register ?   
    You need to provide a window handle.  No big deal.  Some messages were designed by Windows to use only a window handle.  This is the case.
    But I suppose your first code does not work also.  $hHandle is unassigned.
×
×
  • Create New...