GameController framework

Example show how you could get values() from Game Controller in ASObjC
Everything should work, but not sure how touchPad works. The test have been done for Playstation DualSense Controller.

You need to have Game Controller that is supported in Monterey,
The connection could be Bluetooth or USB.

Press any button or move any analog stick on the controller and hold, run the script.

use framework "GameController"

set controllers to (current application's GCController's controllers())'s firstObject()
set inputProfile to controllers's physicalInputProfile()

set buttonHomeState to (inputProfile's valueForKey:"buttonHome")'s value()
log "buttonHome: " & buttonHomeState as anything
set buttonMenuState to (inputProfile's valueForKey:"buttonMenu")'s value()
log "buttonMenu: " & buttonMenuState
set buttonOptionsState to (inputProfile's valueForKey:"buttonOptions")'s value()
log "buttonOptions: " & buttonOptionsState

-- Buttons right
set buttonCrossState to (inputProfile's valueForKey:"buttonA")'s value()
log "buttonA: " & buttonCrossState
set buttonCircleState to (inputProfile's valueForKey:"buttonB")'s value()
log "buttonB: " & buttonCircleState
set buttonSquareState to (inputProfile's valueForKey:"buttonX")'s value()
log "buttonX: " & buttonSquareState
set buttonTriangleState to (inputProfile's valueForKey:"buttonY")'s value()
log "buttonY: " & buttonTriangleState

-- Buttons left (Direction Pad)
set directionPadDownState to (inputProfile's dpad()'s valueForKey:"down")'s value()
log "dpad-down: " & directionPadDownState
set directionPadLeftState to (inputProfile's dpad()'s valueForKey:"left")'s value()
log "dpad-left: " & directionPadLeftState
set directionPadRightState to (inputProfile's dpad()'s valueForKey:"right")'s value()
log "dpad-right: " & directionPadRightState
set directionPadUpState to (inputProfile's dpad()'s valueForKey:"up")'s value()
log "dpad-up: " & directionPadUpState

-- Left thumbstick
set leftShoulderState to (inputProfile's leftShoulder())'s value() --> L1
log "leftShoulder: " & leftShoulderState
set leftThumbstickButtonState to (inputProfile's leftThumbstickButton())'s value()
log "leftThumbstickButton: " & leftThumbstickButtonState

set leftThumbstickDownState to (inputProfile's leftThumbstick()'s valueForKey:"down")'s value()
log "leftThumbstick-down: " & leftThumbstickDownState
set leftThumbstickLeftState to (inputProfile's leftThumbstick()'s valueForKey:"left")'s value()
log "leftThumbstick-left: " & leftThumbstickLeftState
set leftThumbstickRightState to (inputProfile's leftThumbstick()'s valueForKey:"right")'s value()
log "leftThumbstick-right: " & leftThumbstickRightState
set leftThumbstickUpState to (inputProfile's leftThumbstick()'s valueForKey:"up")'s value()
log "leftThumbstick-up: " & leftThumbstickUpState
set leftTriggerState to (inputProfile's valueForKey:"leftTrigger")'s value() --> L2
log "leftTrigger: " & leftTriggerState

-- Right thumbstick
set rightShoulderState to (inputProfile's rightShoulder())'s value() --> R1
log "rightShoulder: " & rightShoulderState
set rightThumbstickButtonState to (inputProfile's rightThumbstickButton())'s value()
log "rightThumbstickButton: " & rightThumbstickButtonState

set rightThumbstickDownState to (inputProfile's rightThumbstick()'s valueForKey:"down")'s value()
log "rightThumbstick-down: " & rightThumbstickDownState
set rightThumbstickLeftState to (inputProfile's rightThumbstick()'s valueForKey:"left")'s value()
log "rightThumbstick-left: " & rightThumbstickLeftState
set rightThumbstickRightState to (inputProfile's rightThumbstick()'s valueForKey:"right")'s value()
log "rightThumbstick-right: " & rightThumbstickRightState
set rightThumbstickUpState to (inputProfile's rightThumbstick()'s valueForKey:"up")'s value()
log "rightThumbstick-up: " & rightThumbstickUpState
set rightTriggerState to (inputProfile's valueForKey:"rightTrigger")'s value() --> R2
log "rightTrigger: " & rightTriggerState

-- TouchPad
set touchpad1Down to (inputProfile's touchpadPrimary()'s valueForKey:"down")'s value()
log "touchpadPrimary-down: " & touchpad1Down
set touchpad1Left to (inputProfile's touchpadPrimary()'s valueForKey:"left")'s value()
log "touchpadPrimary-left: " & touchpad1Left
set touchpad1Right to (inputProfile's touchpadPrimary()'s valueForKey:"right")'s value()
log "touchpadPrimary-right: " & touchpad1Right
set touchpad1Up to (inputProfile's touchpadPrimary()'s valueForKey:"up")'s value()
log "touchpadPrimary-up: " & touchpad1Up

set touchpad2Down to (inputProfile's touchpadSecondary()'s valueForKey:"down")'s value()
log "touchpadSecondary-down: " & touchpad2Down
set touchpad2Left to (inputProfile's touchpadSecondary()'s valueForKey:"left")'s value()
log "touchpadSecondary-left: " & touchpad2Left
set touchpad2Right to (inputProfile's touchpadSecondary()'s valueForKey:"right")'s value()
log "touchpadSecondary-right: " & touchpad2Right
set touchpad2Up to (inputProfile's touchpadSecondary()'s valueForKey:"up")'s value()
log "touchpadSecondary-up: " & touchpad2Up

set touchPadButtonState to (inputProfile's valueForKey:"touchpadButton")'s value()
log "touchPadButton: " & touchPadButtonState


(**
* [GCPhysicalInputProfile, elements]
*)
-- log (inputProfile's valueForKey:"elements")'s |description|() as string
-- log (inputProfile's valueForKey:"buttons")'s |description|() as string
-- log (inputProfile's valueForKey:"axes")'s |description|() as string
-- log (inputProfile's valueForKey:"dpads")'s |description|() as string
-- log (inputProfile's valueForKey:"touchpads")'s |description|() as string

-- To get the value of Cross-Button on a Playstation DualSense Controller
-- log (inputProfile's objectForKeyedSubscript:"Button A")'s value()

log ((inputProfile's device())'s valueForKey:"vendorName") as string
log ((inputProfile's device())'s valueForKey:"productCategory") as string
2 Likes

This example use GCMouse class

(**
* [GCMouse]
*)
set inputMouse to current application's GCMouse's mice()'s firstObject()
set inputProfile to inputMouse's valueForKey:"mouseInput"
log (inputProfile's valueForKey:"elements")'s |description|() as string

set leftButton to (inputProfile's valueForKey:"leftButton")'s value()
log "leftButton: " & leftButton
set rightButton to (inputProfile's valueForKey:"rightButton")'s value()
log "rightButton: " & rightButton
set scrollDown to (inputProfile's scroll()'s valueForKey:"down")'s value()
log "scroll-Down: " & scrollDown
set scrollLeft to (inputProfile's scroll()'s valueForKey:"left")'s value()
log "scroll-Left: " & scrollLeft
set scrollRight to (inputProfile's scroll()'s valueForKey:"right")'s value()
log "scroll-Right: " & scrollRight
set scrollUp to (inputProfile's scroll()'s valueForKey:"up")'s value()
log "scroll-Up: " & scrollUp

set scrollXAxis to (inputProfile's scroll()'s valueForKey:"xAxis")'s value()
log "scroll-XAxis: " & scrollXAxis
set scrollYAxis to (inputProfile's scroll()'s valueForKey:"yAxis")'s value()
log "scroll-YAxis: " & scrollYAxis

This example use GCKeyboard class

(**
* [GCKeyboard]
*)
set inputKeyboard to current application's GCKeyboard's coalescedKeyboard()
set inputProfile to inputKeyboard's valueForKey:"keyboardInput"
log (inputProfile's valueForKey:"elements")'s |description|() as string

Its also possible to use valueForKeyPath for some properties, it makes the code more compact.

Old reference from @Nigel about valueForKeyPath, Thanks.

set directionPadDownState to (inputProfile's valueForKeyPath:"dpad.down")'s value()
log "dpad-down: " & directionPadDownState