GameControllerKit
GameControllerKit is a Swift package that makes it easy to work with game controllers on iOS, macOS, and tvOS. It provides a simple API to connect to game controllers, read input from them, and control their lights and haptics.
Install / Use
/learn @0xWDG/GameControllerKitREADME
GameControllerKit
GameControllerKit is a Swift package that makes it easy to work with game controllers on iOS, macOS, and tvOS. It provides a simple API to connect to game controllers, read input from them, and control their lights and haptics.
Requirements
- Swift 5.9+ (Xcode 15+)
- iOS 13+, macOS 10.15+, tvOS 16+
Installation (Pakage.swift)
dependencies: [
.package(url: "https://github.com/0xWDG/GameControllerKit.git", branch: "main"),
],
targets: [
.target(name: "MyTarget", dependencies: [
.product(name: "GameControllerKit", package: "GameControllerKit"),
]),
]
Installation (Xcode)
- In Xcode, open your project and navigate to File → Swift Packages → Add Package Dependency...
- Paste the repository URL (
https://github.com/0xWDG/GameControllerKit) and click Next. - Click Finish.
Usage
import SwiftUI
import GameControllerKit
struct ContentView: View {
/// The game controller kit
@State
var gameController = GameControllerKit()
/// Log
@State
var log: [String] = []
var body: some View {
VStack {
Button {
gameController.set(color: .GCKRandom)
} label: {
Text("Random Color")
}
Text("Controller: \(gameController.controller?.productCategory ?? "None"), " +
"\((gameController.controllerType ?? .generic).description)")
Text("Last action:\n\(String(describing: gameController.lastAction)).")
GCKControllerView()
.environmentObject(gameController)
List {
ForEach(log.reversed(), id: \.self) { text in
Text(text)
}
}
}
.padding()
.onAppear {
gameController.set(handler: handler)
UIApplication.shared.isIdleTimerDisabled = true
}
}
/// Handler
///
/// - Parameters:
/// - action: action
/// - pressed: is the button pressed?
/// - controller: which controller?
public func handler(
action: GCKAction,
pressed: Bool,
controller: GCKController
) {
log.append(
"\(String(describing: action))(\(action.position.arrowRepresentation)) \(pressed ? "Pressed" : "Unpressed"), " +
"Controller #id \(String(describing: controller.playerIndex.rawValue))"
)
if action == .buttonA && pressed {
// set to a random color
gameController.set(color: .GCKRandom)
}
}
}
Image of Usage Demo App
iOS
MacOS
<img width="1012" alt="AA801C52-88A1-4326-A5DC-3A04DF491077" src="https://github.com/user-attachments/assets/f6eaa752-fdda-4ddd-8eeb-acbc9797dc94">tvOS
Mentions
- Touch-free Touch Screens by Rob Whitaker
https://appdevcon.nl/session/touch-free-touch-screens/ @ AppDevCon 2025
https://www.youtube.com/watch?v=bHPMuVyjBYw @ iOSKonf25
Contact
🦋 @0xWDG 🐘 mastodon.social/@0xWDG 🐦 @0xWDG 🧵 @0xWDG 🌐 wesleydegroot.nl 🤖 Discord
Interested learning more about Swift? Check out my blog.
Related Skills
node-connect
333.7kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
82.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
333.7kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
82.0kCommit, push, and open a PR
