Platforms to show: All Mac Windows Linux Cross-Platform

/MacOSX/Accessibility services/Active Window Logging


Required plugins for this example: MBS Util Plugin, MBS MacCF Plugin, MBS Main Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacOSX/Accessibility services/Active Window Logging

This example is the version from Thu, 6th Feb 2013.

Project "Active Window Logging.xojo_binary_project"
Class mainWindow Inherits Window
Control List Inherits ListBox
ControlInstance List Inherits ListBox
End Control
Control Liste Inherits ListBox
ControlInstance Liste Inherits ListBox
End Control
EventHandler Sub Open() if AccessibilityMBS.Available then if AccessibilityMBS.AXAPIEnabled then List.InsertRow 0,"Listing..." else List.InsertRow 0,"Accessibility API is not enabled." end if ce=new MyCarbonEvents ce.Listen else MsgBox "This test requires Mac OS X 10.2" end if End EventHandler
Sub Switched(processSerial as memoryBlock) // Application switched dim p as ProcessMBS dim e as AXUIElementMBS dim v as AXValueMBS dim f as AXUIElementMBS dim pid,error,err as integer dim i,c as integer p=new ProcessMBS p.GetProcess(processSerial) pid=p.ProcessID c=UBound(apps) for i=1 to c if pid=apps(i) then Return // allready observing end if next e=AccessibilityMBS.SystemWideAXUIElement if e<>nil then v=e.AttributeValue(AccessibilityMBS.kAXFocusedApplicationAttribute) if v<>Nil and v.Type=AccessibilityMBS.kAXUIElementMBSTypeID then o=new MyObserver error=o.Create(pid) f=new AXUIElementMBS f.Handle=v.Handle // just clone for the one line: err=o.AddNotification(f,AccessibilityMBS.kAXApplicationDeactivatedNotification) err=o.AddNotification(f,AccessibilityMBS.kAXApplicationActivatedNotification) err=o.AddNotification(f,AccessibilityMBS.kAXApplicationHiddenNotification) err=o.AddNotification(f,AccessibilityMBS.kAXApplicationShownNotification) err=o.AddNotification(f,AccessibilityMBS.kAXWindowCreatedNotification) err=o.AddNotification(f,AccessibilityMBS.kAXWindowDeminiaturizedNotification) err=o.AddNotification(f,AccessibilityMBS.kAXWindowMiniaturizedNotification) err=o.AddNotification(f,AccessibilityMBS.kAXWindowMovedNotification) err=o.AddNotification(f,AccessibilityMBS.kAXWindowResizedNotification) err=o.AddNotification(f,AccessibilityMBS.kAXFocusedUIElementChangedNotification) err=o.AddNotification(f,AccessibilityMBS.kAXFocusedWindowChangedNotification) 'List.InsertRow 0,"Observing application """+p.Name+"""." apps.Append pid end if end if Update End Sub
Sub Update() dim e1,e2,e3 as AXUIElementMBS dim a1,a2,a3,a4 as AXValueMBS dim typ as integer dim s as String e1=AccessibilityMBS.SystemWideAXUIElement a1=e1.AttributeValue(AccessibilityMBS.kAXFocusedApplicationAttribute) typ=a1.Type if typ=AccessibilityMBS.kAXUIElementMBSTypeID then e2=new AXUIElementMBS e2.Handle=a1.Handle e2.RetainObject a2=e2.AttributeValue(AccessibilityMBS.kAXTitleAttribute) if a2<>nil and a2.Type=kCFStringMBSTypeID then s=a2.CFStringMBS.str end if a3=e2.AttributeValue(AccessibilityMBS.kAXFocusedWindowAttribute) if a3<>nil then typ=a3.Type if typ=AccessibilityMBS.kAXUIElementMBSTypeID then e3=new AXUIElementMBS e3.Handle=a3.Handle e3.RetainObject a4=e3.AttributeValue(AccessibilityMBS.kAXTitleAttribute) if a4<>nil and a4.Type=kCFStringMBSTypeID then if s<>"" then s=s+" - " end if s=s+a4.CFStringMBS.str end if end if end if end if if last<>s then List.InsertRow 0,s last=s end if End Sub
Property Protected apps(0) As integer
Property Protected ce As mycarbonEvents
Property Protected last As string
Property Protected o As myObserver
End Class
MenuBar Menu
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = "File"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu0 = "Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class MyObserver Inherits AXObserverMBS
EventHandler Sub Action(element as AXUIElementMBS, notification as CFStringMBS) mainWindow.Liste.InsertRow 0,notification.str mainWindow.Update End EventHandler
End Class
Class MyCarbonEvents Inherits CarbonApplicationEventsMBS
EventHandler Sub ApplicationSwitched(ProcessSerial as memoryblock) mainWindow.switched ProcessSerial End EventHandler
End Class
Class App Inherits Application
End Class
Module CFUtil
Function CFStringMBS(extends o as CFObjectMBS) As CFStringMBS dim s as CFStringMBS if o<>nil then if o.Handle<>0 then s=new CFStringMBS s.Handle=o.Handle s.RetainObject Return s end if end if End Function
End Module
End Project

See also:

The items on this page are in the following plugins: MBS MacOSX Plugin.


The biggest plugin in space...