Link to home
Start Free TrialLog in
Avatar of lilaudrey
lilaudrey

asked on

disable print screen

I am trying to find a way within VB to disable the print screen key within my application.  I have secure information displayed and I don't want users to be able use the print screen key and then go into another application and paste and print information.  I only want this to be for this application and I don't want to disable the cut and paste for other applications they may have running.  Any ideas?
Avatar of ChrisLewis
ChrisLewis

You cannot disable the printscreen key in VB, but here's the start of a work around.

You can try this to start.

In a form with Keypreview set to TRUE...

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
  Debug.Print "UP:" & KeyCode
  If KeyCode = vbKeyPrint Or vbKeySnapshot Then
    Clipboard.Clear
    MsgBox "No Print Screens!"
  End If

End Sub

This doesn't eliminate the printScreen, just immediately clears the copy buffer.  This, however, has some problems.  It only works if your form has focus.  If it's visible in the background, PrintScreen will still work.

Ways around this include minimizing the form when it looses forcus,  and also setting the form on top always.

To minimize on non use, try this.

Set a timer  in the form, with the following code. (interval real low - 2 or 3 based on processing needs)  

Private Sub Timer1_Timer()
  DoEvents
  Select Case apiGetFocus()
    Case Me.hWnd
    Case Text1.hWnd
    Case Text2.hWnd
    Case Command1.hWnd
    Case Else
      Me.WindowState = vbMinimized
  End Select
End Sub
You will have to put a line for each control on your form!

Ad a declare in a module:
Declare Function apiGetFocus Lib "user32" Alias "GetFocus" () As Long

This should work, even though it's kinda clunky

Hope this helps

Chris
Avatar of lilaudrey

ASKER

The first part works great, however the part on minimizing when it looses focus does not work.  Could this have something to do with the fact that we are using 16 bit VB instead of 32.  It bombs using your method on some DLL file.  I need both parts to work if I am to use this solution.    Thanks
ASKER CERTIFIED SOLUTION
Avatar of ChrisLewis
ChrisLewis

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
Thanks,  I will try that and let you know if it works.  I agree it is sort of a weird solution but if it works it will be a great help in solving my security problem and will allow us to implement.
Chris,
This doesn't seem to work either.  I do not have a user.dll.  Is this  my problem and if so could you send me one at acampbell @ppg.com