Consulting

Page 1 of 2 1 2 LastLast
Results 1 to 20 of 21

Thread: How to disable ALT+TAB,CTRL+ESC, and Windows key using VBA

  1. #1
    VBAX Regular
    Joined
    Aug 2009
    Posts
    21
    Location

    Question How to disable ALT+TAB,CTRL+ESC, and Windows key using VBA

    Hi all..

    I'm trying to make an internet cafe billing application using Microsoft Access. Any one can help me how to disable ALT+TAB, CTRL+ESC, and Windows button function using access VBA? I can do that in VB using SetWindowsHookEx API function. But in access vba it's not running well because the variable/object/property "App" does not exist in Microsoft Access. There is the way to do that in Microsoft Access VBA?

    Thanks

  2. #2
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    I don't know the answer to your question, but can I ask why you would want to do this? As a user I would be extremely unhappy if any application disabled these keystrokes as I use them constantly.

  3. #3
    VBAX Regular
    Joined
    Aug 2009
    Posts
    21
    Location

    Smile

    Quote Originally Posted by geekgirlau
    I don't know the answer to your question, but can I ask why you would want to do this? As a user I would be extremely unhappy if any application disabled these keystrokes as I use them constantly.
    Thanks for your response. But i think you don't read my post well. I've said that i try to make INTERNET CAFE BILLING application. Therefore i need to disable the function of ALT+TAB, CTRL+ESC, & WINDOWS key to prevent users to accessing computer before they login to billing application. I can do that in my vb project, but i don't know how to make my code in vb can run in access vba too.
    Last edited by Yance; 09-03-2009 at 08:19 AM.

  4. #4
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    GG has a good point, but for an I-Cafe I could see why you might want to do that.
    I haven't tried to do this myself, but one approach to consider would be to make your database using Access's "Data Access Pages" and for your application's "front end" and then just using your application via internet explorer in "kiosk mode".

    This won't completely lock down the desktop, but it get's you a hair closer. If you have a copy of the original VB6 code, I might be able to help you adapt it.
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

  5. #5
    VBAX Regular
    Joined
    Aug 2009
    Posts
    21
    Location

    Smile

    Thank you Oorang..

    Here my VB6 code:

    [VBA]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

    Public hhkLowLevelKybd
    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[/VBA]

    To run this function, i add this code below in Form_Load Event:

    [VBA]hhkLowLevelKybd = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf LowLevelKeyboardProc, App.hInstance, 0)[/VBA]

    The problem is on "App.hInstance". I don't know the Access VBA object/property for that.

  6. #6
    VBAX Regular
    Joined
    Aug 2009
    Posts
    21
    Location

    Smile

    Thank you Oorang..

    I don't have any problem with database. But your input gives me a new inspiration.

    Here my VB6 code:

    [VBA]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

    Public hhkLowLevelKybd
    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[/VBA]

    To run this function, i add this code below in Form_Load Event:

    [VBA]hhkLowLevelKybd = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf LowLevelKeyboardProc, App.hInstance, 0)[/VBA]

    The problem is on "App.hInstance". I don't know the Access VBA object/property for that.

  7. #7
    VBAX Regular
    Joined
    Aug 2009
    Posts
    21
    Location
    Sorry for my double post, there is problem with my internet connection.

  8. #8
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    Haven't tested this, but to get the form's handle just use me.Hwnd (from inside the form). If you want the handle to Access itself you would use Access.hWndAccessApp. Let me know if that works?
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

  9. #9
    VBAX Regular
    Joined
    Aug 2009
    Posts
    21
    Location
    No, i've tried it before and it doesn't work. That is mean we can't do that in access vba?

  10. #10
    VBAX Regular
    Joined
    Aug 2009
    Posts
    21
    Location
    Currently i just write a code in Form_Timer event to make access window always on top and disable the task manager. So, although users press the ALT+TAB, CTRL+ESC, WINDOWS key on the keyboard, they never can't use or got focus to another application before successfull login to the my i-cafe application (just like using internet explorer in "kiosk mode").

  11. #11
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    Nice solution I'd like to know how it tests out. Would you mind posting your results?
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

  12. #12
    VBAX Regular
    Joined
    Aug 2009
    Posts
    21
    Location

    Smile

    Here i enclose my project example. But i'm not satisfied with this result, that's why i posting my question here to find the way for adapting my vb code in access vba. Is this possible?

  13. #13
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    It's not bad. I can still alt-f4 out of it though. And if you are really quick you can hit the windows key and then click something off the start menu. I think the answer may lie with configuring the OS properly. Take a look at this.
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

  14. #14
    VBAX Regular
    Joined
    Aug 2009
    Posts
    21
    Location
    I'm sorry. I forgot to post my code for prevent user to close the form/application using combination key (CTRL+F4 & ALT+F4) in Form_Unload event.
    The solution on PC Tools just configure the windows registry. I also ever do that. But the way to disable the coolswitch (ALT+TAB function) with configure the registry is not working. That's why i use the LowLevelKeyboardProc function in vb to disable all the combination key.

  15. #15
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    Did you reboot after you altered the registry?
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

  16. #16
    VBAX Regular
    Joined
    Aug 2009
    Posts
    21
    Location
    Yes, i reboot my pc after that. FYI, only to disable the ALT+TAB with configure the registry is not working.
    Last edited by Yance; 09-11-2009 at 09:56 AM.

  17. #17
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    Hmmm, I haven't tried it, but there are some indications that setting these values to zero might work:
    HKEY_CURRENT_USER\Control Panel\Desktop\Coolswitch
    HKEY_CURRENT_USER\Control Panel\Desktop\CoolSwitchColumns
    HKEY_CURRENT_USER\Control Panel\Desktop\CoolSwitchRows
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

  18. #18
    VBAX Regular
    Joined
    Aug 2009
    Posts
    21
    Location
    No, it's doesn't wok. I ever do that.

  19. #19
    VBAX Regular
    Joined
    Aug 2009
    Posts
    21
    Location

    Smile

    Hello oorang, sorry i don't give an update for my i-cafe project about 1 year . I've found the solution of my question to disable the hot keys, even to make/run in new desktop.

    But i have one question again about: How to make our form always on top even in fullscreen game? (should i make a new post?) I already can make my access form always on top but not in all fullscreen game. In Point Blank, Counter Strike game, my form can always on top without any problem. But in a several games like Batle Realms, Pop Caps game, my form is blinking. In Call Of Duty 2, my form can't always on top (hide/in back of this game). Are you or anyone here know the solution? (sorry my bad english)

  20. #20
    VBAX Regular
    Joined
    Nov 2010
    Location
    Las Vegas Nv
    Posts
    74
    Location
    i'm not sure how to do it through VBA, but you can accomplish all of the goals in this thread with autoit very quickly and easily. check it out at autoitscript.com/autoiot3 there's another very helpful forum over there, and if you have any questions about the language feel free to message me here or there (my name there is cameronsdad)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •