WM手机,如何实现震动?

 public class LedLib
    {
        private int m_count;
        private const int NLED_COUNT_INFO_ID = 0;
        private const int NLED_SUPPORTS_INFO_ID = 1;

        public LedLib()
        {
            NLED_COUNT_INFO pOutput = new NLED_COUNT_INFO();
            if (!NLedGetDeviceCount(0, ref pOutput))
            {
                throw new Exception("震动模块初始化错误!");
            }
            this.m_count = (int)pOutput.cLeds;
        }

        [DllImport("coredll.dll", EntryPoint = "NLedGetDeviceInfo")]
        private static extern bool NLedGetDeviceCount(short nID, ref NLED_COUNT_INFO pOutput);
        [DllImport("coredll.dll", EntryPoint = "NLedGetDeviceInfo")]
        private static extern bool NLedGetDeviceSupports(short nID, ref NLED_SUPPORTS_INFO pOutput);
        [DllImport("coredll.dll")]
        private static extern bool NLedSetDevice(short nID, ref NLED_SETTINGS_INFO pOutput);
        public void SetLedStatus(uint led, LedState newState)
        {
            NLED_SETTINGS_INFO pOutput = new NLED_SETTINGS_INFO();
            pOutput.LedNum = led;
            pOutput.OffOnBlink = (int)newState;
            bool flag = NLedSetDevice(2, ref pOutput);
        }

        public enum LedState
        {
            Off,
            On,
            Blink
        }

        [StructLayout(LayoutKind.Sequential)]
        private struct NLED_COUNT_INFO
        {
            public uint cLeds;
        }

        [StructLayout(LayoutKind.Sequential)]
        private struct NLED_SETTINGS_INFO
        {
            public uint LedNum;
            public int OffOnBlink;
            public int TotalCycleTime;
            public int OnTime;
            public int OffTime;
            public int MetaCycleOn;
            public int MetaCycleOff;
        }

        [StructLayout(LayoutKind.Sequential)]
        private struct NLED_SUPPORTS_INFO
        {
            public uint LedNum;
            public int lCycleAdjust;
            public bool fAdjustTotalCycleTime;
            public bool fAdjustOnTime;
            public bool fAdjustOffTime;
            public bool fMetaCycleOn;
            public bool fMetaCycleOff;
        }
    }

 

 

        /// <summary>
        /// 实现震动
        /// </summary>
        /// <param name="setTimes">震动毫秒数</param>
        public static void Play(int setTimes)
        {
            try
            {
                LedLib led = new LedLib();
                led.SetLedStatus(1, LedLib.LedState.On);
                Thread.Sleep(setTimes);
                led.SetLedStatus(1, LedLib.LedState.Off);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值