I am new to using Windows API functions in VBA and I can’t find what the keys(0) exactly does/means. It is also not in a bracket/parentheses so I do not understand how it works. Thanks in advance!
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
I’m assuming that you already know that GetKeyboardState is used to obtain an array of the state of your keys.
When you pass keys(0) essentially you are providing the memory location of the array to the Win API function. By doing this, your array is passed by reference to the function and the array you pass is filled with the data.
Here is sample usage copied from the linked page which I’m providing only because it has lots of comments: