[SOLVED] How to trigger a button click in code

I piggybacked this on another thread (How to use Back Button Android?) so I figured this should have it’s own thread. Here is the solution on how to trigger a button click in code:

The magic is just the emit() call.

var canvas = cc.find("Canvas");
cc.eventManager.addListener({
	event: cc.EventListener.KEYBOARD,
	onKeyPressed: (code, event) => {
		if (code == cc.KEY.back || code == cc.KEY.backspace || code == cc.KEY.escape) {
			closeButton = cc.find("close-button", canvas);
			closeButton.emit("touchend");
		}
	}
}, canvas);