# PFApplicationUIElement

A concrete class representing the root application UI element of a running application or the system-wide UI element.

Superclass: PFUIElement
Declared In: PFUIElement.h

##### Discussion

A PFApplicationUIElement object represents the root application UI element of a running application or the system-wide UI element. It is a subclass of PFUIElement and inherits all of PFUIElement's functionality (except that it does not respond to the -PFUIElementWasDestroyed: delegate method). It offers additional features for root-level UI elements (applications and the system-wide UI element).

See the PFUIElement class description for more information.

Class Design:

Before a client application can make use of this class, the "Enable access for assistive devices" setting in the Universal Access pane of System Preferences must be turned on, or the client application must be trusted through use of the accessibility API's `AXMakeProcessTrusted()` function. Authentication may be required.

## Groups

### INITIALIZATION

#### Group members:

`-initSystemWideWithDelegate:`

  The designated initializer for the PFApplicationUIElement class for a system-wide element.

`-initWithPath:delegate:`

  Initializes and returns a newly allocated PFApplicationUIElement object with `path`, the full path to the target application's bundle or file.

`-initWithPid:delegate:`

  The designated initializer for the PFApplicationUIElement class for a specific application.

### ACCESSOR METHODS

#### Group members:

`-pidNumber`

  Returns the BSD Unix process identification number (PID) of the receiver.

### ELEMENT UTILITIES

#### Group members:

`-elementAtPoint:`

  Creates and returns a PFUIElement object representing the visible UI element located at `point` on the screen belonging to the receiving application UI element.

`-typeCharacters:keyCode:withModifierFlags:`

  Posts keyboard events to the application represented by the receiver, whether or not it is the active application.

`+typeCharactersSystemWide:keyCode:withModifierFlags:`

  Class method posts keyboard events to the active application.

## Methods

`-elementAtPoint:`

  Creates and returns a PFUIElement object representing the visible UI element located at `point` on the screen belonging to the receiving application UI element.

`-initSystemWideWithDelegate:`

  The designated initializer for the PFApplicationUIElement class for a system-wide element.

`-initWithPath:delegate:`

  Initializes and returns a newly allocated PFApplicationUIElement object with `path`, the full path to the target application's bundle or file.

`-initWithPid:delegate:`

  The designated initializer for the PFApplicationUIElement class for a specific application.

`-pidNumber`

  Returns the BSD Unix process identification number (PID) of the receiver.

`-typeCharacters:keyCode:withModifierFlags:`

  Posts keyboard events to the application represented by the receiver, whether or not it is the active application.

`+typeCharactersSystemWide:keyCode:withModifierFlags:`

  Class method posts keyboard events to the active application.

### elementAtPoint:

Creates and returns a PFUIElement object representing the visible UI element located at `point` on the screen belonging to the receiving application UI element.

    - (PFUIElement *)elementAtPoint:(NSPoint)point;

##### Parameters

`point`

  An NSPoint struct using top-left relative screen coordinates.

##### Return Value

The PFUIElement object at `point`, or `nil` if the application does not own it.

##### Discussion

Use this method to read the screen, based, for example, on the current location of the mouse.

Use the PFUIElement class method +elementAtPoint:withDelegate:error: instead of this instance method to get a PFUIElement object representing the UI element located at `point` without regard to what application owns it.

See PFUIElement's -initWithElementRef:delegate:: method for important information.

### initSystemWideWithDelegate:

The designated initializer for the PFApplicationUIElement class for a system-wide element.

    - (PFApplicationUIElement *)initSystemWideWithDelegate:(id)delegate;

##### Parameters

`delegate`

  An object that may implement the optional -PFUIElementReportError: delegate method. May be `nil.`

##### Return Value

An object of type PFApplicationUIElement.

##### Discussion

Initializes and returns a newly allocated PFApplicationUIElement object.

Use this designated initializer to initialize a newly-allocated root UI element object for the entire system, representing all running applications collectively. Use this method, for example, to obtain the element currently having systemwide focus without first determining which application is active.

A PFApplicationUIElement object does not participate in PFUIElement's delegate and notification mechanisms regarding destroyed UI elements. See the -PFUIElementWasDestroyed: delegate method and PFUIElement's -elementInfo for details regarding these mechanisms.

See PFUIElement's -initWithElementRef:delegate: method for important information.

See also -initWithPath:delegate: and -initWithPid:delegate:.

### initWithPath:delegate:

Initializes and returns a newly allocated PFApplicationUIElement object with `path`, the full path to the target application's bundle or file.

    - (PFApplicationUIElement *)initWithPath:(NSString *)path
            delegate:(id)aDelegate;

##### Parameters

`path`

  An NSString object giving the full path to the application file.

`aDelegate`

  An object that may implement the optional -PFUIElementReportError: delegate method. May be `nil.`

##### Return Value

An object of type PFApplicationUIElement.

##### Discussion

Use this convenience initializer or the designated initializer -initWithPid:delegate: to initialize a newly-allocated root UI element object for a specific application; for example, to browse a specific application's user interface without regard to whether it is frontmost or where on the screen its UI elements may be located.

A PFApplicationUIElement object does not participate in PFUIElement's delegate and notification mechanisms regarding destroyed UI elements. It does not report when it is destroyed (that is, when the application quits). See the -PFUIElementWasDestroyed: delegate method and PFUIElement's -elementInfo for details regarding these mechanisms.

