VBA GetAsyncKeystate

2019-08-25 02:35发布

I am trying to capture keys strokes using the GetAsyncKeystate.

I am aware this can be done using Application.Onkey but I want to ensure that the code is not fired multiple times when the key is held down and I know this can be done using GetAsyncKeystate storing the previous state in variable for later comparison.

I currently have the following declared in a public module:

#If Win64 Then
  Public Declare PtrSafe Function GetAsyncKeystate Lib "user32" _
  (ByVal vKey As Long) As Integer

#Else
  Public Declare Function GetAsyncKeystate Lib "user32" _
  (ByVal vKey As Long) As Integer

#End If

Then in the module which contains my main code I am trying to do something along the lines of:

Sub KeyPressed
  'If KeyPressed is X key then
      'Do something

  'Or if KeyPressed is Y key then
      'Do something else

End Sub

Any help would be appreciated.

0条回答
登录 后发表回答