RequestCapabilities

Requests platform permissions or queries their current state.

This function is exported by the KS module.

Status := RequestCapabilities(Capabilities*)

Parameters

Capabilities

Zero or more capability-name strings. Each string can contain names separated by commas or spaces; arrays of names are also accepted. If no capability is specified, the function returns the current state of every capability without prompting.

Capability Names

NamePurpose
InputMonitoringObserve keyboard/mouse input or poll arbitrary key/button state. Modifier state, lock-toggle state and cursor position are ungated.
InputControlSynthesize or suppress keyboard/mouse input, including BlockInput. A suppressing hook requires this and InputMonitoring.
WindowMonitoringQuery, enumerate, identify or subscribe to events from foreign windows and controls. On macOS it requires Accessibility and Screen Recording permission.
WindowControlActivate or mutate foreign windows and controls. Resolving a target can also require WindowMonitoring.
ScreenCaptureCapture pixels with PixelGetColor, ImageSearch or Image.
AudioCaptureReserve permission for audio capture. Audio.Recorder requires it before it opens a device.
CameraCaptureReserve permission for camera capture. No current capture API consumes it.
ClipboardMonitoringRead or listen to the clipboard. Clipboard writes are ungated.

The eight canonical names are case-insensitive. Other spellings and aliases are rejected.

Return Value

Type: Object

Returns an object with one property per capability. Each value is "Granted", "Denied", "NotApplicable" or "Unsupported". The IsGranted property is 1 only if every requested capability was granted or is not applicable.

Remarks

Linux

On Linux, keysharp-input and keysharp-desktop approve their capabilities separately, so one call can show a polkit prompt for each. Grants persist until revoked and are shared by scripts run by the same executable. See Linux permissions.

Use #Requires capability when permissions are needed from startup. Use RequestCapabilities when a script needs to choose when to prompt or inspect individual results.

Examples

#Import "Ks" { RequestCapabilities }
Caps := RequestCapabilities("InputMonitoring", "ScreenCapture")
if Caps.IsGranted
    MsgBox "All permissions granted"
MsgBox Caps.ScreenCapture

; Query without prompting.
Current := RequestCapabilities()

#Requires capability, Platform Support