Git Product home page Git Product logo

trackpad-joystick's Introduction

title

demo

Example of how to use MacBook's or Apple Magic Trackpad not for a positioning of the cursor but for getting an absolute coordinates of touches - i.e. as a joystick.

The project (TrackpadJoystick.swift) is combined with a simple example (ViewController.swift) - sending a coordinates over an UDP socket. See wifi-car for the counterpart.

Overview

The idea behind the application is to use a custom view - subclass of NSView - to receive one touch at a time. To emulate a real joystick behavior touches are allowed to begin only from the center of he trackpad - in a circle with stickStartPositionRadius radius. Also, after releasing a finger from the panel the stick is automatically returning to the start position.

Coordinates are retrieving in a real time on every request to the TrackpadJoystick.centeredCoords member.

To prevent distractions in cases when the window is losing focus the app is running itself in a fullscreen mode (use Cmd+Q to exit). Currently, I haven't found a simple way to make an NSView a fully transparent overlay in a fullscreen mode to place other UI elements behind it and not rely on them in the main TrackpadJoystick class. So if you want any additional UI components please put them in this class.

Installation

TrackpadJoystick itself has no dependencies although the example has one - it uses IBM-Swift/BlueSocket as a simple socket framework:

  • Install IBM-Swift/BlueSocket via Carthage (carthage update) and embed them in your build target
  • Turn on network connections (Project settings -> Capabilities -> App Sandbox -> Network)
  • Create and configure your desired UI and outlets in the Interface Builder

Usage

See (ViewController.swift) to see a concept of how to instantiate and use the joystick. In two words, you need to:

// create one
@IBOutlet weak var trackpadJoystick: TrackpadJoystick!
// retrieve coordinates
let c = trackpadJoystick.centeredCoords
print("x = \(c.x), y = \(c.y)")

Centered means that the center of the trackpad is considered an origin point (0.0; 0.0) and the range for both X and Y axes is [-1.0; 1.0]. There are some another initialization and converting methods available through the CenteredCoords interface such as toNormalized(), toScreenCoords().

TODOs

Check for TODOs all over the code to get the insight of what would be great to do.

trackpad-joystick's People

Contributors

ussserrr avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

samson721223

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.