Link to home
Start Free TrialLog in
Avatar of dreamvb
dreamvb

asked on

Disable Keyboard keys.

hi Experts

Can someone please tell me how to disable keys on the keyboard this needs to disable the keys for the WebBroswer control. anyway I have make an eBook Compiler in Visual Basic and I am useing the WebBroswer to show the pages.

in my ebook compiler I have many options one of them is to disable the user from printing. but am haveing problums as the user can simply press the keys CTRL + P and this then brings up the print dialog box. is there anyway I can stop this from happing.

Thank you,
Avatar of Mike McCracken
Mike McCracken

Have you tried trapping for it in the control's keypress event?

I am not sure whether a ctrl-p is trapped by Windows before it is passed to you.

mlmcc
Avatar of dreamvb

ASKER

It does not have any keypress events.
you need to use a hook to make your app process all keyboard messages.  this is some code laying around EE here.

'IN A SUB!!!!!!!!!!!!!!!!!!
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
   
Private Const GWL_WNDPROC = -4
Private lpPrevWndProc As Long
Public gHW As Long
Public IsHooked As Boolean
   
Private Const WM_MOUSEFIRST = &H200
Private Const WM_MOUSELAST = &H209
Private Const WM_KEYFIRST = &H100
Private Const WM_KEYLAST = &H108
   
   
Public Sub Hook()
    If IsHooked Then
        MsgBox "Don't hook it twice without unhooking, or you will be unable to unhook it."
    Else
        lpPrevWndProc = SetWindowLong(gHW, GWL_WNDPROC, AddressOf WindowProc)
        IsHooked = True
    End If
End Sub
   
Public Sub Unhook()
    Dim temp As Long
    temp = SetWindowLong(gHW, GWL_WNDPROC, lpPrevWndProc)
    IsHooked = False
End Sub
   
Function WindowProc(ByVal hw As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Debug.Print "Message: "; hw, uMsg, wParam, lParam
   
    Select Case uMsg
        Case 258
            If wParam = 16 Then
                ' don't pass messages
                Exit Function
            Else
                WindowProc = CallWindowProc(lpPrevWndProc, hw, uMsg, wParam, lParam)
            End If
        Case Else
            WindowProc = CallWindowProc(lpPrevWndProc, hw, uMsg, wParam, lParam)
    End Select
End Function

'-----

That will make sure that ctrl + p doesnt get sent through the hooked object.
ASKER CERTIFIED SOLUTION
Avatar of RocketMan801
RocketMan801

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dreamvb

ASKER

Hi Thanks this is just what I needed.

Thanks, Agian.