Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Locking out keyboard keys (including the Windows key)

Posted on 2005-03-01
7
Medium Priority
?
258 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
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month10 days, 22 hours left to enroll

572 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