Jump to content

How do I click on a popup?


masCh
 Share

Recommended Posts

Hi everyone. Hope your weekend has been great.

i have a question, I got to this part (see bottom right corner):Clipboard02.jpg

The popup with the text "Exit". How do I click on that? I tried to Send("e") but it does nothing. If I physically type "e" on the keyboard, it will Exit.

I can't use the Finder Tool on it because as soon as I click on the Finder Tool this section of the desktop gets minimized.

 

-itisallinthemind-

Link to comment
Share on other sites

Ohh, maybe that's why.. I didn't wait for the popup and just did the Send right after the previous command.

THank you! I will try this soon.

Btw, can you advise me where did you get the class:#32768 information from? How can I check it myself using the Finder Tool?

-itisallinthemind-

Link to comment
Share on other sites

Hi.

I've tried this but it doesn't respond:
 

WinWait("[class:#32768]")
Send("{down}{enter}")

I also tried:
 

WinWait("[class:#32768]")
WinActivate("[class:#32768]")
WinWaitActive("[class:#32768]")
Send("{down}{enter}")

And it just hangs (I have to abort script). If I remove the WinWaitActive the script finishes but the button isn't clicked.

You're right, the class number is exactly that with the Finder Tool.

I did some more tests and I think that's not where the problem is.

I tested this code:
 

MouseMove(500,500,30)
ControlClick('[CLASS:Shell_TrayWnd]', '', '[CLASS:Button; INSTANCE:2]', "left")
MouseMove(1000,1000,30)
_GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSystray_ButtonNumber, "right")
MouseMove(1000,500,30)

And only the first two MouseMoves respond. The last one doesn't, but the script finishes and closes by itself.

The _GuiCtrlToolbar_ClickButton must have broken something. And I do not know what it is, the code seems to look fine:
 

; #FUNCTION# ====================================================================================================================
; Author ........: Paul Campbell (PaulIA)
; Modified.......: Gary Frost
; ===============================================================================================================================
Func _GUICtrlToolbar_ClickButton($hWnd, $iCommandID, $sButton = "left", $bMove = False, $iClicks = 1, $iSpeed = 1)
    Local $tRECT = _GUICtrlToolbar_GetButtonRectEx($hWnd, $iCommandID)
    Local $tPoint = _WinAPI_PointFromRect($tRECT)
    $tPoint = _WinAPI_ClientToScreen($hWnd, $tPoint)
    Local $iX, $iY
    _WinAPI_GetXYFromPoint($tPoint, $iX, $iY)
    Local $iMode = Opt("MouseCoordMode", 1)
    If Not $bMove Then
        Local $aPos = MouseGetPos()
        _WinAPI_ShowCursor(False)
        MouseClick($sButton, $iX, $iY, $iClicks, $iSpeed)
        MouseMove($aPos[0], $aPos[1], 0)
        _WinAPI_ShowCursor(True)
    Else
        MouseClick($sButton, $iX, $iY, $iClicks, $iSpeed)
    EndIf
    Opt("MouseCoordMode", $iMode)
EndFunc   ;==>_GUICtrlToolbar_ClickButton

Do you notice anything that could cause subsequent mouse/keyboard commands to be ignored? I'm too scared to modify anything there.

-itisallinthemind-

Link to comment
Share on other sites

@masCh Try this

#include <GuiToolbar.au3>

$TrayButtonTooltip = "Avast"

$Tray = ControlGetHandle("[class:Shell_TrayWnd]", "", "ToolbarWindow323") ; Win10_1703
If Not FindClick($TrayButtonTooltip, "right") Then
  ControlClick("[class:Shell_TrayWnd]", "", "Button2") ; Win10_1703
  $Tray = ControlGetHandle("[class:NotifyIconOverflowWindow]", "", "ToolbarWindow321")
  If Not FindClick($TrayButtonTooltip, "right") Then Exit MsgBox(0, "", "Not found")
EndIf
If WinWait("[class:#32768]", "", 1) Then Send("{down}{enter}")

