Thanks for the quick response, vitor. I think I did what your instructions describe, but the keyboard brightness is not increasing. In fact, I don't think anything happens.
Before trying the Workflow, I set my keyboard brightness to no brightness, then tried to increase brightness using my Hotkey. I entered the Command-1 Hotkey several times. I also tried holding Command-1 down for a long time. Neither works.
Could you look at the attached pictures and the code I'm using to see what might be wrong?
If important, I'm using Ventura 13.3.1 on MBP 16-in 2021.
And here's the code I'm running:
var query = CommandLine.arguments[1]
print(query, terminator: "")import Quartz
let supportedKeys: [String: UInt32] = [
"screen-brightness-up": 2,
"screen-brightness-down": 3,
"keyboard-brightness-up": 21,
"keyboard-brightness-down": 22,
"play-pause": 16,
"fast-forward": 17,
"rewind": 18,
"volume-mute-toggle": 7,
"volume-up": 0,
"volume-down": 1,
]
func pressKey(_ key: UInt32) {
func keyDown(_ down: Bool) {
let flags = NSEvent.ModifierFlags(rawValue: (down ? 0xa00 : 0xb00))
let data1 = Int((key << 16) | (down ? 0xa00 : 0xb00))
let ev = NSEvent.otherEvent(
with: NSEvent.EventType.systemDefined,
location: NSPoint(x: 0, y: 0),
modifierFlags: flags,
timestamp: 0,
windowNumber: 0,
context: nil,
subtype: 8,
data1: data1,
data2: -1
)
let cev = ev?.cgEvent
cev?.post(tap: CGEventTapLocation.cgSessionEventTap)
}
keyDown(true)
keyDown(false)
}
pressKey(supportedKeys[CommandLine.arguments[1]]!)