This is an application which allows detection of the S Pen detachment even on AOSP/AOKP/CM based ROMs.
It has only been tested on the Note 2 by me. If it works on your note device please let me know so that I can add it to the list of compatible note devices.
The source code can be found here https://github.com/tushar9989/cmspen
Explanation of how it works:
The android system automatically adds event files for each input device it detects when being installed. These event files are located in /dev/input/eventX where X denotes a particular device. These event files can be read using native C code for which I use an API provided by Radu Motisan which can be found here and also a bit more information about the event files can be found there. So now using this interface I find the event file for the S Pen and then continously read it to see if the value of the S Pen sensor has been changed. Whenever it changes I broadcast the corresponding Intent which was broadcasted by Samsung so that any applications which work based on that Intent can work even on these ROMs without having to change any of their code.
An interesting thing is that this feature is already present in CyanogenMod i.e S-Pen Power saving mode which disables the s pen touch decoder when the s pen is inserted. I fail to understand why they are not doing the same thing that I am doing through my application and save all of us the trouble.