我假设您已经知道GetKeyboardState用于获取键状态的数组。
当您传递 keys(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.