See PFUIElement's -initWithElementRef:delegate: for important information.

See also -initWithPid:delegate: and -initSystemWideWithDelegate:.

### initWithPid:delegate:

The designated initializer for the PFApplicationUIElement class for a specific application.

    - (PFApplicationUIElement *)initWithPid:(pid_t)pid delegate:(id)aDelegate;

##### Parameters

`pid`

  An integer, the running application's BSD Unix process identification number.

`aDelegate`

  An object that may implement the optional -PFUIElementReportError: delegate method. May be `nil.`

##### Return Value

An object of type PFApplicationUIElement.

##### Discussion

Initializes and returns a newly allocated PFApplicationUIElement object with `pid`, the target application's BSD Unix process identification number (PID).

Use this designated initializer or the convenience initializer -initWithPath:delegate: to initialize a newly-allocated root UI element object for a specific application; for example, to browse a specific application's user interface without regard to whether it is frontmost or where on the screen its UI elements may be located.

A PFApplicationUIElement object does not participate in PFUIElement's delegate and notification mechanisms regarding destroyed UI elements. It does not report when it is destroyed (that is, when the application quits). See the -PFUIElementWasDestroyed: delegate method and PFUIElement's -elementInfo for details regarding these mechanisms.

See PFUIElement's -initWithElementRef:delegate: for important information.

See also -initWithPath:delegate: and -initSystemWideWithDelegate:.

### pidNumber

Returns the BSD Unix process identification number (PID) of the receiver.

    - (NSNumber *)pidNumber;

##### Return Value

An NSNumber object encoding an integer value.

##### Discussion

It is sometimes useful to know the process identification number of an application. For example, it can be used with a variety of Carbon functions to access information not otherwise readily available in Cocoa.

See also the -pid method in the PFUIElement class, which returns the PID as an integer.

Use NSNumber's `-intValue` method to extract the integer value of the result.

### typeCharacters:keyCode:withModifierFlags:

Posts keyboard events to the application represented by the receiver, whether or not it is the active application.

    - (void)typeCharacters:(NSString *)characters keyCode:(unsigned short)virtualKey
            withModifierFlags:(NSUInteger)flags;

##### Parameters

`characters`

  An NSString object representing a Unicode character that can be generated by a single key press without modifier keys (Shift excepted).

`virtualKey`

  The virtual key code provided by NSEvent's `-keyCode` method.

`flags`

  An integer; either 0 for no modifier keys, or one or more of the first five key mask constants listed in NSEvent.h (combined using the C bitwise OR operator, if more than one) for modifier keys.

##### Discussion

Use this method to type one character at a time into the UI element that currently has keyboard focus in the application represented by the receiver (usually a text-based view or control such as a text view or a text field). Specifying the Command key in `flags` may be treated by the application as a keyboard shortcut for a menu item or button.

Use -typeCharactersSystemWide:keyCode:withModifierFlags: instead of this method to type characters into the active application without first determining which application is active.

The `characters` and `flags` parameters are equivalent to those used in NSEvent's `-charactersIgnoringModifiers` and `-modifierFlags` methods. The `virtualKey` parameter is the virtual key code provided by NSEvent's `-keyCode` method; it is a hardware-independent integer value provided by system resources for every known keyboard, mapped from the hardware-dependent raw key code using the current keyboard layout resource.

On Roman systems, the `characters` parameter is optional and should be passed as `nil` or an empty string unless you are knowledgeable regarding the use of keyboard layouts, but it is not optional on some other systems where it is used as a hint to supplement the virtual key code during key translation.

### typeCharactersSystemWide:keyCode:withModifierFlags:

Class method posts keyboard events to the active application.

    + (void)typeCharactersSystemWide:(NSString *)characters
            keyCode:(unsigned short)virtualKey withModifierFlags:(NSUInteger)flags;

##### Parameters

`characters`

  An NSString object representing a Unicode character that can be generated by a single key press without modifier keys (Shift excepted).

`virtualKey`

  The virtual key code provided by NSEvent's `-keyCode` method.

`flags`

  An unsigned integer; either 0 for no modifier keys, or one or more of the first five key mask constants listed in NSEvent.h (combined using the C bitwise OR operator, if more than one) for modifier keys.

##### Discussion

Use this method to type one character at a time into the UI element that currently has keyboard focus in the active application (usually a text-based view or control such as a text view or a text field). Specifying the Command key in flags may be treated by the application as a keyboard shortcut for a menu item or button.

Use -typeCharacters:keyCode:withModifierFlags: instead of this method to type characters into a specific application whether or not it is active.

The `characters` and `flags` parameters are equivalent to those used in NSEvent's `-charactersIgnoringModifiers` and `-modifierFlags` methods. The `virtualKey` parameter is the virtual key code provided by NSEvent's `-keyCode` method; it is a hardware-independent integer value provided by system resources for every known keyboard, mapped from the hardware-dependent raw key code using the current keyboard layout resource.

On Roman systems, the `characters` parameter is optional and should be passed as `nil` or an empty string unless you are knowledgeable regarding the use of keyboard layouts, but it is not optional on some other systems where it is used as a hint to supplement the virtual key code during key translation.

Last Updated: Wednesday, May 19, 2010