BigPete
BigPete

Reputation: 778

wp7 Haptic Feedback

Where could I find documentation on how to implement haptic feedback for windows phone 7? I want the phone to give short vibrations when a button is pressed.

Upvotes: 13

Views: 2301

Answers (3)

Evan Larsen
Evan Larsen

Reputation: 9965

I created a vibration class for my buttons so that its easy to call. Here is my code. Please give me +1 if you like.

public class Vibration
    {
        public static void VibrateOnButtonPress()
        {
            Microsoft.Devices.VibrateController.Default.Start(TimeSpan.FromMilliseconds(50));
            System.Windows.Threading.DispatcherTimer timer = new System.Windows.Threading.DispatcherTimer();
            timer.Interval = new TimeSpan(0, 0, 0, 0, 200);
            timer.Tick += (tsender, tevt) =>
            {
                var t = tsender as System.Windows.Threading.DispatcherTimer;
                t.Stop();
                Microsoft.Devices.VibrateController.Default.Stop();
            };
            timer.Start();
        }
    }

Upvotes: 5

Joel Martinez
Joel Martinez

Reputation: 47809

Perhaps you can use the XNA API to set the vibration of the "GamePad"
http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.gamepad.setvibration.aspx

I'd be curious to know if you get it to work in silverlight, please comment after you try it :-)

Upvotes: 2

Francesco De Vittori
Francesco De Vittori

Reputation: 9290

Basically all you need to make the phone vibrate is this:

VibrateController.Default.Start(TimeSpan.FromMilliseconds(200));

I suggest to read this blog as it explains it quite well. The other chapters are interesting too if you haven't already seen them.

Upvotes: 18

Related Questions