WPF virtual keyboard and wpf virtual keyboard

Source: Internet
Author: User

WPF virtual keyboard and wpf virtual keyboard

Previously, a WPF virtual keyboard called Win32 API to simulate Keyboard Events.

The Code is as follows:

The key layout is as follows:

   <Button Name="CmdTlide" Focusable="False" Click="Button_Click"  Style="{StaticResource InformButton}"  VerticalContentAlignment="Top" HorizontalContentAlignment="Left"  Width="60" Height="60">                                    <StackPanel Orientation="Vertical" HorizontalAlignment="Left" VerticalAlignment="Top" >                                        <TextBlock    HorizontalAlignment="Left" VerticalAlignment="Top"   ><Run Text="~"/></TextBlock>                                        <TextBlock HorizontalAlignment="Left" VerticalAlignment="Bottom"   ><Run Text="'"/></TextBlock>                                    </StackPanel>                                </Button>

Click Event:

Private void Button_Click (object sender, RoutedEventArgs e) {System. windows. controls. button keybtn = sender as System. windows. controls. button; # region // First Row if (keybtn. name = "CmdTlide") {addNumkeyINput (0xc0);} else if (keybtn. name = "cmd1") {addNumkeyINput (0x31);} else if (keybtn. name = "cmd2") {addNumkeyINput (0x32);} else if (keybtn. name = "cmd3") {addNumkeyINput (0x33);} else if (Keybtn. name = "00004") {addNumkeyINput (0x34);} else if (keybtn. name = "00005") {addNumkeyINput (0x35);} else if (keybtn. name = "00006") {addNumkeyINput (0x36);} else if (keybtn. name = "00007") {addNumkeyINput (0x37);} else if (keybtn. name = "00008") {addNumkeyINput (0x38);} else if (keybtn. name = "00009") {addNumkeyINput (0x39);} else if (keybtn. name = "00000") {addNumkeyINput (0x30);} e Lse if (keybtn. name = "cmdminus") //-_ {addNumkeyINput (0xbd);} else if (keybtn. name = "cmd1") // + = {addNumkeyINput (0xbb);} else if (keybtn. name = "cmdBackspace") // backspace {AddKeyBoardINput (0x08);} # endregion # region/Second Row else if (keybtn. name = "shorttab") {AddKeyBoardINput (0x09);} else if (keybtn. name = "CmdQ") {AddKeyBoardINput (0x51);} else if (keybtn. name = "Drawing W") {AddKeyB OardINput (0x57);} else if (keybtn. name = "CmdE") {AddKeyBoardINput (0X45);} else if (keybtn. name = "CmdR") {AddKeyBoardINput (0X52);} else if (keybtn. name = "CmdT") {AddKeyBoardINput (0X54);} else if (keybtn. name = "CmdY") {AddKeyBoardINput (0X59);} else if (keybtn. name = "CmdU") {AddKeyBoardINput (0X55);} else if (keybtn. name = "CmdI") {AddKeyBoardINput (0X49);} else if (keybtn. name = "CmdO") {AddKeyBoardINput (0X4F);} else if (keybtn. name = "CmdP") {AddKeyBoardINput (0X50);} else if (keybtn. name = "CmdOpenCrulyBrace") {addNumkeyINput (0xdb);} else if (keybtn. name = "CmdEndCrultBrace") {addNumkeyINput (0xdd);} else if (keybtn. name = "CmdOR") {addNumkeyINput (0xdc) ;}# endregion # region // Third ROw else if (keybtn. name = "Your capslock") // caps lock {AddKeyBoardINput (0 X14); if (checkImage. Visibility! = Visibility. visible) {checkImage. visibility = Visibility. visible;} else {checkImage. visibility = Visibility. hidden;} else if (keybtn. name = "CmdA") {AddKeyBoardINput (0x41);} else if (keybtn. name = "CmdS") {AddKeyBoardINput (0x53);} else if (keybtn. name = "CmdD") {AddKeyBoardINput (0x44);} else if (keybtn. name = "CmdF") {AddKeyBoardINput (0x46);} else if (keybtn. name = "CmdG") {Add KeyBoardINput (0x47);} else if (keybtn. name = "CmdH") {AddKeyBoardINput (0x48);} else if (keybtn. name = "CmdJ") {AddKeyBoardINput (0x4A);} else if (keybtn. name = "CmdK") {AddKeyBoardINput (0X4B);} else if (keybtn. name = "CmdL") {AddKeyBoardINput (0X4C);} else if (keybtn. name = "your colon") //;: {addNumkeyINput (0xba);} else if (keybtn. name = "CmdDoubleInvertedComma") // '"{addNumkeyINput (0xde);} else if (keybtn. name = "CmdEnter") {AddKeyBoardINput (0x0d) ;}# endregion # region // Fourth Row else if (keybtn. name = "Shift" | keybtn. name = "CmdlShift") {if (CtrlFlag) {CtrlFlag = false; ShiftFlag = false; changeInput () ;}else {ShiftFlag = true ;}} else if (keybtn. name = "CmdZ") {AddKeyBoardINput (0X5A);} else if (keybtn. name = "jsonx") {AddKeyBoardINput (0X58);} else if (Keybtn. name = "CmdC") {AddKeyBoardINput (0X43);} else if (keybtn. name = "CmdV") {AddKeyBoardINput (0X56);} else if (keybtn. name = "CmdB") {AddKeyBoardINput (0X42);} else if (keybtn. name = "CmdN") {AddKeyBoardINput (0x4E);} else if (keybtn. name = "CmdM") {AddKeyBoardINput (0x4D);} else if (keybtn. name = "CmdLessThan") // <, {addNumkeyINput (0xbc);} else if (keybtn. name = "CmdGreaterThan") //>. {AddNumkeyINput (0xbe);} else if (keybtn. Name = "CmdQuestion ")//? /{AddNumkeyINput (0xbf);} else if (keybtn. name = "CmdSpaceBar") {AddKeyBoardINput (0x20);} # endregion # region/Last row else if (keybtn. name = "Ctrl" | keybtn. name = "CmdlCtrl") // ctrl {if (ShiftFlag) {ShiftFlag = false; CtrlFlag = false;} else {CtrlFlag = true ;} // AddKeyBoardINput (0x11);} else if (keybtn. name = "Pageup") {AddKeyBoardINput (0x21);} else if (keybtn. name = "Pagedown") {AddKeyBoardINput (0x22);} else if (keybtn. name = "Closing close") // close the keyboard {// this. opacity = 0; // this. close (); // this. keyboard. visibility = Visibility. hidden; // this. keyboard. focusable = false; System. windows. application. current. shutdown () ;}# endregion}

Trigger a keyboard event:

  private static void addNumkeyINput(byte input)        {            if (CtrlFlag)            {                CtrlFlag = false;                ShiftFlag = false;                keybd_event(input, 0, 0, 0);                keybd_event(input, 0, 0x02, 0);            }            else            {                if (!ShiftFlag)                {                    keybd_event(input, 0, 0, 0);                    keybd_event(input, 0, 0x02, 0);                }                else                {                    keybd_event(0x10, 0, 0, 0);//shift                    keybd_event(input, 0, 0, 0);                    keybd_event(input, 0, 0x02, 0);                    keybd_event(0x10, 0, 0x02, 0);                    ShiftFlag = false;                }            }        }

Source code download

 

Related Article

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.