HTC Touch Diamond Stylus Sensor API


I spent a bit of time figuring out how to determine the stylus on the HTC Touch Diamond. It only took like 5 minutes: it was exactly where I suspected, a registry key that toggled depending on the stylus state. So basically it's really easy to access. I rolled access to this registry key up in the Sensor SDK.

(HKEY_CURRENT_USER\ControlPanel\Keybd\StylusOutStatus for those curious.)

The new HTCStylusSensor has 2 members:


This property is has a value that is either StylusIn or StylusOut.


This event fires whenever the StylusState property changes.

Click here if you want to download the APIs and source to access the G-Sensor, Light Sensor, Nav Sensor, or Stylus Sensor.


I will be releasing an tool shortly that allows users to launch any application, shortcut, sound file, etc, when the stylus is removed from the device.


Spiceworm said...

As a software developper your posts convinced me to buy an HTC touch diamond. ;)

Koush said...

Yeah! They're really fun phones to develop software for. :) Lots of cool gadgets. Let me know what you come up with!

Thomas Hamböck's Blog said...

I just wanted to ask you if you know also sth. about the stylus sensor and then i see that you've made the API for it... cool!

the app you mean is like this:
? (but i'd never spend 7$ for such an app)

what i wanted to ask you... what do you know about the sensor where the keys lighten up when you move over the middle (Enter) button?
is that an proximity sensor?
and how can you let the lights light under the enter button?
(there are 4 unter enter and each of the other 4 buttons has 1 LED)
then we could play simon says with that 4 lights and the 4 navi buttons... lol


Koush said...

Yep, that application is exactly what I mean. I just started working on it a minute ago; I'll be done soon. I also wouldn't pay $15 for something so simple.

harald said...

I did some refactoring of your SDK to have a generic interface and a HTC implementation that is only loaded at runtime. That way one can bind to just one API and the implementation can depend on the platform the app is running on (e.g. the new samsung and sony mobiles).

I sent you a mail about that, but got no feedback so far. What do you think about putting that on sourceforge or such and join efforts?

Koush said...

Yeah, that was the reason I made interfaces for the various sensors: so that different devices can have different implementations, and then at runtime the proper implementation for your device is created, and the interface is returned.
However, I don't know anything about the APIs on the other devices, so I didn't bother writing that code.
I don't mind hosting this on sourceforge. You can contact me on AIM at koushd. Or via email at