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 Commandline Lock Keys Controller

 

About Klocks
Parameters
Examples

clip_image001Download klocks.zip (4k)

About Klocks

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 /?.

Parameters

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.

Examples

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
:: Turn all lights on
klocks +n +c +s
:top
ping 127.0.0.1 -n 2 >nul
:: Toggle all lights
klocks !n !c !s
goto :top

Batch file to parse klocks output using a colon and a space as delimiters:-

@echo off
for /f "tokens=2,4,6 delims=: " %%a in ('klocks') do (
  set num=%%a
  set cap=%%b
  set scr=%%c
)
if %num%==1 (echo/Num is on) else (echo/Num is off)
if %cap%==1 (echo/Caps is on) else (echo/Caps is off)
if %scr%==1 (echo/Scroll is on) else (echo/Scroll is off)

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值