Detecting

Detecting the Shift, Ctrl or Alt Keys
The following function uses a Windows API call to detect if the shift, ctrl and/or alt keys are pressed.

Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer 

Public Const VK_SHIFT As Long = &H10
Public Const VK_CONTROL As Long = &H11
Public Const VK_ALT As Long = &H12

Function GetShiftCtrlAlt() As String

    If GetAsyncKeyState(VK_SHIFT) <> 0 Then
        Debug.Print "SHIFT key held down"
        GetShiftCtrlAlt = "SHIFT"
    End If
    
    If GetAsyncKeyState(VK_CONTROL) <> 0 Then
        Debug.Print "CTRL key held down"
        GetShiftCtrlAlt = "CTRL"
    End If
    
    If GetAsyncKeyState(VK_ALT) <> 0 Then
        Debug.Print "ALT key held down"
        GetShiftCtrlAlt = "ALT"
    End If
End Function


© 2019 Better Solutions Limited. All Rights Reserved. © 2019 Better Solutions Limited TopPrevNext