Skip to content
This repository has been archived by the owner on Feb 17, 2020. It is now read-only.
/ LightKit Public archive

Ambient Light Sensor, Display, and Keyboard brightness control in Swift.

License

Notifications You must be signed in to change notification settings

maxmouchet/LightKit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LightKit

License CocoaPods compatible Carthage compatible

Access the ambient light sensors, and control MacBook's display & keyboard brightness in Swift.

LightKit

Warning: While it should be safe to play with the backlight, I am not responsible for any damages made to a computer using this code.

Installation

# Podfile
pod "LightKit"

# Cartfile
github "maxmouchet/LightKit"

Usage

import LightKit
let lk = LightKit()! // May be nil if it failed to open I/Os.

Note : Most methods and properties are returning optional as I/Os requests may fail if sensors and controllers could not be found.

Ambient light sensors

let lightSensorsReadings = lk.lightSensors
print("Left sensor: \(lightSensorsReadings?.left).")
print("Right sensor: \(lightSensorsReadings?.right).")

Display

print("Display brightness is \(lk.displayBrightness)")
lk.setDisplayBrightness(0.8) // A value between 0 and 1.
lk.setDisplayPower(false) // Put display to sleep
lk.setDisplayPower(true) // Wake up display

Keyboard

print("Keyboard brightness is \(lk.keyboardBrightness)")
lk.setKeyboardBrightness(0.8) // A value between 0 and 1.