人气 4120

[Excel技巧] 利用VBA判断Caps Lock,Num Lock,Scroll Lock键的状态 [复制链接]

精益人 2017-10-3 18:00:09
分享一个VBA源码:判断Caps Lock键、Num Lock键及Scroll Lock键的开启状态,这里用到API函数,API使用需放置在代码窗口的最上方:
PrivateDeclareFunctionGetKeyStateLib"user32"(ByValnVirtKeyAsLong)AsInteger
ConstVK_NUMLOCK=&H90
ConstVK_SCROLL=&H91
ConstVK_CAPITAL=&H14
PrivateSubKeyStates()
IfGetKeyState(VK_CAPITAL)Then 'CapsLock键
MsgBox"CapsLockON"
Else
MsgBox"CapsLockOFF"
EndIf
IfGetKeyState(VK_NUMLOCK)Then 'NumLock键
MsgBox"NumLockON"
Else
MsgBox"NumLockOFF"
EndIf
IfGetKeyState(VK_SCROLL)Then 'ScrollLock键
MsgBox"ScrollLockON"
Else
MsgBox"ScrollLockOFF"
EndIf
EndSub
'另外,在Word中可以使用下面的VBA代码来判断CapsLock键是否开启:
SubKeyStates2()
IfSelection.Information(wdCapsLock)Then
MsgBox"CapsLock键已开启"
Else
MsgBox"CapsLock键已关闭"
EndIf
EndSub
1506759191260729.png (5.43 KB, 下载次数: 0, 售价: 4 金钱)
您需要登录后才可以回帖 登录 | 立即注册

QQ|手机版|精益人 ( 沪ICP备19004111号-1 )|网站地图

GMT+8, 2024-12-23 04:15 , Processed in 0.261558 second(s), 24 queries .

Powered by Lean.ren X3.5 Licensed  © 2001-2030 LEAN.REN