Link to home
Start Free TrialLog in
Avatar of peed112097
peed112097

asked on

Disabling printscreen

Can anyone show me how to disable the print screen event.
There are two ways I guess, either through Application.OnMessage
or through theWMSysCommand(var message...

I'd like the second since the first would slow the application down.

Please anyone!
Avatar of pjdb
pjdb

I think that the print screen does not go to the application since it is handle by the system to copy all the screen.
The only way i see to do it is to hook to the clipboard to be notifyed of he changes and clear it if the content is a copy of the screen.
JDB
Avatar of peed112097

ASKER

Ok, maby I did'nt make my self clear. I'm not interested in disabling the printscreen, all I want is that when hitting the printscreen key, nothing in my application should be printed.

/Per
There is a component in the RXLibrary that can view the clipboard...it might be useful to you in some way ..

Regards,
Viktor Ivanov
You might wanna hook the window with the the keyboard hook, and if that key is pressed then do nothing,,,,

Regards,
Viktor Ivanov
You might wanna hook the window with the the keyboard hook, and if that key is pressed then do nothing,,,,

Regards,
Viktor Ivanov
Can you show me with an examle on the keyboard hook?
ASKER CERTIFIED SOLUTION
Avatar of ZifNab
ZifNab

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
function KeyBoardCallback (Code : Integer; WParam : Word;
   LParam : Longint) : LongInt;
   begin
     Result := 0;
     // Check to see if it's the hot key ..here is the secret to get the key
   if Lo(wParam) = VK_SNAPSHOT then
     begin
     //Do your code here.....
      ShowMessage('Hot key pressed');
   Result := 1;
   end;
   CallNextHookEx(gHook, code, Wparam, Lparam);
   end;
-==============To hook===============-
   gHook := SetWindowsHookEx(WH_KEYBOARD, @ClueCardKeyBoardCallback,
   HInstance, GetCurrentThreadId);
   If (gHook = 0) then ShowMessage('Not Hooked');
-==============To unhook===============-
   { This unhooks the hook }
   If not(UnHookWindowsHookEx(gHook)) then
   ShowMessage('Couldnt Unhook');
--------------
It would be something similar to this.....I hope it helps =)

Regards,
Viktor Ivanov

Here's an example from borland.com:

The PrintScreen system key is not processed during the TForm
keydown event. The following example tests if the PrintScreen key has
been pressed by calling the Windows API function GetAsyncKeyState()
during the Application.OnIdle event.

Example:

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    procedure AppIdle(Sender: TObject; var Done: Boolean);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.OnIdle := AppIdle;
end;

procedure TForm1.AppIdle(Sender: TObject; var Done: Boolean);
begin
  if GetAsyncKeyState(VK_SNAPSHOT) <> 0 then
  Form1.Caption := 'SnapShot';
  Done := True;
end;

/// John
And here's another:

The following example demonstrates registering a hot key with the
system to globally trap the windows printscreen key.

Example:

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
    procedure WMHotKey(var Msg : TWMHotKey); message WM_HOTKEY;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

const id_SnapShot = 101;

procedure TForm1.WMHotKey (var Msg : TWMHotKey);
begin
  if Msg.HotKey = id_SnapShot then
  ShowMessage('GotIt');
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  RegisterHotKey(Form1.Handle,
    id_SnapShot,
    0,
    VK_SNAPSHOT
  );
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  UnRegisterHotKey (Form1.Handle, id_SnapShot);
end;

/// John