Hi all...
Anyone can help me how to disable the ALT+TAB key using VBA code in microsoft access? I can do it in VB6 using low-level keyboard hook WH_KEYBOARD_LL. But this code didn't run in access vba. Can we do that using VBA code?
Thx
Hi all...
Anyone can help me how to disable the ALT+TAB key using VBA code in microsoft access? I can do it in VB6 using low-level keyboard hook WH_KEYBOARD_LL. But this code didn't run in access vba. Can we do that using VBA code?
Thx
Sounds like you want to trap it at the Windows level. What is the WH_KEYBOARD_LL code?
No, i just trying to make the internet cafe billing aplication using Microsoft Access. Oh, WH_KEYBOARD_LL is a variable of low level keyboard in SetWindowsHookEx API function which i use in vb to disable combination Alt+Tab key. But how we do that in access VBA?
Probably very close to the way you do it in VB. Do you want to post the code you are using in VB?
Here this code that i use in VB:
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Public Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Public 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
Public Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public Const HC_ACTION = 0
Public Const WM_KEYDOWN = &H100
Public Const WM_KEYUP = &H101
Public Const WM_SYSKEYDOWN = &H104
Public Const WM_SYSKEYUP = &H105
Public Const VK_TAB = &H9
Public Const VK_CONTROL = &H11
Public Const VK_ESCAPE = &H1B
Public Const VK_STARTKEY = &H5B
Public Const WH_KEYBOARD_LL = 13
Public Const LLKHF_ALTDOWN = &H20
Public Type KBDLLHOOKSTRUCT
vkCode As Long
scanCode As Long
flags As Long
time As Long
dwExtraInfo As Long
End Type
Dim p As KBDLLHOOKSTRUCT
Function LowLevelKeyboardProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim fEatKeystroke As Boolean
If (nCode = HC_ACTION) Then
If wParam = WM_KEYDOWN Or wParam = WM_SYSKEYDOWN Or wParam = WM_KEYUP Or wParam = WM_SYSKEYUP Then
CopyMemory p, ByVal lParam, Len(p)
fEatKeystroke = _
((p.vkCode = VK_TAB) And ((p.flags And LLKHF_ALTDOWN) <> 0)) Or _
((p.vkCode = VK_ESCAPE) And ((p.flags And LLKHF_ALTDOWN) <> 0)) Or _
((p.vkCode = VK_ESCAPE) And ((GetKeyState(VK_CONTROL) And &H8000) <> 0)) Or _
p.vkCode = VK_STARTKEY
End If
End If
If fEatKeystroke Then
LowLevelKeyboardProc = -1
Else
LowLevelKeyboardProc = CallNextHookEx(0, nCode, wParam, ByVal lParam)
End If
End Function
and then in the event Form Load (OnLoad) i write this code below to disable the ALT+TAB key combinations:
hhkLowLevelKybd = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf LowLevelKeyboardProc, App.hInstance, 0)
The problem is on "App.hInstance", because there is no "App" object/variable on Access.
<ALT> Tab switches to the next Windows Application right? Is that what you are trying to stop?
Yes, that is. Do you know how to do that with access vba
Unfortunately no. It sounds like you are on the right track but just need the right code for Access. Good luck. Have you checked Google yet?
Yeah, i just need to find the vb object (App/App.hInstace) that equal in access VBA. I'd checked google too but still not found the right code