gpt4 book ai didi

vba - VBA中GetKeyboardState keys(0)之后的 "keys(0)"是什么?

转载 作者:行者123 更新时间:2023-12-03 02:10:47 26 4
gpt4 key购买 nike

我是在 VBA 中使用 Windows API 函数的新手,我找不到 key(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用于获取按键状态的数组。

当你传递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.

关于vba - VBA中GetKeyboardState keys(0)之后的 "keys(0)"是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13127762/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com