Vbscript SendKeys and Get NumLock ,CapsLock, ScrollLock Key Status
Vbscript SendKeys and Get NumLock ,CapsLock, ScrollLock Key Status
在VBS脚本语言中只提供了SendKeys 来发送击键,却不能得到一些功能键的状态,如大小写功能键,数字功能键…, 尽管如些,我们还是有一些方法通过第三方来获取功能键的状态。
我可以通过调用word 或excel 等软件,来判断一此功能键的状态,但却只能得到NumLock ,CapsLock 的状态,却没办法获取ScrollLock 的状态。
这里我这介绍一个能够获取NumLock ,CapsLock, ScrollLock Key Status 的一个第三方很好用的小工具。
VBS程序如下:
'-----------------------------------------------------------------
' Description: Vbscript Send Key and Call Third Party Tool(klocks)
' Get NumLock, CapsLock,ScrollLock Key Status.
'
' Author: Lilo.Zhu
'
' Date: 2009-10-21
'------------------------------------------------------------------
Set WshShell = WScript.CreateObject("wscript.shell")
Set d = CreateObject("Scripting.Dictionary")
'----Turn On/Off All NumLock, CapsLock,ScrollLock----
For i =0 To 4
WshShell.Run "D:/Z/Tips/Script/Sample/klocks +n +c +s",0
WScript.Sleep 500
WshShell.Run "D:/Z/Tips/Script/Sample/klocks -n -c -s",0
WScript.Sleep 500
i = i + 1
Next
'----SendKeys For NumLock, CapsLock,ScrollLock----
For i =0 To 50
WshShell.SendKeys "{NUMLOCK}"
WScript.Sleep 500
WshShell.SendKeys "{CAPSLOCK}"
WScript.Sleep 500
WshShell.SendKeys "{SCROLLLOCK}"
WScript.Sleep 500
i=i+1
Next
'----Call Word Get NumLock,CapsLock Keys Status,But Can't Get ScrollLock Status----
'Function IsNumLocked()
'Dim oWrd
'Set oWrd = CreateObject("Word.Application")
'IsNumLocked = oWrd.NumLock
'oWrd.Application.Quit True
'End Function
'Function IsCapsLock()
'Dim oWrd
'Set oWrd = CreateObject("Word.Application")
'IsNumLocked = oWrd.CapsLock
'oWrd.Application.Quit True
'End Function
关于第三方小工具 Klocks.zip 的介绍如下:
|
||
Klocks is a Win32 commandline utility for NT4/W2K/XP/2003 that allows the Num, Caps and Scroll lock keys to be turned on, off or toggled. Klocks is a tiny standalone Win32 executable. It does not create any temporary files, nor does it write to the registry. There is no installation procedure, just run it. To completely remove all traces of it from your system, delete it. Klocks was written with batch file programmers in mind, and the output is easily parsed using the 'FOR /F' command found in NT4/W2K/XP/2003. Klocks is simple and intuitive to use. To list all its options, type klocks /?. |
||
KLOCKS [+key | -key | !key] [...] |
||
+ |
Turns the specified key on. |
|
- |
Turns the specified key off. |
|
! |
Toggles the specified key. |
|
key |
Key to be controlled. [N]um, [C]aps or [S]croll (either the first letter can be used or the full name of the key). |
|
... |
Additional keys to control (more than one key can be controlled). |
|
If no options are specified, the current status of the Num, Caps and Scroll lock keys is displayed, where 0 = off and 1 = On. |
||
View the Klocks main help screen:- klocks /? Display the current Lock keys status:- klocks Typical output from the above command showing that only the Num lock is on:- Num:1 Caps:0 Scroll:0 Turn on the Num lock:- klocks +n Toggles Num and Caps lock.:- klocks !num !caps Turns on Scroll lock and turns off Num and Caps lock:- klocks +scroll -num -c Batch file to continuously flash all Lock indicator lights:- @echo off Batch file to parse klocks output using a colon and a space as delimiters:- @echo off |