Spring Spring environment, I need to trigger a warning message every time a user closes the article listing, at this time existing events do not foresee this action.
Is there another way to control the closure of the chip and trigger the message?
Spring Spring environment, I need to trigger a warning message every time a user closes the article listing, at this time existing events do not foresee this action.
Is there another way to control the closure of the chip and trigger the message?
For the 1 case use this code example. This one made for VB6 is a point that will have to adptar to your reality.
Public Const WH_KEYBOARD = 2
Public Const VK_SHIFT = &H10
Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal
ncode As Long, ByVal wParam As Long, lParam As Any) As Long
Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As
Integer
Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA"
(ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal
dwThreadId As Long) As Long
Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As
Long
Public hHook As Long
Public Function KeyboardProc(ByVal idHook As Long, ByVal wParam As Long,
ByVal lParam As Long) As Long
If idHook < 0 Then
'call the next hook
KeyboardProc = CallNextHookEx(hHook, idHook, wParam, ByVal lParam)
Else
'check if SHIFT-S is pressed
If (GetKeyState(VK_SHIFT) And &HF0000000) And wParam = Asc("S") Then
'show the result
Debug.Print "Shift-S pressed ..."
End If
'call the next hook
KeyboardProc = CallNextHookEx(hHook, idHook, wParam, ByVal lParam)
End If
End Function
Private Sub Start_Hook()
hHook = SetWindowsHookEx(WH_KEYBOARD, AddressOf KeyboardProc, App.hI
nstance, App.ThreadID)
End Sub
Private Sub End_Hook()
UnhookWindowsHookEx hHook
End Sub
In the second case you have to mount a Timer, so you can easily catch the ESC from the window. This approach has a problem, which is the fact that some windows have this event locked and do not close when the user loads on ESC.
Private Sub Timer()
DoEvents
If GetAsyncKeyState(vbKeyEscape) < 0 Then
Debug.Print "ESC pressed"
End If
End Sub