UIAutomation Events on Powershell

Welcome Forums General PowerShell Q&A UIAutomation Events on Powershell

Viewing 3 reply threads
  • Author
    Posts
    • #229468
      Participant
      Topics: 3
      Replies: 1
      Points: 15
      Rank: Member

      I’m trying to listen UIAutomation events using Powershell, and wrote somethings like this.

      [/crayon]

      But I got a problem.

      The  AddautomationPropertyChangedEventHandler method will need a  AutomationPropertyChangedEventHandler (with an  eventHandler as parameter) as parameter, but both  AutomationPropertyChangedEventHandler and  eventHandler are functions.

      That means function(function(function()))

      (Please find the  $propChangeHandler($OnPropertyChange) from the above code.)

      Obviously writing it as  $propChangeHandler($OnPropertyChange) is not correct. How can I revise?

    • #229504
      Participant
      Topics: 17
      Replies: 1956
      Points: 4,010
      Helping Hand
      Rank: Community Hero

      What exactly isn’t working? The OnPropertyChange is a ScriptBlock, not a function, basically when the event is triggered call this script. When the event triggers, it will return an eventHandler object that has a src (source) and e (element) property that is being processed be the OnPropertyChange script. It looks like you call the Subscribe-PropertyChange with an element parameter to indicate what element to monitor.

      It appears you cross-posted this here as well: https://answers.microsoft.com/en-us/windows/forum/all/uiautomation-events-on-powershell/4e636b5b-3fde-40e1-a400-06ab6f724aeb

    • #229588
      Participant
      Topics: 3
      Replies: 1
      Points: 15
      Rank: Member

      What exactly isn’t working? The OnPropertyChange is a ScriptBlock, not a function, basically when the event is triggered call this script. When the event triggers, it will return an eventHandler object that has a src (source) and e (element) property that is being processed be the OnPropertyChange script. It looks like you call the Subscribe-PropertyChange with an element parameter to indicate what element to monitor.

      It appears you cross-posted this here as well: https://answers.microsoft.com/en-us/windows/forum/all/uiautomation-events-on-powershell/4e636b5b-3fde-40e1-a400-06ab6f724aeb

      It get this syntax error:

       

      + $propChangeHandler($OnPropertyChange),
      + ~
      Missing ‘)’ in method call.

       

      but when I remove ($OnPropertyChange), it report no syntax error.

    • #229810
      Participant
      Topics: 17
      Replies: 1956
      Points: 4,010
      Helping Hand
      Rank: Community Hero

      Not sure why $propChangeHandler is set like that, but it’s odd to call variable like a function with params, try it like this:

Viewing 3 reply threads
  • The topic ‘UIAutomation Events on Powershell’ is closed to new replies.