SwiftAutoGUI

SPM is supported Github issues Github forks Github stars Github top language Github license

Used to programmatically control the mouse & keyboard. A library for manipulating macOS with Swift.

This repository is implemented with reference to pyautogui.

Installation

SwiftAutoGUI is available through Swift Package Manager.

in Package.swift add the following:

dependencies: [
    // Dependencies declare other packages that this package depends on.
    .package(url: "https://github.com/NakaokaRei/SwiftAutoGUI", branch: "master")
],
targets: [
    .target(
        name: "MyProject",
        dependencies: [..., "SwiftAutoGUI"]
    )
    ...
]

Example Usage

Keyboard and Mouse Control

See Keycode.swift for supported keys. If it is not a US keyboard, This may not work properly.

import SwiftAutoGUI

// Send ctrl + ←
SwiftAutoGUI.sendKeyShortcut([.control, .leftArrow])

// Send sound up
SwiftAutoGUI.keyDown(.soundUp)
SwiftAutoGUI.keyUp(.soundUp)

// Move mouse by dx, dy from the current location
SwiftAutoGUI.moveMouse(dx: 10, dy: 10)

// Click where the mouse is located
SwiftAutoGUI.leftClick()

Contributors

License

MIT license. See the LICENSE file for details.

GitHub

View Github