Jump to content

Do You Think The Code Is Correct? I Deleted Nox Player Apps Text Box Content Using UI Automation


Volkan
 Share

Recommended Posts

  

Hello everyone, friends.

With AutoIt UI Automation, I had to delete data from an app's text box in the Nox Player emulator.

That's how I did it. It seamlessly erases the space in the text box.

I am concerned about whether I am doing everything right in my code. What are your ideas?

Please share your suggestions with me.

Best regards Thanks..

 

#include "..\Includes\CUIAutomation2.au3"
#include "..\Includes\UIA_Functions-a.au3"

Opt("MustDeclareVars", 1)

Global $oUIAutomation
Global $pDesktop, $oDesktop
Global $pNox, $oNox
Global $pNoxSub, $oNoxSub

prepareNox()
setVarsInit()
deleteTextBox()


Func prepareNox()

    ; Prepare Nox Player
    If Not WinExists("[CLASS:Qt5QWindowIcon]") Then
        Exit
    Else
        WinActivate("[CLASS:Qt5QWindowIcon]", "")
    EndIf

    Sleep(1000)

EndFunc   ;==>prepareNox

Func setVarsInit()

    ; Create UI Automation object
    $oUIAutomation = ObjCreateInterface($sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation)
    If Not IsObj($oUIAutomation) Then Return ConsoleWrite("$oUIAutomation ERR" & @CRLF)
    ConsoleWrite("$oUIAutomation OK" & @CRLF)

    ; Get Desktop element
    $oUIAutomation.GetRootElement($pDesktop)
    $oDesktop = ObjCreateInterface($pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement)
    If Not IsObj($oDesktop) Then Return ConsoleWrite("$oDesktop ERR" & @CRLF)
    ConsoleWrite("$oDesktop OK" & @CRLF)

    ; Nox Player Element
    Local $pCondition0
    $oUIAutomation.CreatePropertyCondition($UIA_ClassNamePropertyId, "Qt5QWindowIcon", $pCondition0)
    If Not $pCondition0 Then Return ConsoleWrite("$pCondition0 ERR" & @CRLF)
    ConsoleWrite("$pCondition0 OK" & @CRLF)

    $oDesktop.FindFirst($TreeScope_Children, $pCondition0, $pNox)
    $oNox = ObjCreateInterface($pNox, $sIID_IUIAutomationElement, $dtagIUIAutomationElement)
    If Not IsObj($oNox) Then Return ConsoleWrite("$oNox ERR" & @CRLF)
    ConsoleWrite("$oNox OK" & @CRLF)

    ; Nox Sub Class element
    Local $pCondition0
    $oUIAutomation.CreatePropertyCondition($UIA_ClassNamePropertyId, "subWin", $pCondition0)
    If Not $pCondition0 Then Return ConsoleWrite("$pCondition0 ERR" & @CRLF)
    ConsoleWrite("$pCondition0 OK" & @CRLF)

    $oNox.FindFirst($TreeScope_Descendants, $pCondition0, $pNoxSub)
    $oNoxSub = ObjCreateInterface($pNoxSub, $sIID_IUIAutomationElement, $dtagIUIAutomationElement)
    If Not IsObj($oNoxSub) Then Return ConsoleWrite("$oNoxSub ERR" & @CRLF)
    ConsoleWrite("$oNoxSub OK" & @CRLF)

EndFunc   ;==>setVarsInit

Func deleteTextBox()

    ; Nox Alt Pencere Sınır Değişkeni
    Local $vsNox

    ; Nox Alt Penceresi
    $oNoxSub.GetCurrentPropertyValue($UIA_BoundingRectanglePropertyId, $vsNox)

    ; X konumunu Nox Player boyutuna göre hesapla
    Local $x_mat = Int($vsNox[2] / 1.95)

    ; Y Konumunu Nox Player boyutuna göre hesapla
    Local $y_mat = Int($vsNox[3] / 1.32)

    ; X Konumunu bul
    Local $x = $vsNox[0] + $vsNox[2] - $x_mat

    ; Y Konumunu bul
    Local $y = $vsNox[1] + $vsNox[3] - $y_mat

    ; Fare imlecini x ve y konumuna ışınla
    MouseMove($x, $y)

    ; Farenin sol tuşunu x ve y konumuna tetikle
    MouseClick("left")

    ; Uyku
    Sleep(500)

    ; Imei sil
    Send("{BS 20}")

EndFunc   ;==>deleteTextBox

AutoIt-Nox.thumb.gif.43e3695559a1794074e249206ec2477c.gif

Link to comment
Share on other sites

Func prepareNox()

    ; Prepare Nox Player
    If Not WinExists("[CLASS:Qt5QWindowIcon]") Then Exit
    
    Local $hNox = WinActivate("[CLASS:Qt5QWindowIcon]", "")
    ; Instead of: Sleep(1000)
    WinWaitActive(hNox, "", 0) ; Optionally, add a timeout for it not to be active

EndFunc   ;==>prepareNox

And since you're already using UI Automation, use it for setting the value of that box too. (Granted, I can't test this, so maybe your field doesn't support it)

If you're using UIASpy, this example code is under Sample Code\Patterns... and Sample Code\Pattern Methods...

Local $pValuePattern, $oValuePattern
$oNoxSub.GetCurrentPattern($UIA_ValuePatternId, $pValuePattern)
$oValuePattern = ObjCreateInterface($pValuePattern, $sIID_IUIAutomationValuePattern, $dtagIUIAutomationValuePattern)
If Not IsObj($oValuePattern1) Then Return ConsoleWrite("$oValuePattern1 ERR" & @CRLF)
ConsoleWrite("$oValuePattern OK" & @CRLF)

Local $sValue = "" ; Set this to an empty string to clear the text
$oValuePattern.SetValue($sValue)
ConsoleWrite("$oValuePattern.SetValue()" & @CRLF)
Edited by seadoggie01

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

First of all I am grateful for your advice.

Yes I know the SetValue and Invoke methods. But NoxPlayer does not have access to hidden elements of any application.

Of the Nox Player Class elements, I could only access "Qt5QWindowIcon" and "Qt5QWindowToolSaveBits".

Note: I have used all tools like UIASpy and Microsoft Inscept.exe. Result failed.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...