Code Monkey home page Code Monkey logo

swiftautogui's Introduction

SwiftAutoGUI

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

A library for manipulating macOS with Swift, which is used to programmatically control the mouse & keyboard.

This repository is inspired by pyautogui.

Installation

Swift Package Manager

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"]
    )
    ...
]

CocoaPods

SwiftAutoGUI is available through CocoaPods.

in Podfile add the following:

pod 'SwiftAutoGUI'

Example Usage

If you would like to know more details, please refer to the DocC Style Document.

Keyboard

By calling a method of the SwiftAutoGUI class as shown below, you can send key input commands to macOS. Supported keys are written in Keycode.swift.

As shown in the sample below, you can also input shortcuts, such as moving the virtual desktop by sending the command ctrl + ←.

Currently only US keyboards are supported. Otherwise, it may not work properly.

import SwiftAutoGUI

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

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

Mouse

Similarly, mouse operations can generate basic commands such as mouse movement, clicking, and scrolling by invoking methods of the SwiftAutoGUI class.

import SwiftAutoGUI

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

// Move the mouse to a specific position
// This parameter is the `CGWindow` coordinate.
SwiftAutoGUI.move(to: CGPointMake(0, 0))

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

// Scroll
SwiftAutoGUI.vscroll(clicks: 10) // up
SwiftAutoGUI.vscroll(clicks: -10) // down
SwiftAutoGUI.hscroll(clicks: 10) // left
SwiftAutoGUI.hscroll(clicks: -10) // right

Contributors

License

MIT license. See the LICENSE file for details.

swiftautogui's People

Contributors

nakaokarei avatar

Stargazers

Johannes Jakob avatar  avatar Andrew Olechtchouk avatar Max Shu avatar  avatar Xiaoyu Wang avatar  avatar Abraham Abreu avatar Saumya avatar  avatar Antony Nasce avatar X.app (Developer) avatar Jun Ogino avatar Mark Clayton avatar Kotaro Suto avatar  avatar hiro avatar Shin avatar とんとんぼ avatar  avatar Glenn Sugden avatar Ryu avatar Ren Takahashi avatar Richard Dominick avatar Phillmont Muktar avatar Atsushi Miyaji avatar Euan Traynor avatar  avatar Takahiro Nagai avatar Takao Hayashi avatar banjun avatar M"e avatar nakaji avatar yoki avatar TOMIKAWA Sotaro avatar

Watchers

Mark Clayton avatar  avatar

Forkers

okkann

swiftautogui's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.