ExcelVBAでESCキー押された判定する関数作成

標準モジュールでのみ実装可能です

#If Win64 Then
Declare PtrSafe Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
#Else
Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
#End If

Function IsEscPressed() As Boolean
    ' VK_ESCAPE = &H1B
    If GetAsyncKeyState(&H1B) Then
        IsEscPressed = True
    Else
        IsEscPressed = False
    End If
End Function