Func FindClick($Text, $Button = "left", $Click = 1)
  For $i = 0 To _GUICtrlToolbar_ButtonCount($Tray) - 1
    If StringInStr(_GUICtrlToolbar_GetButtonText($Tray, _GUICtrlToolbar_IndexToCommand($Tray, $i)), $Text) > 0 Then
      _GUICtrlToolbar_ClickIndex($Tray, $i, $Button, True, $Click)
      Return 1
    EndIf
  Next
  Return 0
EndFunc

 

Link to comment
Share on other sites

Hi InnI 

The new code doesn't work for me either. It must have finished because the AutoIt script icon disappears after so the class 32768 exists and the WinWait executes successfully. The {down} and {enter} doesn't do anything. I've changed it from Send("{down}{enter}") to MouseMove(100,100,30) and the cursor doesn't move.

Does this code work on yours? Maybe there is something wrong with my specific Windows 10?

D

-itisallinthemind-

Link to comment
Share on other sites

17 minutes ago, masCh said:

Does this code work on yours?

Yes of course. Win10x64 1703 Creators Update.

Do you see the popup?

Try this code with some other tray buttons (change $TrayButtonTooltip to part of tooltip button text).

Try to set some pause before send, for example Sleep(111).

Try to add #RequireAdmin.

Link to comment
Share on other sites

Mine is Win10 x64 1703 as well.

I have tried to change this code with other ones (Steam, Dragon, Speedfan) but they are all the same. Commands after the popup appears are not registered. I even made the script open another script (compiled to .exe) that all it does is Send("{down}{enter}") but the key presses doesn't seem to be sent to that popup or anywhere at all. I will try MouseMove to see in an external script to see anything happens. 

-itisallinthemind-

Link to comment
Share on other sites

@masCh Try this function for click popup menu item by index

#include <GuiMenu.au3>

WinWait("[class:#32768]")
_ClickPopupItem(0)

Func _ClickPopupItem($iIndex)
  Local $hWnd = WinGetHandle("[class:#32768]")
  If Not $hWnd Then Return SetError(1, 0, 0)
  Local $hPopup = _SendMessage($hWnd, 0x01E1) ; MN_GETHMENU
  If $iIndex < 0 Or $iIndex >= _GUICtrlMenu_GetItemCount($hPopup) Then Return SetError(2, 0, 0)
  Local $aRect = _GUICtrlMenu_GetItemRect($hWnd, $hPopup, $iIndex)
  If Not IsArray($aRect) Then Return SetError(3, 0, 0)
  Local $iOpt = Opt("MouseCoordMode", 1)
  MouseClick("left", $aRect[0], $aRect[1], 1, 0)
  Opt("MouseCoordMode", $iOpt)
  Return 1
EndFunc

 

Edited by InnI
Link to comment
Share on other sites

No it doesn't work either. Maybe the popup box is not the typical popup box.
Here is what I've found out after more testing.

$Tray = ControlGetHandle("[class:Shell_TrayWnd]", "", "ToolbarWindow323") ; Win10_1703
If Not FindClick($TrayButtonTooltip, "right") Then
  ControlClick("[class:Shell_TrayWnd]", "", "Button2") ; Win10_1703
  $Tray = ControlGetHandle("[class:NotifyIconOverflowWindow]", "", "ToolbarWindow321")
  If Not FindClick($TrayButtonTooltip, "right") Then Exit MsgBox(0, "", "Not found")
EndIf

;___________________start here
Sleep(100)
WinWait("[class:#32768]")

;SplashTextOn("heh","ok")
;SplashOff()

;MsgBox(1,"heh","done")

MouseMove(1000,500,30)

Basically the MouseMove won't respond  if I enable the SplashText, or basically it won't respond by default.

Only AFTER MsgBox is enabled would the MouseMove respond. But then, doing the MsgBox command turns off the popup that I wanted to send the {down}{enter} command to.


 

-itisallinthemind-

