什么是VBA中的GetKeyboardState键(0)后的“keys(0)”?

我是在VBA中使用Windows API函数的新手,我无法find键(0)确切的意思。 它也不在括号/括号中,所以我不明白它是如何工作的。 提前致谢!

Private Declare PtrSafe Function GetKeyboardState Lib "user32" _ (pbKeyState As Byte) As Long Property Get Value() As Boolean Dim keys(0 To 255) As Byte GetKeyboardState keys(0) '<< Can someone explain what this is doing? Value = keys(VK_NUMLOCK) End Property 

我假设你已经知道GetKeyboardState是用来获得你的密钥的状态的数组。

当您传递键(0)时,本质上是将数组的内存位置提供给Win API函数。 通过这样做,您的数组通过引用传递给函数,并且传递的数组充满了数据。

这里是从我提供的链接页面复制的示例用法,因为它有很多评论:

 ' Display the key status of the Enter and Backspace keys ' Enter's virtual key code = 13; Backspace's virtual key code = 8 Dim keystat(0 To 255) As Byte ' receives key status information for all keys Dim retval As Long ' return value of function retval = GetKeyboardState(keystat(0)) ' In VB, the array is passed by referencing element #0. ' Display info about Enter If (keystat(13) And &H01) = &H01 Then Debug.Print "Enter is being pressed." If (keystat(13) And &H80) = &H80 Then Debug.Print "Enter is toggled." ' Display info about Backspace If (keystat(8) And &H01) = &H01 Then Debug.Print "Backspace is being pressed." If (keystat(8) And &H80) = &H80 Then Debug.Print "Backspace is toggled.