Skip to main content

Module input

Module input 

Source
Expand description

Real input for checks: clicks and keystrokes that take the path a user’s do, not AppKit’s entry points (performClick, selectRowIndexes).

Two kinds:

  • Event-queue input (click, type_text, key…): mouse and key events posted to the app’s own event queue. AppKit dispatches them as it dispatches the window server’s: sendEvent, hit-testing, key equivalents through the menus, the first responder, the field editor and text input. They need the app active and the window key (see ready); no permission.
  • Window-server input (server_click, server_type): CGEvents posted to this process, through the window server like a real keyboard and mouse, without moving the pointer. They need the process to be trusted for Accessibility (System Settings › Privacy & Security › Accessibility, for the terminal that runs the checks): server_available says whether it is. Checks skip them, and say so, when it isn’t.

Events are delivered on the run loop’s next turns: check their effect a moment later.

Enums§

Key
A key for key.

Functions§

click
Clicks the middle of view, as the user would: the window hit-tests the point, so whatever is on top there gets the click.
click_at
Clicks view at x, y points from its top-left corner.
click_at_with
Clicks view at x, y points from its top-left corner, holding mods.
double_click
Double-clicks the middle of view.
key
Presses key with mods in window (to its first responder, or the menus’ key equivalents when ⌘ is held).
ready
Brings the app to the front and makes window key, so input reaches it. True once both hold (it can take a run-loop turn: call it, wait a moment, and call it again before sending input).
server_available
Whether window-server input can be posted: this process is trusted for Accessibility. (Asking for it is the user’s to do, in System Settings.)
server_click
Clicks the middle of view through the window server (see the module docs); false if that isn’t available.
server_type
Types text through the window server (see the module docs); false if that isn’t available.
type_text
Types text into window’s first responder, a key at a time (capitals with ⇧, line breaks as Return).