Use sendkeys and shell functions in vb.net

Source: Internet
Author: User
Remote control using sendkeys in vb.net:
Sendkeys has been used in vb6. Remote control is used to indirectly control external programs by sending keyboard events.
In vb7, I found that this was useless and it was useless. Later I saw this when I checked msdn. I tried it and it turned out to be as easy as it was to use.
In the system. winforms family, the sendkeys usage is the same as that in vb6.
Key: The general character key is as follows: "a" "B" "c ".................." Z ", if you want to press more than two in a row, use the" AB "form. If you press AB at the same time, use parentheses, such as" (AB )"
If it is a function key, put it in braces such as "{f4}". In addition, use + to represent shift, use ^ to represent ctrl, and use % to represent alt.
For example, "+ a" means to press shift and press
The following is an example:
Dim sdstr as system. winforms. sendkeys
Sdstr. send ("% {f4}") send alt + f4
The following code transfers the focus to the next control after pressing button2 so that the button can be pressed and the focus cannot be pressed.
Protected sub button2_click (byval sender as object, byval e
As system. eventargs)
Dim sdstr as system. winforms. sendkeys
Sdstr. send ("{tab }")
End sub
Sendwait is used in the following way. The same method is used. However, to execute this process, the subsequent code will be executed after the sending key is executed.
Protected sub button2_click (byval sender as object, byval e
As system. eventargs)
Dim sdstr as system. winforms. sendkeys
'Sdstr. send ("{tab }")
Sdstr. sendwait ("{tab }")
End sub
Use shell to call external programs in vb.net:
Shell (pathname as string, [style
Microsoft. visualbasic. appwinstyle = 2], [wait
Boolean = false], [timeout as integer =-1]) as integer
Call Resource Manager
Dim pid as integer
Pid = shell ("assumer.exe http://vbnetcn.126.com ",
Microsoft. visualbasic. appwinstyle. normalfocus, true)
Call the default program
Dim pid as integer
Pid = shell ("start.exe mailto: vbnetcn@163.com ",
Microsoft. visualbasic. appwinstyle. hide, true)
The microsoft. visualbasic. appwinstyle. hide parameter is used to hide the program.
Dos window popped out during running.
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.