词条 | 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,则键被关闭,且不被触发。触发键在键盘上的指示灯,当键被触发时即亮,键不被触发时即灭。 备注:当给定线程从它的消息队列中读键消息时,该函数返回的键状态发生改变。该状态并不反映与硬件相关的中断级的状态。使用GetAsyncKeyState可获取这一信息。 应用程序可以使用GetKeyState来响应一个由键盘输入产生的消息。此时该程序获得的是在输入消息生成时该键位的状态。 欲检取所有虚拟键状态信息,可以使用GetKeyboardState函数。 应用程序可以使用虚拟键码常数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 |
随便看 |
百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。