views:

187

answers:

1

Hi,

I am wondering if anyone could provide me with a hint for adding vibration to a button's click event. I have been looking around but only found similar examples using the window registry - however I would prefer avoid toching the registry if possible.

Anyone who could provide me with some sample-code to achieve this (C# or VB.Net)?

Thank you.

UPDATE: The code provided by jball works like a charm. I called the code as follows in order to achieve a short vibration:

Private Sub btnMute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _  
handles btnMute.Click
            SetVibrate(1)
            Thread.Sleep(50) 'how long should the vibration last
            SetVibrate(0)
end sub

Works really great!

+2  A: 

It's accessed through the LED API. From here:

On most devices the vibration is set to LED device 1.

Here's the sample code from the same source.

Private Structure NLED_SETTINGS_INFO
    Public LedNum As Integer
    Public OffOnBlink As Integer
    Public TotalCycleTime As Integer
    Public OnTime As Integer
    Public OffTime As Integer
    Public MetaCycleOn As Integer
    Public MetaCycleOff As Integer
End Structure

<DllImport("Coredll")> _
Private Shared Function NLedSetDevice(ByVal deviceId As Integer, ByRef info 
                                            As NLED_SETTINGS_INFO) As Boolean
End Function

Private Shared Sub SetVibrate(ByVal state As Boolean)
    Dim info As New NLED_SETTINGS_INFO()
    info.LedNum = 1
    info.OffOnBlink = If(state, 1, 0)
    NLedSetDevice(1, info)
End Sub
jball
Excellent! I just tried it and it worked like a charm.
moster67