Game Controller to execute AppleScript

Update of other Script I made to get some inputs from Game Controller Framework.
I believe the framework use Objective-C block that is not supported in AppleScriptObjC. And I do not know any other way to do it. So I made this little code to demonstrate a function to be able
to execute AppleScript from a Game Controller. I use the idle handler and set the time to 0.5 seconds. The code have been tested on PlayStation DualSense Controller. The handler controllerDidDisconnect:sender is not used.

Ps. The code is saved as stay open applet

use framework "Foundation"
use framework "GameController"
use scripting additions

on idle
	set theController to current application's GCController's controllers()'s firstObject()
	
	current application's GCController's setShouldMonitorBackgroundEvents:true
	
	-- A notification that posts after a controller connects to the device.
	set {notificationName, theSelector} to ¬
		{"GCControllerDidConnectNotification", "controllerDidConnect:"}
	
	set notificationCenter to current application's NSNotificationCenter's defaultCenter()
	notificationCenter's addObserver:me selector:theSelector ¬
		|name|:notificationName object:theController
	
	if theController is not missing value then
		set inputProfile to theController's physicalInputProfile()
		if (inputProfile's valueForKey:"buttonA")'s value() is 1 then
			my performSelector:"pressedChangedHandlerButtonA:" withObject:(missing value) ¬
				afterDelay:0.0
		end if
		if (inputProfile's valueForKey:"buttonB")'s value() is 1 then
			my performSelector:"pressedChangedHandlerButtonB:" withObject:(missing value) ¬
				afterDelay:0.0
		end if
	end if
	-- Set the time for idle handler
	return 0.5
end idle

on pressedChangedHandlerButtonA:sender
	display alert "Button A pressed on controller"
end pressedChangedHandlerButtonA:

on pressedChangedHandlerButtonB:sender
	display alert "Button B pressed on controller"
end pressedChangedHandlerButtonB:

on controllerDidConnect:sender
	-- log "Game Controller Connected..."
	display alert "Game Controller Connected..."
	my (notificationCenter's removeObserver:me ¬
		|name|:notificationName object:theController)
end controllerDidConnect:

on controllerDidDisconnect:sender
	-- log "Game Controller Disconnect..."
	display alert "Game Controller Disconnect..."
	my (notificationCenter's removeObserver:me ¬
		|name|:notificationName object:theController)
end controllerDidDisconnect: