[vb.net] Call API Get/SET keyboard key state

Source: Internet
Author: User

1. Call Getasynckeystate () to get the state of the specified key, Getactivekey () retrieves the key state in the specified range

2. Call keybd_event () to synthesize a keystroke event, usually between two keystroke events you need to set a time interval

3. Call Mapvirtualkey () to get the hardware scan code for the specified key, and the second parameter to the keybd_event () is valid for DirectInput.

 Public ClassImitatekeyclassPrivate Declare SubKeybd_eventLib "User32"(ByValBvk as Byte,ByValBscan as Byte,ByValDwFlags as Integer,ByValdwExtraInfo as Integer)    Private Declare FunctionMapvirtualkeyLib "User32" Alias "Mapvirtualkeya"(ByValWcode as Integer,ByValWmaptype as Integer) as Integer    Private Declare FunctionGetasynckeystateLib "User32"(ByValVkey as Integer) as Integer    " " <summary>    " "send button" " </summary>    " " <param name= "Chararray" ></param>     Public SubSendstring (Chararray as String)         for  eachSubchar as Char inchChararray keybd_event (ASC(Subchar), Mapvirtualkey (ASC(Subchar),0), &AMP;H1Or 0,0)'Press theSystem.Threading.Thread.Sleep (Ten)'DelayKeybd_event (ASC(Subchar), Mapvirtualkey (ASC(Subchar),0), &AMP;H1Or&AMP;H2,0)'pop UpSystem.Threading.Thread.Sleep (Ten)        Next    End Sub    " " <summary>    " "gets the key state of the A~z" " </summary>    " " <returns></returns>     Public FunctionGetactivekey () as Byte         fori = $  to  - 'A~z's ASICC code            IfCurrentkeystate (i) =True  Then ReturnINext        Return 0    End Function    " " <summary>    " "get keyboard key State" " </summary>    " " <param name= "KeyCode" ></param>    " " <returns></returns>    Private FunctionCurrentkeystate (ByValKeyCode as Byte) as Boolean        DimTemp as Integer=getasynckeystate (keycode)Return(IIf(temp =-32767,True,False))    End FunctionEnd Class

[vb.net] Call API Get/SET keyboard key state

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.