Windows Mobile 中類比按鍵

來源:互聯網
上載者:User

在Windows Mobile 中類比按鍵有時是非常有用的,比如我們可以發送Tab鍵使輸入焦點自動跳轉到下一個輸入框。在Windows Form程式中,我們可以調用SystemCalls.SendKey()來實現,但不幸的是在.net framework ce中卻沒有SystemCalls這個類。在網上找到實現這個功能的代碼,分享一下。

 

 class SystemCalls
    {
        public const byte VK_NONAME = 0xFC; // 什麼也不做

        public const byte VK_ESC = 0x1B; // Smartphone的回退鍵

        public const byte VK_F4 = 0x73; // Home Screen

        public const byte VK_APP6 = 0xC6; // Smartphone上鎖定鍵盤

        public const byte VK_F22 = 0x85; // PocketPC上鎖定鍵盤 (VK_KEYLOCK)

        public const byte VK_F16 = 0x7F; // 出發擴音器

        public const byte VK_OFF = 0x7F; //電源鍵

        public const byte VK_TAB = 0x09; //Tab鍵

        /// <summary>

        /// 將按鍵送至全域鍵盤緩衝區

        /// </summary>

        /// <param name="key"></param>

        public static void SendKey(byte key)
        {

            //const byte KEYEVENTF_SILENT = 0x0004;

            const int KEYEVENTF_KEYUP = 0x02;

            const int KEYEVENTF_KEYDOWN = 0x00;

            keybd_event(key, 0, KEYEVENTF_KEYDOWN, 0);

            keybd_event(key, 0, KEYEVENTF_KEYUP, 0);

        }

        [DllImport("coredll", SetLastError = true)]

        private static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);

    }

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.