GetKeyState

GetKeyState

  函数功能:该函数检取指定虚拟键的状态。该状态指定此键是UP状态,DOWN状态,还是被触发的(开关每次按下此键时进行切换)。
  函数原型:SHORT GetKeyState(int nVirtKey);
  函数:
  nVrtKey:定义一虚拟键。若要求的虚拟键是字母或数字(A~Z,a~z或0~9),nVirtKey必须被置为相应字符的ASCII码值,对于其他的键,nVirtKey必须是一虚拟键码。若使用非英语键盘布局,则取值在ASCIIa~z和0~9的虚拟键被用于定义绝大多数的字符键。例如,对于德语键盘格式,值为ASCII0(OX4F)的虚拟键指的是"0"键,而VK_OEM_1指"带变音的0键"
  返回值:返回值给出了给定虚拟键的状态,状态如下:
  若高序位为1,则键处于DOWN状态,否则为UP状态。
  若低序位为1,则键被触发。例如CAPS LOCK键,被找开时将被触发。若低序位置为0,则键被关闭,且不被触发。触发键在键盘上的指示灯,当键被触发时即亮,键不被触发时即灭。
  备注:当给定线程从它的消息队列中读键消息时,该函数返回的键状态发生改变。该状态井不反映与硬件相关的中断级的状态。使用SetKeyboardState可获取这一信息。
  欲检取所有虚拟键状态信息,可以使用SetKeyboardState函数。
  应用程序可以使用虚拟键码常数VK_SHIFT,VK_CONTROL和VK_MENU作为nVirtKey参数的值。它给出shift,ctrl或alt键的值而不区分左右键,应用程序也可以使用如下的虚拟键码常数作nVirtKey的值来区分前述键的左键、右键的情形。
  VK_LSHIFT,VK_RSHIFT;VK_LCONTROL,VK_RCONTROL;VK_LMENU,VK_RMENU
  仅当应用程序调用GetKeyboardSlate,SetKeyboardState,GetAsyncKeystate;GetKeyState和MapVirtualKey函数时,才可用这些区分左右键的常数。
  Windows CE:GetKeyState函数仅能用于检查如下虚拟键的DOWN状态。
  VK_LSHIFT,VKRSHIFT,VK_LCONTROL;VK_RCONTROL;VK_LMENU,VK_RMENU
  GetKeyState函数只能用于检查VK_CAPITAL虚拟键的触发状态。
  速查:Windows NT:3.1及以上版本;Windows:95及以上版本;Windows CE:1.I及以上版本;头文件:winuser.h;库文件:user32.lib。 
  GetKeyState Function
  Declare Function GetKeyState Lib "user32.dll" (ByVal nVirtKey As Long) As Integer 
  GetKeyState returns the current status of one of the keys on the keyboard. This status contains two pieces of information: the key's toggle state and the key's pressed state. The information is put into the return value. The toggle state is analogous to the toggle nature of the Caps Lock, Num Lock, and Scroll Lock keys, but Windows records toggle information about every key. The toggle information is stored in bit &H80 of the return value. The pressed state is true if the key is currently being depressed. The pressed information is stored in bit &H01 of the return value. See the example for more information on how to use the return value. 
  nVirtKey
  The virtual key code of the key to read the status of. 
  Example: 
  ' Read the status of the Enter key
  x = GetKeyState(&H0D) ' Enter's virtual key code is &H0D
  If (x And &H80) = &H80 Then ' check to see if it is toggled
  Debug.Print "Enter is currently toggled."
  End If
  If (x And &H01) = &H01 Then ' check to see if it is depressed
  Debug.Print "Enter is currently depressed."
  End If
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值