...
The S Pen SDK is, unsurprisingly, the way to control the S Pen.
Consider reading the documentation, which has examples, and an API reference.
http://developer.samsung.com/s-pen-sdk/technical-docs/S-Pen-SDK-2-3-Tutorial
Note that this is being rolled into the Mobile SDK: