Documentation
¶
Overview ¶
Package native binds the MaaFramework C API for Go through purego. The four mandatory dynamic libraries (MaaFramework, MaaToolkit, MaaAgentServer and MaaAgentClient) are loaded by Initialize from an explicit directory or the platform loader's current search configuration, and their C functions are resolved into the package-level function variables named after them. Shutdown unloads the libraries but does not restore DLL search configuration changed on Windows.
Deprecated C APIs are intentionally not bound. The package is not safe for concurrent use: Initialize and Shutdown must be serialized by the caller (the public maa package does so), and no function of this package may be called after Shutdown: successfully unloaded libraries leave their variables nil, and function values captured before Shutdown reference native code whose lifetime is no longer guaranteed.
Initialize supports linux, android, darwin and windows on amd64 or arm64 and panics for any other GOOS it compiles on.
Index ¶
- Constants
- Variables
- func Initialize(libDir string) error
- func Shutdown() error
- type Entry
- type Library
- type LibraryLoadError
- type MaaCtrlOption
- type MaaCustomActionCallback
- type MaaCustomRecognitionCallback
- type MaaEventCallback
- type MaaGamepadType
- type MaaGlobalOption
- type MaaInferenceDevice
- type MaaInferenceExecutionProvider
- type MaaMacOSInputMethod
- type MaaMacOSPermission
- type MaaMacOSScreencapMethod
- type MaaResOption
- type MaaTaskerOption
- type SymbolLookupError
Constants ¶
const ( // MaaInferenceExecutionProvider_Auto lets MaaFramework choose the execution // provider; MaaResOption_InferenceDevice is not recommended with it because // the provider used varies across user devices. The framework tries CUDA, // then DirectML, then WebGPU, and falls back to CPU. MaaInferenceExecutionProvider_Auto = 0 // MaaInferenceExecutionProvider_CPU selects the CPU execution provider; // MaaResOption_InferenceDevice has no effect with it. MaaInferenceExecutionProvider_CPU = 1 // MaaInferenceExecutionProvider_DirectML selects DirectML; // MaaResOption_InferenceDevice sets the adapter id from the Win32 API // EnumAdapters1. MaaInferenceExecutionProvider_DirectML = 2 // MaaInferenceExecutionProvider_CUDA selects CUDA; MaaResOption_InferenceDevice // sets the NVIDIA GPU id. MaaInferenceExecutionProvider_CUDA = 4 // MaaInferenceExecutionProvider_WebGPU selects WebGPU; // MaaResOption_InferenceDevice sets the WebGPU device id // (ep.webgpuexecutionprovider.deviceId). Auto uses device 0. The provider is // shipped on Windows, Linux, and macOS. MaaInferenceExecutionProvider_WebGPU = 5 )
Execution provider values for MaaResOption_InferenceExecutionProvider.
Variables ¶
var ( MaaAgentClientCreateV2 func(identifier uintptr) uintptr MaaAgentClientCreateTcp func(port uint16) uintptr MaaAgentClientDestroy func(client uintptr) MaaAgentClientIdentifier func(client uintptr, identifier uintptr) bool MaaAgentClientBindResource func(client uintptr, res uintptr) bool MaaAgentClientRegisterResourceSink func(client uintptr, res uintptr) bool MaaAgentClientRegisterControllerSink func(client uintptr, ctrl uintptr) bool MaaAgentClientRegisterTaskerSink func(client uintptr, tasker uintptr) bool MaaAgentClientConnect func(client uintptr) bool MaaAgentClientDisconnect func(client uintptr) bool MaaAgentClientConnected func(client uintptr) bool MaaAgentClientAlive func(client uintptr) bool MaaAgentClientSetTimeout func(client uintptr, milliseconds int64) bool MaaAgentClientGetCustomRecognitionList func(client uintptr, buffer uintptr) bool MaaAgentClientGetCustomActionList func(client uintptr, buffer uintptr) bool )
Agent client C API bindings (MaaAgentClient.h). MaaAgentClientCreateV2 reads the identifier from a caller-owned MaaStringBuffer; MaaAgentClientIdentifier writes the effective identifier to such a buffer. The Get*List functions fill a caller-owned MaaStringListBuffer. MaaAgentClientSetTimeout takes milliseconds per communication wait. Create functions return owned handles released by MaaAgentClientDestroy.
var ( MaaAgentServerRegisterCustomRecognition func(name string, recognition MaaCustomRecognitionCallback, transArg uintptr) bool MaaAgentServerRegisterCustomAction func(name string, action MaaCustomActionCallback, transArg uintptr) bool MaaAgentServerAddResourceSink func(sink MaaEventCallback, transArg uintptr) int64 MaaAgentServerAddControllerSink func(sink MaaEventCallback, transArg uintptr) int64 MaaAgentServerAddTaskerSink func(sink MaaEventCallback, transArg uintptr) int64 MaaAgentServerAddContextSink func(sink MaaEventCallback, transArg uintptr) int64 MaaAgentServerStartUp func(identifier string) bool MaaAgentServerShutDown func() MaaAgentServerJoin func() MaaAgentServerDetach func() )
Agent server functions. The server runs in its own process and serves custom recognition and action implementations to the host that connects through an agent client. MaaAgentServerRegisterCustomRecognition and MaaAgentServerRegisterCustomAction register those implementations under the pipeline custom_recognition and custom_action field names; the native layer rejects duplicate names. The Add*Sink functions receive the events the connected client forwards for its resource, controller, tasker or context through a MaaEventCallback and return a sink ID, 0 on failure.
MaaAgentServerStartUp starts the service in a separate native thread and returns after starting it; the identifier is the rendezvous name matched with the agent client, an IPC socket named after the identifier or, for a purely numeric identifier in 1-65535, the TCP port the client binds. An empty identifier fails to start. MaaAgentServerShutDown requests a stop and, while the service thread is attached, waits for it to exit before closing the sockets; MaaAgentServerJoin waits for that thread to end without requesting a stop; MaaAgentServerDetach abandons the thread, giving up the ability to wait for or observe its exit.
var ( MaaTaskerCreate func() uintptr MaaTaskerDestroy func(tasker uintptr) MaaTaskerAddSink func(tasker uintptr, sink MaaEventCallback, transArg uintptr) int64 MaaTaskerRemoveSink func(tasker uintptr, sinkId int64) MaaTaskerClearSinks func(tasker uintptr) MaaTaskerAddContextSink func(tasker uintptr, sink MaaEventCallback, transArg uintptr) int64 MaaTaskerRemoveContextSink func(tasker uintptr, sinkId int64) MaaTaskerClearContextSinks func(tasker uintptr) MaaTaskerSetOption func(tasker uintptr, key MaaTaskerOption, value unsafe.Pointer, valSize uint64) bool MaaTaskerBindResource func(tasker uintptr, res uintptr) bool MaaTaskerBindController func(tasker uintptr, ctrl uintptr) bool MaaTaskerInited func(tasker uintptr) bool MaaTaskerPostTask func(tasker uintptr, entry, pipelineOverride string) int64 MaaTaskerPostRecognition func(tasker uintptr, recognitionType, recognitionParam string, image uintptr) int64 MaaTaskerPostAction func(tasker uintptr, actionType, actionParam string, box uintptr, recoDetail string) int64 MaaTaskerStatus func(tasker uintptr, id int64) int32 MaaTaskerWait func(tasker uintptr, id int64) int32 MaaTaskerRunning func(tasker uintptr) bool MaaTaskerPostStop func(tasker uintptr) int64 MaaTaskerStopping func(tasker uintptr) bool MaaTaskerGetResource func(tasker uintptr) uintptr MaaTaskerGetController func(tasker uintptr) uintptr MaaTaskerClearCache func(tasker uintptr) bool MaaTaskerGetRecognitionDetail func(tasker uintptr, recoId int64, nodeName uintptr, algorithm uintptr, hit *bool, box uintptr, detailJson uintptr, raw uintptr, draws uintptr) bool MaaTaskerGetActionDetail func(tasker uintptr, actionId int64, nodeName uintptr, action uintptr, box uintptr, success *bool, detailJson uintptr) bool MaaTaskerGetWaitFreezesDetail func(tasker uintptr, wfId int64, nodeName uintptr, phase uintptr, success *bool, elapsedMs *uint64, recoIdList uintptr, recoIdListSize *uint64, roi uintptr) bool MaaTaskerGetNodeDetail func(tasker uintptr, nodeId int64, nodeName uintptr, recoId *int64, actionId *int64, completed *bool) bool MaaTaskerGetTaskDetail func(tasker uintptr, taskId int64, entry uintptr, nodeIdList uintptr, nodeIdListSize *uint64, status *int32) bool MaaTaskerGetLatestNode func(tasker uintptr, taskName string, latestId *int64) bool MaaTaskerOverridePipeline func(tasker uintptr, taskId int64, pipelineOverride string) bool )
MaaTasker API bindings (MaaTasker.h). MaaTaskerCreate creates a tasker handle released by MaaTaskerDestroy. Post* functions post work asynchronously and return an id that MaaTaskerStatus and MaaTaskerWait accept, and sink registration returns a sink id for MaaTaskerRemoveSink and MaaTaskerRemoveContextSink. MaaTaskerSetOption reads the option from the value buffer of valSize bytes. The detail getters write through caller-supplied output pointers; MaaTaskerGetWaitFreezesDetail and MaaTaskerGetTaskDetail take their *Size arguments by pointer, with the buffer capacity passed in and the actual element count filled back.
var ( MaaResourceCreate func() uintptr MaaResourceDestroy func(res uintptr) MaaResourceAddSink func(res uintptr, sink MaaEventCallback, transArg uintptr) int64 MaaResourceRemoveSink func(res uintptr, sinkId int64) MaaResourceClearSinks func(res uintptr) MaaResourceRegisterCustomRecognition func(res uintptr, name string, recognition MaaCustomRecognitionCallback, transArg uintptr) bool MaaResourceUnregisterCustomRecognition func(res uintptr, name string) bool MaaResourceClearCustomRecognition func(res uintptr) bool MaaResourceRegisterCustomAction func(res uintptr, name string, action MaaCustomActionCallback, transArg uintptr) bool MaaResourceUnregisterCustomAction func(res uintptr, name string) bool MaaResourceClearCustomAction func(res uintptr) bool MaaResourcePostBundle func(res uintptr, path string) int64 MaaResourcePostOcrModel func(res uintptr, path string) int64 MaaResourcePostPipeline func(res uintptr, path string) int64 MaaResourcePostImage func(res uintptr, path string) int64 MaaResourceOverridePipeline func(res uintptr, pipelineOverride string) bool MaaResourceOverrideNext func(res uintptr, nodeName string, nextList uintptr) bool MaaResourceOverrideImage func(res uintptr, imageName string, image uintptr) bool MaaResourceGetNodeData func(res uintptr, nodeName string, buffer uintptr) bool MaaResourceClear func(res uintptr) bool MaaResourceStatus func(res uintptr, id int64) int32 MaaResourceWait func(res uintptr, id int64) int32 MaaResourceLoaded func(res uintptr) bool MaaResourceSetOption func(res uintptr, key MaaResOption, value unsafe.Pointer, valSize uint64) bool MaaResourceGetHash func(res uintptr, buffer uintptr) bool MaaResourceGetNodeList func(res uintptr, buffer uintptr) bool MaaResourceGetCustomRecognitionList func(res uintptr, buffer uintptr) bool MaaResourceGetCustomActionList func(res uintptr, buffer uintptr) bool MaaResourceGetDefaultRecognitionParam func(res uintptr, recoType string, buffer uintptr) bool MaaResourceGetDefaultActionParam func(res uintptr, actionType string, buffer uintptr) bool )
MaaResource API bindings (MaaResource.h). MaaResourceCreate creates a resource handle released by MaaResourceDestroy. Post* functions load content asynchronously and return a resource id that MaaResourceStatus and MaaResourceWait accept, and custom recognition and action callbacks are registered and unregistered by name. Getters such as GetHash, GetNodeList, and GetDefaultRecognitionParam write into caller-created buffer handles.
var ( MaaAdbControllerCreate func(adbPath, address string, screencapMethods uint64, inputMethods uint64, config, agentPath string) uintptr MaaPlayCoverControllerCreate func(address, uuid string) uintptr MaaWin32ControllerCreate func(hWnd unsafe.Pointer, screencapMethods uint64, mouseMethod, keyboardMethod uint64) uintptr MaaLinuxControllerCreate func(configJson string) uintptr MaaCustomControllerCreate func(controller unsafe.Pointer, controllerArg uintptr) uintptr MaaGamepadControllerCreate func(hWnd unsafe.Pointer, gamepadType MaaGamepadType, screencapMethod uint64) uintptr MaaMacOSControllerCreate func(windowID uint32, screencapMethod MaaMacOSScreencapMethod, inputMethod MaaMacOSInputMethod) uintptr MaaAndroidNativeControllerCreate func(configJson string) uintptr MaaReplayControllerCreate func(recordingPath string) uintptr MaaRecordControllerCreate func(inner uintptr, recordingPath string) uintptr MaaControllerDestroy func(ctrl uintptr) MaaControllerAddSink func(ctrl uintptr, sink MaaEventCallback, transArg uintptr) int64 MaaControllerRemoveSink func(ctrl uintptr, sinkId int64) MaaControllerClearSinks func(ctrl uintptr) MaaControllerSetOption func(ctrl uintptr, key MaaCtrlOption, value unsafe.Pointer, valSize uint64) bool MaaControllerPostConnection func(ctrl uintptr) int64 MaaControllerPostClick func(ctrl uintptr, x, y int32) int64 // MaaControllerPostClickV2 posts a click with explicit contact and pressure: // for adb controller, contact means finger id (0 for first finger, 1 for second finger, etc); // for win32 controller, contact means mouse button id (0 for left, 1 for right, 2 for middle). MaaControllerPostClickV2 func(ctrl uintptr, x, y, contact, pressure int32) int64 MaaControllerPostSwipe func(ctrl uintptr, x1, y1, x2, y2, duration int32) int64 MaaControllerPostSwipeV2 func(ctrl uintptr, x1, y1, x2, y2, duration, contact, pressure int32) int64 MaaControllerPostClickKey func(ctrl uintptr, keycode int32) int64 MaaControllerPostInputText func(ctrl uintptr, text string) int64 MaaControllerPostStartApp func(ctrl uintptr, intent string) int64 MaaControllerPostStopApp func(ctrl uintptr, intent string) int64 MaaControllerPostTouchDown func(ctrl uintptr, contact, x, y, pressure int32) int64 MaaControllerPostTouchMove func(ctrl uintptr, contact, x, y, pressure int32) int64 MaaControllerPostTouchUp func(ctrl uintptr, contact int32) int64 MaaControllerPostRelativeMove func(ctrl uintptr, dx, dy int32) int64 MaaControllerPostKeyDown func(ctrl uintptr, keycode int32) int64 MaaControllerPostKeyUp func(ctrl uintptr, keycode int32) int64 MaaControllerPostScreencap func(ctrl uintptr) int64 MaaControllerPostScroll func(ctrl uintptr, dx, dy int32) int64 MaaControllerPostInactive func(ctrl uintptr) int64 MaaControllerPostShell func(ctrl uintptr, cmd string, timeout int64) int64 MaaControllerGetShellOutput func(ctrl uintptr, buffer uintptr) bool MaaControllerStatus func(ctrl uintptr, id int64) int32 MaaControllerWait func(ctrl uintptr, id int64) int32 MaaControllerConnected func(ctrl uintptr) bool MaaControllerCachedImage func(ctrl uintptr, buffer uintptr) bool MaaControllerGetUuid func(ctrl uintptr, buffer uintptr) bool MaaControllerGetResolution func(ctrl uintptr, width, height *int32) bool MaaControllerGetInfo func(ctrl uintptr, buffer uintptr) bool )
MaaController API bindings (MaaController.h). The Create functions build the platform controllers: adb, PlayCover (macOS), Win32, Linux, custom callback, gamepad (Windows), macOS native, and Android native, plus a record wrapper that logs operations to a JSONL file and a replay wrapper that replays one; MaaControllerDestroy releases the handle. Post* functions post operations asynchronously and return a control id that MaaControllerStatus and MaaControllerWait accept, and MaaControllerPostShell takes its timeout in milliseconds. GetShellOutput, CachedImage, GetUuid, and GetInfo write into caller-created buffers, and GetResolution writes the raw device resolution through its width and height pointers.
var ( MaaContextRunTask func(context uintptr, entry, pipelineOverride string) int64 MaaContextRunRecognition func(context uintptr, entry, pipelineOverride string, image uintptr) int64 MaaContextRunAction func(context uintptr, entry, pipelineOverride string, box uintptr, recoDetail string) int64 MaaContextRunRecognitionDirect func(context uintptr, recoType, recoParam string, image uintptr) int64 MaaContextRunActionDirect func(context uintptr, actionType, actionParam string, box uintptr, recoDetail string) int64 MaaContextWaitFreezes func(context uintptr, time uint64, box uintptr, waitFreezesParam string) bool MaaContextOverridePipeline func(context uintptr, pipelineOverride string) bool MaaContextOverrideNext func(context uintptr, nodeName string, nextList uintptr) bool MaaContextOverrideImage func(context uintptr, imageName string, image uintptr) bool MaaContextGetNodeData func(context uintptr, nodeName string, buffer uintptr) bool MaaContextGetTaskId func(context uintptr) int64 MaaContextGetTasker func(context uintptr) uintptr MaaContextClone func(context uintptr) uintptr MaaContextSetAnchor func(context uintptr, anchorName, nodeName string) bool MaaContextGetAnchor func(context uintptr, anchorName string, buffer uintptr) bool MaaContextGetHitCount func(context uintptr, nodeName string, count *uint64) bool MaaContextClearHitCount func(context uintptr, nodeName string) bool )
MaaContext API bindings (MaaContext.h). Context handles are supplied to custom recognition and action callbacks and run nested pipeline work: RunTask, RunRecognition, and RunAction return the corresponding task, recognition, or action id, while RunRecognitionDirect and RunActionDirect run by type and parameters without a pipeline entry. MaaContextWaitFreezes waits until the box region stops changing for the given time; Override* functions adjust pipeline and node data for the running task, and the remaining functions query task and tasker state, clone the context, and manage node anchors and hit counters.
var ( MaaStringBufferCreate func() uintptr MaaStringBufferDestroy func(handle uintptr) MaaStringBufferIsEmpty func(handle uintptr) bool MaaStringBufferClear func(handle uintptr) bool MaaStringBufferGet func(handle uintptr) unsafe.Pointer MaaStringBufferSize func(handle uintptr) uint64 MaaStringBufferSet func(handle uintptr, str string) bool MaaStringBufferSetEx func(handle uintptr, str string, size uint64) bool MaaStringListBufferCreate func() uintptr MaaStringListBufferDestroy func(handle uintptr) MaaStringListBufferIsEmpty func(handle uintptr) bool MaaStringListBufferSize func(handle uintptr) uint64 MaaStringListBufferAt func(handle uintptr, index uint64) uintptr MaaStringListBufferAppend func(handle uintptr, value uintptr) bool MaaStringListBufferRemove func(handle uintptr, index uint64) bool MaaStringListBufferClear func(handle uintptr) bool MaaImageBufferCreate func() uintptr MaaImageBufferDestroy func(handle uintptr) MaaImageBufferIsEmpty func(handle uintptr) bool MaaImageBufferClear func(handle uintptr) bool MaaImageBufferGetRawData func(handle uintptr) unsafe.Pointer MaaImageBufferWidth func(handle uintptr) int32 MaaImageBufferHeight func(handle uintptr) int32 MaaImageBufferChannels func(handle uintptr) int32 MaaImageBufferType func(handle uintptr) int32 MaaImageBufferSetRawData func(handle uintptr, data unsafe.Pointer, width, height, imageType int32) bool MaaImageBufferResize func(handle uintptr, width, height int32) bool MaaImageListBufferCreate func() uintptr MaaImageListBufferDestroy func(handle uintptr) MaaImageListBufferIsEmpty func(handle uintptr) bool MaaImageListBufferSize func(handle uintptr) uint64 MaaImageListBufferAt func(handle uintptr, index uint64) uintptr MaaImageListBufferAppend func(handle uintptr, value uintptr) bool MaaImageListBufferRemove func(handle uintptr, index uint64) bool MaaImageListBufferClear func(handle uintptr) bool MaaRectCreate func() uintptr MaaRectDestroy func(handle uintptr) MaaRectGetX func(handle uintptr) int32 MaaRectGetY func(handle uintptr) int32 MaaRectGetW func(handle uintptr) int32 MaaRectGetH func(handle uintptr) int32 MaaRectSet func(handle uintptr, x, y, w, h int32) bool )
Buffer bindings (MaaBuffer.h). Each buffer is created with its Create function, released with its Destroy function, and passed by handle to other framework functions that produce string, image, or geometry results. MaaStringBufferGet returns borrowed storage valid until the buffer is modified or destroyed; MaaStringBufferSize gives its byte length. The list At functions return a borrowed element view that must not be destroyed, while Append copies the element value with an independent buffer lifetime. Appended image elements may share pixel storage with the source image.
var ( MaaGlobalSetOption func(key MaaGlobalOption, value unsafe.Pointer, valSize uint64) bool MaaGlobalLoadPlugin func(path string) bool )
Global functions (MaaGlobal.h). MaaGlobalSetOption reads the option from the value buffer of valSize bytes. MaaGlobalLoadPlugin loads a plugin from a full library path, by name searched in the system and current directories, or from a directory searched recursively.
var ( MaaToolkitAdbDeviceListCreate func() uintptr MaaToolkitAdbDeviceListDestroy func(handle uintptr) MaaToolkitAdbDeviceFind func(buffer uintptr) bool MaaToolkitAdbDeviceFindSpecified func(adbPath string, buffer uintptr) bool MaaToolkitAdbDeviceListSize func(list uintptr) uint64 MaaToolkitAdbDeviceListAt func(list uintptr, index uint64) uintptr MaaToolkitAdbDeviceGetName func(device uintptr) string MaaToolkitAdbDeviceGetAdbPath func(device uintptr) string MaaToolkitAdbDeviceGetAddress func(device uintptr) string MaaToolkitAdbDeviceGetScreencapMethods func(device uintptr) uint64 MaaToolkitAdbDeviceGetInputMethods func(device uintptr) uint64 MaaToolkitAdbDeviceGetConfig func(device uintptr) string )
ADB device discovery functions. MaaToolkitAdbDeviceListCreate creates an empty device list and MaaToolkitAdbDeviceListDestroy frees it; the Find functions fill the list buffer with the discovered devices, scanning all known emulators plus the adb executable from PATH, or restricting discovery to the given adbPath. MaaToolkitAdbDeviceListSize returns the number of devices and MaaToolkitAdbDeviceListAt the device at index, a pointer borrowed from the list that stays valid until the list is destroyed or modified by another Find call. The Get accessors report that device's fields: a human-readable name, the adb path used to query it, the adb serial as address, the supported screencap and input method bitmasks, and the JSON config object that discovery generated for the device.
var ( MaaToolkitDesktopWindowListCreate func() uintptr MaaToolkitDesktopWindowListDestroy func(handle uintptr) MaaToolkitDesktopWindowFindAll func(buffer uintptr) bool MaaToolkitDesktopWindowListSize func(list uintptr) uint64 MaaToolkitDesktopWindowListAt func(list uintptr, index uint64) uintptr MaaToolkitDesktopWindowGetHandle func(window uintptr) unsafe.Pointer MaaToolkitDesktopWindowGetClassName func(window uintptr) string MaaToolkitDesktopWindowGetWindowName func(window uintptr) string )
Desktop window discovery functions. MaaToolkitDesktopWindowListCreate creates an empty window list and MaaToolkitDesktopWindowListDestroy frees it; MaaToolkitDesktopWindowFindAll fills the list buffer with the windows found, and MaaToolkitDesktopWindowListSize and MaaToolkitDesktopWindowListAt read the list contents. The Get accessors report a window's platform-specific fields: GetHandle returns the raw window handle (a Win32 HWND, or on macOS a CGWindowID force-cast to a pointer, never an NSWindow pointer), GetClassName the Win32 window class name or the macOS bundle identifier, and GetWindowName the window title.
var ( MaaToolkitGamescopeInstanceListCreate func() uintptr MaaToolkitGamescopeInstanceListDestroy func(handle uintptr) MaaToolkitGamescopeInstanceFindAll func(buffer uintptr) bool MaaToolkitGamescopeInstanceListSize func(list uintptr) uint64 MaaToolkitGamescopeInstanceListAt func(list uintptr, index uint64) uintptr MaaToolkitGamescopeInstanceGetDisplayNo func(instance uintptr) uint32 MaaToolkitGamescopeInstanceGetPipeWireNodeId func(instance uintptr) uint32 MaaToolkitGamescopeInstanceGetEisSocketPath func(instance uintptr) string )
Gamescope instance discovery functions. MaaToolkitGamescopeInstanceListCreate creates an empty instance list and MaaToolkitGamescopeInstanceListDestroy frees it; MaaToolkitGamescopeInstanceFindAll fills the list buffer with the running gamescope instances ordered by display number, and MaaToolkitGamescopeInstanceListSize and MaaToolkitGamescopeInstanceListAt read the list contents. The Get accessors report an instance's display number, the PipeWire node ID of its capture stream, and the EIS socket path used to inject input events via libei; a zero node ID or an empty socket path means that endpoint is unavailable.
var ( MaaToolkitPortalHelperCreate func() uintptr MaaToolkitPortalHelperDestroy func(helper uintptr) MaaToolkitPortalHelperOpenStream func(helper uintptr) bool MaaToolkitPortalHelperGetPersist func(helper uintptr) bool MaaToolkitPortalHelperSetPersist func(helper uintptr, enable bool) MaaToolkitPortalHelperGetPipeWireFD func(helper uintptr) int32 MaaToolkitPortalHelperGetPipeWireNodeID func(helper uintptr) uint32 MaaToolkitPortalHelperGetRestoreToken func(helper uintptr) string MaaToolkitPortalHelperSetRestoreToken func(helper uintptr, token string) )
xdg-desktop-portal ScreenCast session functions (Linux portal screencap). MaaToolkitPortalHelperCreate creates a helper and MaaToolkitPortalHelperDestroy closes the session and frees it, but does not close the PipeWire file descriptor handed out by the helper. MaaToolkitPortalHelperOpenStream runs the ScreenCast portal flow (create session, select sources, start stream) and connects to the PipeWire remote. GetPersist and SetPersist control whether the session can persist: with persist enabled the portal returns a restore token on start, which GetRestoreToken reports and SetRestoreToken accepts before OpenStream to resume a previous session. GetPipeWireFD returns the PipeWire socket file descriptor, negative while no stream is open, and GetPipeWireNodeID the stream node ID.
var ( MaaToolkitMacOSCheckPermission func(perm MaaMacOSPermission) bool MaaToolkitMacOSRequestPermission func(perm MaaMacOSPermission) bool MaaToolkitMacOSRevealPermissionSettings func(perm MaaMacOSPermission) bool )
macOS permission functions taking a MaaMacOSPermission value. They are only effective on macOS; on other platforms they log and return false. CheckPermission reports whether the permission is granted; RequestPermission shows the system prompt and reports whether the permission is granted now, without waiting for the user's response; RevealPermissionSettings opens the System Settings page for the permission.
var MaaToolkitConfigInitOption func(userPath, defaultJson string) bool
MaaToolkitConfigInitOption initializes the toolkit option file under userPath, creating it from the JSON object defaultJson when it does not exist yet, and applies the loaded options to the global framework configuration. It reports false when defaultJson is not valid option JSON or the file cannot be written or loaded.
var (
MaaVersion func() string
)
MaaVersion returns the version string of the loaded MaaFramework library.
Functions ¶
func Initialize ¶
Initialize loads all mandatory MaaFramework dynamic libraries from libDir and resolves their symbols. A nonempty libDir is treated as an explicit directory and resolved to an absolute path before any library filename is formed; an empty libDir uses the platform loader's current search configuration. If any library fails to open, is missing a required symbol, or cannot be registered, every library opened during this call is rolled back and the returned error describes the failure. After a complete successful load, repeated calls are a no-op success until Shutdown runs.
On Windows, applying a nonempty directory calls SetDllDirectoryW for the whole process. Once that call succeeds, neither Shutdown nor initialization failure rollback restores the previous DLL search configuration. It remains in effect until process exit or another DLL search configuration change. A later empty-directory initialization leaves it unchanged; a nonempty one can replace it. For unpackaged, unprotected Win32 processes, the change can also affect subsequently started child processes.
func Shutdown ¶
func Shutdown() error
Shutdown closes every successfully opened library in reverse load order and clears its handle and function variables. Libraries whose close fails are kept so a later Shutdown can retry them. Any complete-initialization state is invalidated up front so a partial unload cannot leave Initialize looking finished. On Windows, the process's DLL search configuration is not restored.
Types ¶
type Entry ¶
type Entry struct {
// contains filtered or unexported fields
}
Entry binds a package-level function variable to the C symbol name that must be resolved from a loaded library.
type Library ¶
type Library struct {
// contains filtered or unexported fields
}
Library describes one mandatory dynamic library that is loaded during initialization.
type LibraryLoadError ¶
type LibraryLoadError struct {
// LibraryName is the name of the library that failed to load (e.g., "MaaFramework", "MaaToolkit").
LibraryName string
// LibraryPath is the full path to the library file that was attempted to load.
LibraryPath string
// Err is the underlying error from the system's library loading mechanism.
Err error
}
LibraryLoadError represents an error that occurs when loading a dynamic library.
func (*LibraryLoadError) Error ¶
func (e *LibraryLoadError) Error() string
Error implements the error interface.
func (*LibraryLoadError) Unwrap ¶
func (e *LibraryLoadError) Unwrap() error
Unwrap returns the underlying error from the system's library loading mechanism.
type MaaCtrlOption ¶
type MaaCtrlOption int32
MaaCtrlOption is a controller option key passed to MaaControllerSetOption.
const ( MaaCtrlOption_Invalid MaaCtrlOption = 0 // MaaCtrlOption_ScreenshotTargetLongSide specifies that only the long side can be set, and the short side // is automatically scaled according to the aspect ratio. // value: int, eg: 1280; val_size: sizeof(int) MaaCtrlOption_ScreenshotTargetLongSide MaaCtrlOption = 1 // MaaCtrlOption_ScreenshotTargetShortSide specifies that only the short side can be set, and the long side // is automatically scaled according to the aspect ratio. // value: int, eg: 720; val_size: sizeof(int) MaaCtrlOption_ScreenshotTargetShortSide MaaCtrlOption = 2 // MaaCtrlOption_ScreenshotUseRawSize specifies that the screenshot uses the raw size without scaling. // Note that this option may cause incorrect coordinates on user devices with different resolutions if scaling is not performed. // value: bool, eg: true; val_size: sizeof(bool) MaaCtrlOption_ScreenshotUseRawSize MaaCtrlOption = 3 // MaaCtrlOption_MouseLockFollow enables or disables mouse-lock-follow mode for Win32 controllers. // This is designed for TPS/FPS games that lock the mouse to their window in the background. // Only valid for Win32 controllers using message-based input methods. // // value: bool, eg: true; val_size: sizeof(bool) MaaCtrlOption_MouseLockFollow MaaCtrlOption = 4 // MaaCtrlOption_ScreenshotResizeMethod sets the interpolation method used when resizing screenshots. // Value corresponds to cv::InterpolationFlags: // INTER_NEAREST=0, INTER_LINEAR=1, INTER_CUBIC=2, INTER_AREA=3, INTER_LANCZOS4=4 // Default is INTER_AREA (3). // // value: int, eg: 3; val_size: sizeof(int) MaaCtrlOption_ScreenshotResizeMethod MaaCtrlOption = 6 // MaaCtrlOption_BackgroundManagedKeys sets managed Win32 virtual-key codes. // Set before connecting. value: int32_t array; val_size: sizeof(int32_t) * count. MaaCtrlOption_BackgroundManagedKeys MaaCtrlOption = 7 // MaaCtrlOption_ScreenshotTargetExpand scales screenshots uniformly to cover a reference size. // Mutually exclusive with long-side and short-side targets; ignored when raw size is enabled. // value: int32_t[2] = {width, height}; val_size: sizeof(int32_t) * 2 MaaCtrlOption_ScreenshotTargetExpand MaaCtrlOption = 8 )
Controller option values for MaaControllerSetOption. Upstream value 5 (MaaCtrlOption_Recording) is omitted because it is commented out as deprecated in MaaDef.h.
type MaaCustomActionCallback ¶
type MaaCustomActionCallback func(context uintptr, taskId int64, currentTaskName, customActionName, customActionParam *byte, recoId int64, box, transArg uintptr) uintptr
MaaCustomActionCallback is the Go form of the C custom action callback registered through MaaResourceRegisterCustomAction. It gets the context, task id, node name, action name and parameters, the recognition id, the recognition box, and trans_arg; return non-zero to report success.
type MaaCustomRecognitionCallback ¶
type MaaCustomRecognitionCallback func(context uintptr, taskId int64, currentTaskName, customRecognitionName, customRecognitionParam *byte, image, roi, transArg, outBox, outDetail uintptr) uintptr
MaaCustomRecognitionCallback is the Go form of the C custom recognition callback registered through MaaResourceRegisterCustomRecognition. It gets the context, task id, node name, recognition name and parameters, image, roi, and trans_arg; return non-zero on a hit, writing outBox and outDetail.
type MaaEventCallback ¶
MaaEventCallback is the Go form of the C MaaEventCallback function pointer. handle is the event source handle: a MaaTasker, MaaResource, MaaController, or MaaContext; message and detailsJson point to NUL-terminated UTF-8 strings, and transArg receives the trans_arg value passed at registration.
type MaaGamepadType ¶
type MaaGamepadType uint64
MaaGamepadType is a virtual gamepad type for MaaGamepadControllerCreate; select one type only.
const ( MaaGamepadType_Xbox360 MaaGamepadType = 0 MaaGamepadType_DualShock4 MaaGamepadType = 1 )
Virtual gamepad type values for MaaGamepadControllerCreate.
type MaaGlobalOption ¶
type MaaGlobalOption int32
MaaGlobalOption is a global option key passed to MaaGlobalSetOption.
const ( MaaGlobalOption_Invalid MaaGlobalOption = 0 // MaaGlobalOption_LogDir Log dir // // value: string, eg: "C:\\Users\\Administrator\\Desktop\\log"; val_size: string length MaaGlobalOption_LogDir MaaGlobalOption = 1 // MaaGlobalOption_SaveDraw Whether to save draw // // value: bool, eg: true; val_size: sizeof(bool) MaaGlobalOption_SaveDraw MaaGlobalOption = 2 // MaaGlobalOption_StdoutLevel The level of log output to stdout // // value: MaaLoggingLevel, val_size: sizeof(MaaLoggingLevel) // default value is MaaLoggingLevel_Error MaaGlobalOption_StdoutLevel MaaGlobalOption = 4 // MaaGlobalOption_DebugMode Whether to debug // // value: bool, eg: true; val_size: sizeof(bool) MaaGlobalOption_DebugMode MaaGlobalOption = 6 // MaaGlobalOption_SaveOnError Whether to save screenshot on error // // value: bool, eg: true; val_size: sizeof(bool) MaaGlobalOption_SaveOnError MaaGlobalOption = 7 // MaaGlobalOption_DrawQuality Image quality for draw images // // value: int, eg: 85; val_size: sizeof(int) // default value is 85, range: [0, 100] MaaGlobalOption_DrawQuality MaaGlobalOption = 8 // MaaGlobalOption_RecoImageCacheLimit Recognition image cache limit // // value: size_t, eg: 4096; val_size: sizeof(size_t) // default value is 4096 MaaGlobalOption_RecoImageCacheLimit MaaGlobalOption = 9 )
Global option values for MaaGlobalSetOption. Upstream values 3 (MaaGlobalOption_Recording) and 5 (MaaGlobalOption_ShowHitDraw) are omitted because they are commented out as deprecated in MaaDef.h.
type MaaInferenceDevice ¶
type MaaInferenceDevice int32
MaaInferenceDevice is an inference device selector used with MaaResOption_InferenceDevice: a GPU id (0, 1, ...) or a negative constant.
const ( MaaInferenceDevice_CPU MaaInferenceDevice = -2 MaaInferenceDevice_Auto MaaInferenceDevice = -1 MaaInferenceDevice_0 MaaInferenceDevice = 0 MaaInferenceDevice_1 MaaInferenceDevice = 1 )
Inference device values for MaaResOption_InferenceDevice.
type MaaInferenceExecutionProvider ¶
type MaaInferenceExecutionProvider int32
MaaInferenceExecutionProvider is an execution provider selector used with MaaResOption_InferenceExecutionProvider.
type MaaMacOSInputMethod ¶
type MaaMacOSInputMethod uint64
MaaMacOSInputMethod defines the macOS input method. Select ONE method only.
const ( MaaMacOSInputMethod_None MaaMacOSInputMethod = 0 MaaMacOSInputMethod_GlobalEvent MaaMacOSInputMethod = 1 MaaMacOSInputMethod_PostToPid MaaMacOSInputMethod = 1 << 1 )
macOS input method values for MaaMacOSControllerCreate.
type MaaMacOSPermission ¶
type MaaMacOSPermission int32
MaaMacOSPermission defines the macOS permission type.
const ( MaaMacOSPermissionScreenCapture MaaMacOSPermission = 1 MaaMacOSPermissionAccessibility MaaMacOSPermission = 2 )
MaaMacOSPermission values consumed by the MaaToolkitMacOS* permission functions: screen capture and accessibility.
type MaaMacOSScreencapMethod ¶
type MaaMacOSScreencapMethod uint64
MaaMacOSScreencapMethod defines the macOS screencap method. Select ONE method only.
const ( MaaMacOSScreencapMethod_None MaaMacOSScreencapMethod = 0 MaaMacOSScreencapMethod_ScreenCaptureKit MaaMacOSScreencapMethod = 1 )
macOS screencap method values for MaaMacOSControllerCreate.
type MaaResOption ¶
type MaaResOption int32
MaaResOption is a resource option key passed to MaaResourceSetOption.
const ( MaaResOption_Invalid MaaResOption = 0 // MaaResOption_InferenceDevice uses the specified inference device. Set it // before loading the model. // value: MaaInferenceDevice, eg: 0; val_size: sizeof(MaaInferenceDevice) // default value is MaaInferenceDevice_Auto MaaResOption_InferenceDevice MaaResOption = 1 // MaaResOption_InferenceExecutionProvider uses the specified inference // execution provider. Set it before loading the model. // value: MaaInferenceExecutionProvider, eg: 0; val_size: sizeof(MaaInferenceExecutionProvider) // default value is MaaInferenceExecutionProvider_Auto MaaResOption_InferenceExecutionProvider MaaResOption = 2 )
Resource option values for MaaResourceSetOption.
type MaaTaskerOption ¶
type MaaTaskerOption int32
MaaTaskerOption is a tasker option key passed to MaaTaskerSetOption. Upstream currently defines only MaaTaskerOption_Invalid.
const MaaTaskerOption_Invalid MaaTaskerOption = 0
MaaTaskerOption_Invalid is the reserved invalid tasker option.
type SymbolLookupError ¶
type SymbolLookupError struct {
// LibraryName is the name of the library missing the symbol (e.g., "MaaFramework").
LibraryName string
// LibraryPath is the full path to the library file that was opened.
LibraryPath string
// SymbolName is the name of the symbol that could not be resolved.
SymbolName string
// Requirement describes the version expectation for the missing symbol.
// This binding targets the latest matching MaaFramework release, including
// prereleases, and does not claim a fixed minimum stable version.
Requirement string
// Err is the underlying error from the platform symbol lookup.
Err error
}
SymbolLookupError represents an error that occurs when a required symbol is missing from a dynamic library that opened successfully. It reports which library and symbol failed, the path that was opened, the version expectation of this binding, and the underlying platform lookup error.
func (*SymbolLookupError) Error ¶
func (e *SymbolLookupError) Error() string
Error implements the error interface.
func (*SymbolLookupError) Unwrap ¶
func (e *SymbolLookupError) Unwrap() error
Unwrap returns the underlying error from the platform symbol lookup.