Solved

Disable ctrl + P

Posted on 2006-11-23
8
1,458 Views
Last Modified: 2013-11-18
I want to disable control + P
in my web application so nobody can print from the web app.
This should be done through ieViewer object.
Problem with SHDocVW Internetexplorer PlugIn

with the ctrl + P print disable.
0
Comment
Question by:mathieu_cupryk
[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
8 Comments
 
LVL 1

Accepted Solution

by:
kulkarnivishwajit earned 500 total points
ID: 18005955
Hi,

You can try following code:

javascript code to disable return and enter keys

add this in page load

<script language="javascript" type="text/javascript">
function stopctrlPKey(evt) {
document.Form1.t1.value = 100;
var evt = (evt) ? evt : ((event) ? event : null);
var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
if ((evt.keyCode == 16) && (node.type=="text")) { return false}

This will identify Control + P ascill value i.e. 16 and do nothing if that key is pressed.

Regards,
kulkarnivishwajit
0
 
LVL 10

Expert Comment

by:gangwisch
ID: 18006097
try

WebBrowser1.WebBrowserShortcutsEnabled = False
0
 

Author Comment

by:mathieu_cupryk
ID: 18006119
I will try both guys.

but what does WebBrowser1.WebBrowserShortcutsEnabled = False?
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 1

Expert Comment

by:kulkarnivishwajit
ID: 18006142
Hi,

If we make WebBrowser1.WebBrowserShortcutsEnabled = False, then it will disable all the keyboard shortcuts. So I am wondering whether we should use only to disable printing ability.

Regards,
kulkarnivishwajit
0
 

Author Comment

by:mathieu_cupryk
ID: 18006156
Hi Kulk,

I don;t think it would be wise to diasable all the keyboard shortcuts.

http://www.devx.com/codemag/Article/20145/1954?pf=true

Is there another way?
0
 

Author Comment

by:mathieu_cupryk
ID: 18006180
Here is another example?

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=160976&SiteID=1

But I just need to disable the Ctrl+P
0
 

Author Comment

by:mathieu_cupryk
ID: 18006198
I am also talking to you gang, you must excuse me I am tired after 14 hour days.
0
 
LVL 6

Expert Comment

by:manch
ID: 18006598
'Just change the keys u want and Add the Handler of the Event Defined
' --------------------------------------------------
'  Class LowLevelKeyBoardhook
' --------------------------------------------------
Imports System.Runtime.InteropServices

'Note : This class wont work in IDE
'If u want to see the effects Execute the Application from bin

Public Class LowLevelKeyBoardhook

    Private Const HC_ACTION As Integer = 0
    Private Const WH_KEYBOARD_LL As Integer = 13
    Private Const WM_KEYDOWN As Integer = &H100
    Private Const WM_SYSKEYDOWN As Integer = &H104

    Public Structure KBDLLHOOKSTRUCT
        Public vkCode As Integer
        Public scancode As Integer
        Public flags As Integer
        Public time As Integer
        Public dwExtraInfo As Integer
    End Structure

    Private Declare Function SetWindowsHookEx Lib "user32" _
        Alias "SetWindowsHookExA" ( _
        ByVal idHook As Integer, _
        ByVal lpfn As LowLevelKeyboardProcDelegate, _
        ByVal hmod As Integer, _
        ByVal dwThreadId As Integer) As Integer

    Private Declare Function CallNextHookEx Lib "user32" ( _
        ByVal hHook As Integer, _
        ByVal nCode As Integer, _
        ByVal wParam As Integer, _
        ByVal lParam As KBDLLHOOKSTRUCT) As Integer

    Private Declare Function UnhookWindowsHookEx Lib "user32" ( _
        ByVal hHook As Integer) As Integer

    Private Delegate Function LowLevelKeyboardProcDelegate( _
        ByVal nCode As Integer, _
        ByVal wParam As Integer, _
        ByRef lParam As KBDLLHOOKSTRUCT) As Integer

    Private Declare Function GetAsyncKeyState Lib "user32" _
        (ByVal vKey As Integer) As Integer

    Public Event CtrlShiftF12()

    Private hhkLowLevelKeyboard As Integer
    Private keyboardDelegate As LowLevelKeyboardProcDelegate

    Public Sub New()
        keyboardDelegate = New LowLevelKeyboardProcDelegate(AddressOf Me.LowLevelKeyboardProc)
        hhkLowLevelKeyboard = SetWindowsHookEx(WH_KEYBOARD_LL, keyboardDelegate, _
            Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly.GetModules()(0)).ToInt32, 0)
    End Sub

    Private Function LowLevelKeyboardProc( _
        ByVal nCode As Integer, _
        ByVal wParam As Integer, _
        ByRef lParam As KBDLLHOOKSTRUCT) As Integer

        If (nCode = HC_ACTION) Then
            Select Case wParam
                Case WM_KEYDOWN, WM_SYSKEYDOWN
                    If GetAsyncKeyState(Keys.ControlKey) AndAlso _
                            GetAsyncKeyState(Keys.ShiftKey) AndAlso _
                            (lParam.vkCode = Keys.F12) Then
                        RaiseEvent CtrlShiftF12()
                    End If

            End Select
        End If

        Return CallNextHookEx(hhkLowLevelKeyboard, nCode, wParam, lParam)
    End Function

    Protected Overrides Sub Finalize()
        UnhookWindowsHookEx(hhkLowLevelKeyboard)
        MyBase.Finalize()
    End Sub

End Class


'Note : This class wont work in IDE
'If u want to see the effects Execute the Application from bin

' --------------------------------------------------
'  Class Form1
' --------------------------------------------------
Public Class Form1
    Inherits System.Windows.Forms.Form

    Private WithEvents llkb As New LowLevelKeyBoardhook

    Private Sub llkb_CtrlShiftF12() Handles llkb.CtrlShiftF12
        MsgBox("Ctrl-Shift-F12 Pressed ")
    End Sub

End Class

'For example execution the code witha  Form is provided

Try It (It is written for Key Combination Ctrl+Shit+F12 u can change it for Ctrl+p)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

726 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