代码之家  ›  专栏  ›  技术社区  ›  moster67

.Net Compact Framework-向按钮单击事件添加振动

  •  2
  • moster67  · 技术社区  · 16 年前

    我想知道是否有人能给我一个提示,让我在按钮点击事件中增加振动。我一直在四处寻找,但只发现了使用窗口注册表的类似示例——不过,如果可能的话,我宁愿避免使用注册表。

    有谁能为我提供一些示例代码来实现这一点(C#或VB.Net)?

    非常感谢。

    jball提供的代码工作起来很有魅力。 为了实现短振动,我调用了如下代码:

    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
    

    真的很棒!

    1 回复  |  直到 16 年前
        1
  •  2
  •   jball    16 年前

    它是通过网络访问的 LED API . 从…起 here :

    在大多数设备上,振动是设定的 至LED设备1。

    下面是来自同一源代码的示例代码。

    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
    
    推荐文章