Can you provide the API in C#

Can you provide the API in C#


I am working in C# XNA, I would like to know how the get the accelerometer data, the touch collection and the context data (Tablet or laptop mode) in C#.

Thank you!

7 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Great question and I don't know the answer to it, but I'm contacting our Application Engineers (the SW developers that that work with game companies) for how you'd do it.


While I haven't tried it, I think that the Microsoft.Devices.Sensors namespace will give you access to the accelerometer. There are a variety of touch namespaces, depending what you want to do (touch events vs. gestures, single touch vs. multitouch, etc.), with probably the most basic in System.Windows.Input.Touch. Even more simply, basic touch events will arrive as mouse events, so for some kinds of touch input you may already have support without writing a line of code. The GetSystemMetrics() call can tell your app if the system is in tablet mode or not (with SM_CONVERTIBLESLATEMODE as input), but I'm not sure if you have direct access to that call with your version of XNA/.NET. Can you tell us a little more about what you're trying to do and what environment you're in?

Thank you for your answer.

I am using Visual C# Express 2010, with XNA 4.0. I am doing a physics puzzle game. I manged to get multitouch working. 

The things I am missing are:

* To prevent the 2 in 1 to change the display orientation of the display when turned.

* Getting the turning state "accelerometer" so I can change the gravity (can be in jumps of 90 degrees).

* Getting the context of the 2 in 1.

Anyway the XNA Framework is not supported in windows 8 but the game is in XNA.

Hi Kobi,

I wanted to add a few things to this that could help you out.  I wrote a little blurb on how to prevent the auto-rotation in windows 8.  Here is a link to that article.

You will have to be careful when testing for tablet versus clamshell mode.  The problem is that not every hardware manufacturer built their devices with support for the GetSystemMetrics() call that Paul mentioned.  If you happen to have a system that doesn't support it and you make that call it will erroneously tell you that you are in tablet mode.  You could check on this message in your message pump WM_SETTINGCHANGE (article).  That will help you trap the correct case on devices that do support 2:1 properly.

I hope that helps.


Your response was very helpful but can you help me translate the auto rotation code in the article to C#.

Tnx, Kobi

Hi Kobi,

Here is C# code to do what you need.  You'll need to redefine the enum but here you go.  enjoy!


ORIENTATION_PREFERENCE_NONE              = 0x0,   





    public static extern bool SetDisplayAutoRotationPreferences( ORIENTATION_PREFERENCE pref );



Leave a Comment

Please sign in to add a comment. Not a member? Join today