GetAsyncKeyState work in f8 step by step only

mtheriault2000

Well-known Member
Joined
Oct 23, 2008
Messages
826
Hello

I'm using GetAsyncKeyState to verify if the shift key as been press while a macro is activated. It work perfectly when i use the f8, step by step, debug process, give error 400 when running

The sub TestShiftKey is called by another macro

Code:
Private Declare Function GetAsyncKeyState Lib _
    "user32" (ByVal vKey As Long) As Integer

Public Sub TestShiftKey()
    ' (&H10) = Shift Key Code
    If GetAsyncKeyState(&H10) Then 
        ShiftKeyPress = True
        'MsgBox "Shift key is pressed"
    Else
        ShiftKeyPress = False
    End If
    
End Sub

Any help appreciated
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Resolve GetAsyncKeyState work in f8 step by step only

Hello

I did resolve the problem with the help of MrExcel user: Jaafar

I added the Cbool function before the GetAsynchKeyState command.

Code:
Public Sub TestShiftKey()
    If [COLOR="Red"]CBool[/COLOR](GetAsyncKeyState(&H10)) Then
        ShiftKeyPress = True
        MsgBox "Shift key is pressed"
    Else
        ShiftKeyPress = False
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,524
Messages
6,179,310
Members
452,906
Latest member
phanmemchatdakenhupviral

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top