Results 1 to 9 of 9

Thread: Pls help..How to disable "Print Scrn" button in VB application

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2000
    Posts
    26

    Question Pls help..How to disable "Print Scrn" button in VB application

    Hello,
    New to VB. I have a VB application. When the user is using this application, I would like to disable the usage of "Print Scrn" button. I mean if the user hits the "Print Scrn" button, he should not be able to capture the screen shots in the buffer. In the Form_Keypress event, I tried to capture the ascii value of the button. But I can capture all other buttons except "esc" "F1 F21", "Print Screen", "Scroll Lock", "Pause" buttons.
    Can someone point me the right direction..
    thank you
    nath

  2. #2
    Addicted Member rikshawdriver's Avatar
    Join Date
    Apr 2001
    Posts
    160
    You can trap the keycode in Form_KeyUp

    Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
    MsgBox KeyCode
    End Sub

    will return 44

  3. #3
    Addicted Member rikshawdriver's Avatar
    Join Date
    Apr 2001
    Posts
    160
    ..or

    Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
    If KeyCode = 44 or KeyCode = 106 Then
    Clipboard.Clear
    End If
    End Sub

  4. #4
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    Code:
    Private Declare Function GetAsyncKeyState _
    Lib "user32.dll" (ByVal vKey As Long) As Integer
    
    Private Const VK_MENU = &H12 'either alt key
    Private Const VK_SNAPSHOT = &H2C 'print screen
    
    
    Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
        If GetAsyncKeyState(VK_MENU) Then
            MsgBox "Alt key pressed"
        ElseIf GetAsyncKeyState(VK_SNAPSHOT) Then
            MsgBox "Print screen key pressed"
        End If
    End Sub

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Aug 2000
    Posts
    26

    Thankx to both of you..but..

    Thanks to you all. It works fine. As long my screen/form is active and if the user hits Print Screen button, the code works.

    But when the user shrinks my VB application (I mean the screen/form which has code) and is viewing other applications on the desktop and if hits the print screen button, he will get my VB Screen (which is shinked in size) and other application into the clipboard. How can I avoid this scenario.

    Could someone point me right direction please...

    thank you friends.
    nath

  6. #6
    Addicted Member rikshawdriver's Avatar
    Join Date
    Apr 2001
    Posts
    160
    When your application looses focus the control goes to Windows or another application on top. I do not know if windows can be configured to avoid printscreen. Someone pls help..

  7. #7
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    You will have to use system hook, but I am afraid its not possible in VB as it needs a standard dll to work(not an activex dll that is created using VB)

  8. #8
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    You don't need to use a system hook this simple code should do the trick and will work regardless of whether or not your app has focus...

    Code:
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    Private Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function EmptyClipboard Lib "user32" () As Long
    Private Declare Function CloseClipboard Lib "user32" () As Long
    
    Private Const VK_PRNTSCRN = &H2C
    
    Private Sub Form_Load()
        
        Me.Show
        
        Do Until DoEvents = 0
        
            If Not GetAsyncKeyState(VK_PRNTSCRN) = 0 Then
            
                OpenClipboard Me.hwnd
                EmptyClipboard
                CloseClipboard
                
            End If
            
        Loop
        
    End Sub
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Aug 2000
    Posts
    26

    Is it possible in a Browser

    Hello my friend

    Your piece of code works in VB .
    Thank you for that.

    Is it possible to implement same solution in a Browser?

    thank you
    bnath001

Posting Permissions

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



Click Here to Expand Forum to Full Width