?
Solved

Locking out keyboard keys (including the Windows key)

Posted on 2005-03-01
7
Medium Priority
?
256 Views
Last Modified: 2008-03-03
I'm creating a program for a display at a convetion.  I would like to leave the mouse and keyboard available to the user.  But I need to lock out all the keys except for the ones I need for navigation.  These keys (and key shortcuts) which are being locked out MUST include the Windows + D and Windows + E.  Is there a way in VB to lock these out?
0
Comment
Question by:lillockey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 37

Expert Comment

by:Harisha M G
ID: 13435422
0
 
LVL 28

Expert Comment

by:Ark
ID: 13436049
Hi

'=====bas module code====
Option Explicit
Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long
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 Const WH_KEYBOARD = 2

Global hHook As Long

Function KeyboardProc(ByVal idHook As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    If idHook < 0 Then
        KeyboardProc = CallNextHookEx(hHook, idHook, wParam, ByVal lParam)
    Else
       If wParam = Asc("A") Then
          KeyboardProc = 1
          If lParam > 0 Then MsgBox "[A] key disabled"
          Exit Function
       End If
       KeyboardProc = CallNextHookEx(hHook, idHook, wParam, ByVal lParam)
    End If
End Function

'========Form code======
Private Sub Form_Load()
    hHook = SetWindowsHookEx(WH_KEYBOARD, AddressOf KeyboardProc, App.hInstance, App.ThreadID)
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Dim l As Long
    If hHook Then
        l = UnhookWindowsHookEx(hHook)
        hHook = 0
    End If
End Sub

'Run sample and press [A] key
0
 
LVL 10

Expert Comment

by:Jini Jose
ID: 13436845
did you want to bloack the keys when your programm is running ?

jini
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:lillockey
ID: 13443873
qmailjini - yes

Ark - sorry, but I need to be able to block the Windows button.

mgh_mgharish - I'm not gonna give up yet
0
 
LVL 28

Accepted Solution

by:
Ark earned 2000 total points
ID: 13445463
0
 

Author Comment

by:lillockey
ID: 13449901
Ark ... that was fabulous.
If I can detect the keys being pressed, then I can stop them.  I thank you for your sample.  It will help me greatly in making my program.
0
 

Expert Comment

by:RAFAAJ
ID: 14616111
I tested the Code posted by ARK above and whenever I press a Key different from 'A', the whole application frezes !

Any idea why that happens ?

Regards.
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month14 days, 4 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question