Basic SendKeys application in VBS

Source: Internet
Author: User

Ps: I don't know if anyone remembers the code that attacked the QQ group? This is what I wrote!
SendKeys
Simulate a keyboard operation and send one or more key commands to a specified Windows window to control the application running,
The format is: object. SendKeys string

"Object": WshShell object
"String": the string of the key command to be sent, which must be placed in double quotation marks.

1. Basic Key

Generally, the key commands to be sent can be expressed by the key character. For example, to send the letter "x", use "WshShell. SendKeys" x. Of course, you can also directly send multiple key commands. You only need to sort the key characters in order. For example, to send the key "happy", you can use "WshShell. sendKeys "happy "".

2. special function keys

For keys that need to be combined with Shift, Ctrl, and Alt, SendKeys uses special characters:

Shift --------- WshShell. SendKeys "+"
Ctrl --------- WshShell. SendKeys "^"
Alt --------- WshShell. SendKeys "%"

Since the "+" and "^" characters are used to represent special control keys, how do I represent these keys?

You only need to enclose these characters in braces. For example:

To send the plus sign "+", you can use "WshShell. SendKeys" {+ }""

In addition, for some control buttons that do not generate characters, you also need to use braces to enclose the key name. For example, to send the return key, you need to use "WshShell. sendKeys "{ENTER}" indicates that "WshShell. sendKeys "{DOWN.

Space --------- WshShell. SendKeys ""
Enter --------- WshShell. SendKeys "{ENTER }"
Certificate --------- WshShell. SendKeys "{RIGHT }"
Certificate --------- WshShell. SendKeys "{UP }"
F1 --------- WshShell. SendKeys "{F1 }"

Tips: If you need to send multiple duplicate single-letter buttons, you do not need to enter the letter again. SendKeys allows you to describe in a simplified format in the format of {key number }". For example, to send 10 letters "x", enter "WshShell. SendKeys" {x 10.

Instance:
----------------------------------------------------
Press F5 to refresh the Desktop

Dim WshShell, Path, I
Set WshShell = WScript. CreateObject ("WScript. Shell ")
WshShell. SendKeys "{F5 }"
----------------------------------------------------
Automatic computer restart

Set WshShell = CreateObject ("WScript. Shell ")
WshShell. SendKeys "^ {ESC} u"
WshShell. SendKeys "R"
----------------------------------------------------
Start Task Manager

Set WshShell = CreateObject ("WScript. Shell ")
WshShell. SendKeys "^ + {ESC }"
----------------------------------------------------
QQ message sending

Dim WshShell
Set WshShell = WScript. createObject ("WScript. Shell ")
WshShell. AppActivate "bomb"
For I = 1 to 60
WScript. Sleep 800
WshShell. SendKeys "Number0"
WshShell. SendKeys I
WshShell. SendKeys "% s"
Next
----------------------------------------------------
Automatically go to Baidu to search for songs: white flag

Dim WshShell, Path, I
Set WshShell = WScript. CreateObject ("WScript. Shell ")
WshShell. Run ("iw.e. EXE ")
WScript. Sleep 2000
WshShell. AppActivate "about: blank-Microsoft Internet Explorer"
WshShell. SendKeys "+ {TAB }"
WshShell. SendKeys "http://mp3.baidu.com"
WScript. Sleep 800
WshShell. SendKeys "{ENTER }"
WScript. Sleep 3000
WshShell. SendKeys "white flag"
WScript. Sleep 800
WshShell. SendKeys "{ENTER }"
----------------------------------------------------
Enter Happy Birthday in Notepad! Save as birth.txt

Dim WshShell
Set WshShell = WScript. CreateObject ("WScript. Shell ")
WshShell. Run "notepad"
WScript. Sleep 1500
WshShell. AppActivate "untitled-Notepad"
WshShell. SendKeys "H"
WScript. Sleep 500
WshShell. SendKeys ""
WScript. Sleep 500
WshShell. SendKeys "p"
WScript. Sleep 500
WshShell. SendKeys "p"
WScript. Sleep 500
WshShell. SendKeys "y"
WScript. Sleep 500
WshShell. SendKeys ""
WScript. Sleep 500
WshShell. SendKeys "B"
WScript. Sleep 500
WshShell. SendKeys "I"
WScript. Sleep 500
WshShell. SendKeys "r"
WScript. Sleep 500
WshShell. SendKeys "t"
WScript. Sleep 500
WshShell. SendKeys "h"
WScript. Sleep 500
WshShell. SendKeys "d"
WScript. Sleep 500
WshShell. SendKeys ""
WScript. Sleep 500
WshShell. SendKeys "y"
WScript. Sleep 500
WshShell. SendKeys "! "
WScript. Sleep 500
WshShell. SendKeys "% FS"
WScript. Sleep 500
WshShell. SendKeys "B"
WScript. Sleep 500
WshShell. SendKeys "I"
WScript. Sleep 500
WshShell. SendKeys "r"
WScript. Sleep 500
WshShell. SendKeys "t"
WScript. Sleep 500
WshShell. SendKeys "h"
WScript. Sleep 500
WshShell. SendKeys "% S"
WScript. Sleep 500
WshShell. SendKeys "% FX"
----------------------------------------------------
Make a notebook that can automatically save disks at regular intervals

'Part 1: define variables and objects

Dim WshShell, AutoSaveTime, TXTFileName
AutoSaveTime = 300000
Set WshShell = WScript. CreateObject ("WScript. Shell ")
TXTFileName = InputBox ("enter the name of the file you want to create (Chinese and pure numbers are not supported ):")

'Part 2: open and activate notepad

WshShell. Run "notepad"
WScript. Sleep 200
WshShell. AppActivate "untitled-Notepad"

'Part 3: Save the disk with the input file name

WshShell. SendKeys "^ s"
WScript. Sleep 300
WshShell. SendKeys TXTFileName
WScript. Sleep 300
WshShell. SendKeys "% s"
WScript. Sleep AutoSaveTime
'Part 4: Automatic timed disk storage
While WshShell. AppActivate (TXTFileName) = True
WshShell. SendKeys "^ s"
WScript. Sleep AutoSaveTime
Wend
WScript. Quit
----------------------------------------------------
Crashed, hey!
DIM WSHSHELL
Set wshshell = WSCRIPT. CREATEOBJECT ("WSCRIPT. SHELL ")
'Wshshell. RUN ""
'Wscript. SLEEP 1000
WSHSHELL. SENDKEYS "{ENTER }"
'Wscript. SLEEP 1000
WSHSHELL. SENDKEYS "{ENTER }"
'Wscript. SLEEP 1000
WSHSHELL. SENDKEYS "{ENTER }"
'Wscript. SLEEP 1000
WSHSHELL. SENDKEYS "{ENTER }"
'Wscript. SLEEP 1000
WSHSHELL. SENDKEYS "{ENTER }"
----------------------------------------------------

Timed Shutdown

Dim WshShell
Set WshShell = WScript. CreateObject ("WScript. Shell ")
WScript. Sleep 2000
WshShell. Run "shutdown-r-t 120"
Wscript. sleep 6000
WshShell. Run "shutdown-

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.