3

Is there a way to programmatically dim a backlit keyboard on a Mac?

David
  • 14,205
  • 20
  • 97
  • 144
  • possible duplicate of [Changing brightness of the Macbook(Pro) keyboard backlight](http://stackoverflow.com/questions/991813/changing-brightness-of-the-macbookpro-keyboard-backlight) – johnsyweb Sep 24 '11 at 07:17
  • What language are you hoping to use? If you're looking for a C variant (objc, c, c++, etc.) then you should follow the links in Johnsyweb's comment. Keep in mind it's a "private" API which means it could change or evaporate at any time. It may also at some point be banned from the Mac App Store, as private API usage is grounds for rejection in the iPhone app store. – Art Taylor Sep 24 '11 at 08:15
  • I just came across a Swift class that does this. It should be simple to convert to Obj-C. https://github.com/CoordinatedHackers/keyboardparty/blob/master/Keyboard%20Party/KeyboardBacklight.swift I didn't write this code, but I've tested it, and it works great. – original_username Apr 07 '15 at 02:41

1 Answers1

-1
UInt64 lightInsideGetLEDBrightness()
{
kern_return_t kr = 0;
IOItemCount   scalarInputCount  = 1;
IOItemCount   scalarOutputCount = 1;
UInt64        in_unknown = 0, out_brightness;
//kr = IOConnectMethodScalarIScalarO(dataPort, kGetLEDBrightnessID,
//                                  scalarInputCount, scalarOutputCount, in_unknown, &out_brightness);
kr = IOConnectCallScalarMethod(dataPort, kGetLEDBrightnessID, &in_unknown, scalarInputCount, &out_brightness, &scalarOutputCount);
return out_brightness;
}

It may help you.

RetVal
  • 107
  • 3
  • 10
  • What frameworks do you need to include? I get `No matching function for call to 'IOConnectCallScalarMethod'` – Arc676 May 05 '14 at 08:59
  • 3
    I believe the snippet above is taken from Amit Singh's bonus online chapter to the book Mac OSX Internals at http://www.osxbook.com/book/bonus/chapter10/light/ and is actually incomplete. If you look at the code there, you'll see what I mean. For `IOConnectCallScalarMethod` you need `IOKitLib.h` and you need to link to `IOKit.framework`. – mike Sep 01 '14 at 08:43