Is there any way to trap "Print Screen" and "Alt" Keys.
Printable View
Is there any way to trap "Print Screen" and "Alt" Keys.
Not sure what you mean by "trapping" the alt and print screen keys. But here is how you can tell if they are pressed by using the GetAsyncKeyState API function.
Code:Private Declare Function GetAsyncKeyState _
Lib "user32.dll" (ByVal vKey As Long) As Integer
Private Const VK_MENU = &H12 'either alt key
Private Const VK_SNAPSHOT = &H2C 'print screen
Private Sub Timer1_Timer()
If GetAsyncKeyState(VK_MENU) Then
Msgbox "Alt key pressed"
ElseIf GetAsyncKeyState(VK_SNAPSHOT) Then
Msgbox "Print screen key pressed"
End If
End Sub
Thanks!! I was asked to add this as a feature to a program I am creating. The user wants to prevent people from capturing the screen of employees photographs displayed on an index.
GetAsyncKeyState will not prevent this from happening. If you want to prevent it, you'd need to create a systemwide hook.