Link to comment
Share on other sites

Hi Junkew, thanks

I tried looking up Simplespy, in the FAQ31 it really doesn't say anything other than its supposed to be in the Examples folder (it's not on my install).

I looked it up on the web and found this https://github.com/jvanegmond/au3_uiautomation/blob/master/Spy/Spy/Examples/simplespy.au3
 

And when I created the 3 .au3 files it gives Error in expression Global $dtagIUIAutomationElement = "SetFocus hresult();"

 

 

 

-itisallinthemind-

Link to comment
Share on other sites

Interesting to see in this that its not only #32678

Title is: <Exit>    Class   := <>   controltype:= <UIA_MenuItemControlTypeId>   ,<50011>    , (0000C35B)    1478;833;176;24
*** Parent Information top down ***
0: Title is: <DropDown> Class   := <WindowsForms10.Window.20808.app.0.3551b1b_r17_ad1>  controltype:= <UIA_MenuControlTypeId>   ,<50009>    , (0000C359)    1478;807;177;52
"Title:=DropDown;controltype:=UIA_MenuControlTypeId;class:=WindowsForms10.Window.20808.app.0.3551b1b_r17_ad1""

UIA_Wrappers can handle it not sure if the control* functions can deal with it. But typical classname seems to be empty (first time I see that)

;~ *** Standard code maintainable ***
#include "UIAWrappers.au3"
AutoItSetOption("MustDeclareVars", 1)

_UIA_setVar("oP1","Title:=DropDown;controltype:=UIA_MenuControlTypeId;class:=WindowsForms10.Window.20808.app.0.3551b1b_r17_ad1")    ;DropDown

;~ $oUIElement=_UIA_getObjectByFindAll("Exit.mainwindow", "title:=Exit;ControlType:=UIA_MenuItemControlTypeId", $treescope_subtree)
_UIA_setVar("oUIElement","Title:=Exit;controltype:=UIA_MenuItemControlTypeId;class:=") ;ControlType:=UIA_MenuItemControlTypeId;classname:=")

;~ Actions split away from logical/technical definition above can come from configfiles 

;~_UIA_Action("oP1","highlight")
_UIA_Action("oP1","setfocus")

;~_UIA_action($oUIElement","highlight")
;~_UIA_action($oUIElement,"click")
;~_UIA_action("oUIElement","highlight")
;~_UIA_action("oUIElement","click")

and another exit menu in same trayitem area which also has no class but is child of #32678

Having the following values for all properties: 
Title is: <Exit>    Class   := <>   controltype:= <UIA_MenuItemControlTypeId>   ,<50011>    , (0000C35B)    1617;850;177;24
*** Parent Information top down ***
0: Title is: <Context>  Class   := <#32768> controltype:= <UIA_MenuControlTypeId>   ,<50009>    , (0000C359)    1614;815;183;62
"Title:=Context;controltype:=UIA_MenuControlTypeId;class:=#32768""  


;~ *** Standard code maintainable ***
#include "UIAWrappers.au3"
AutoItSetOption("MustDeclareVars", 1)

_UIA_setVar("oP1","Title:=Context;controltype:=UIA_MenuControlTypeId;class:=#32768")    ;Context

;~ $oUIElement=_UIA_getObjectByFindAll("Exit.mainwindow", "title:=Exit;ControlType:=UIA_MenuItemControlTypeId", $treescope_subtree)
_UIA_setVar("oUIElement","Title:=Exit;controltype:=UIA_MenuItemControlTypeId;class:=") ;ControlType:=UIA_MenuItemControlTypeId;classname:=")

;~ Actions split away from logical/technical definition above can come from configfiles 

;~_UIA_Action("oP1","highlight")
_UIA_Action("oP1","setfocus")

;~_UIA_action($oUIElement","highlight")
;~_UIA_action($oUIElement,"click")
;~_UIA_action("oUIElement","highlight")
;~_UIA_action("oUIElement","click")

 

Edited by junkew
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...