Send Win+sapce key, WINDOWS, SPACEBAR

Source: Internet
Author: User
Tags delete key

Keyboard code partial turn from: http://www.cnblogs.com/cpcpc/archive/2011/02/22/2123055.html

Because like to use CTRL + SPACEBAR to switch the input method, in the WIN8 is not accustomed to, so wrote a small program, when you press CTRL + SPACEBAR to send win+ space bar.

First use the global shortcut key, monitor CTRL + Space input, and then send the win+ space bar.

[DllImport ("user32.dll", SetLastError =true)]         Public Static extern BOOLRegisterHotKey (IntPtr hWnd,//Handle to Window         intId//Hot Key IdentifierKeymodifiers Fsmodifiers,//key-modifier OptionsKeys VK//Virtual-key Code         ); [DllImport ("user32.dll", SetLastError =true)]         Public Static extern BOOLUnregisterhotkey (IntPtr hWnd,//Handle to Window         intId//Hot Key Identifier         ); [Flags ()] Public enumkeymodifiers {None=0, Alt=1, Control=2, Shift=4, Windows=8        }/// <summary>        ///Toggle IME/// </summary>        Const intHotkeyid_switchime =343;/// <summary>        ///Send win+ space/// </summary>        /// <param name= "BVK" ></param>        /// <param name= "Bscan" ></param>        /// <param name= "DwFlags" ></param>        /// <param name= "dwExtraInfo" ></param>[DllImport ("user32.dll")]        Private Static extern voidKeybd_event (byteBVK,byteBscan,LongDwFlags,Longdwextrainfo);//register shortcut keys when Form1_shownPrivate voidForm1_shown (Objectsender, EventArgs e) {Version Win7ver=NewVersion ("6.1.9999.9999"); if(Environment.OSVersion.Version.CompareTo (Win7ver) >0)                {                    //CTRL + SPACEBAR toggle IME              BOOLBSUCC =RegisterHotKey (Handle, Hotkeyid_switchime, Keymodifiers.control, keys.space); }}//Send win+ space protected Override voidWndProc (refMessage m) {            Try            {                //Fixed Hotkey message 0x0312                Const intWm_hotkey =0x0312; Switch(m.msg) { CaseWm_hotkey:#regionDetermine which functionSwitch(M.wparam.toint32 ()) { CaseHotkeyid_switchime:Const byteVk_lwin =0x5b; Const byteVk_space =0x20; Const byteKeyeventf_keyup =0x2; Const byteKeyeventf_extendedkey =0x1; Keybd_event (Vk_lwin,0, Keyeventf_extendedkey,0); Keybd_event (Vk_space,0, Keyeventf_extendedkey,0); Keybd_event (Vk_space,0, Keyeventf_keyup,0); Keybd_event (Vk_lwin,0, Keyeventf_keyup,0);  Break; }                        #endregion                         Break; }                Base. WndProc (refm); }            Catch { }        }Private voidForm1_formclosing (Objectsender, FormClosingEventArgs e) {            //de-registering when offUnregisterhotkey (Handle, hotkeyid_switchime); }

You can replace keys on your keyboard with the following values anywhere in your code: Value Description0x1left mouse button0x2Right mouse button0x3CANCEL Key0x4Middle mouse button0x8BACKSPACE Key0x9TAB Key0xCCLEAR Key0xDEnter key0x10Shift key0x11CTRL Key0x12MENU Key0x13PAUSE Key0x14CAPS LOCK Key0x1BESC Key0x20SPACEBAR Key0x21PAGE up key0x22PAGE down key0x23END Key0x24HOME Key0x25Left Arrow key0x26Up Arrow key0x27RIGHT ARROW key0x28Down Arrow key0x29SELECT Key0x2APRINT Screen Key0x2BEXECUTE Key0x2CSNAPSHOT Key0x2DINSERT Key0x2eDELETE Key0x2FHelp Key0x90num LOCK A to Z key with a-the ASCII code of the Z-letter is the same: value description $A Key theB Key theC Key theD Key theE Key -F Key inG Key theH Key theI Key AboutJ Key theK Key theL Key theM Key +N Key -O Key theP KeyBayiQ Key theR Key theS Key -T Key -U Key theV Key theW Key theX Key theY Key -Z Key0To9Keys and Numbers0-9The ASCII code is the same: value description - 0Key the 1Key - 2KeyWuyi 3Key the 4Key - 5Key Wu 6Key - 7Key About 8Key $ 9key The following constants represent keys on the numeric keypad: Value Description0x60 0Key0x61 1Key0x62 2Key0x63 3Key0x64 4Key0x65 5Key0x66 6Key0x67 7Key0x68 8Key0x69 9Key0x6AMultiplication sign (*) Key0x6bPlus SIGN (+) Key0x6cEnter key0x6dMinus SIGN (-) Key0x6eDECIMAL Point (.) Key0x6FDivision sign (/) Key The following constants represent function keys: Value description0x70F1 Key0x71F2 Key0x72F3 Key0x73F4 Key0x74F5 Key0x75F6 Key0x76F7 Key0x77F8 Key0x78F9 Key0x79F10 Key0x7AF11 Key0x7BF12 Key0x7CF13 Key0x7dF14 Key0x7EF15 Key0x7FF16 Key

Send Win+sapce key, WINDOWS, SPACEBAR

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.