🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.delphi.nativeapi
Article #12123

Re: Howto listen for key-event?

#12123
From: Peter Below (TeamB)
Date: Sun, 24 Nov 2002 09:04
55 lines
2484 bytes
In article <3de01f20@newsgroups.borland.com>, Tim Skau wrote:
> I want to listen for spesific key-pressed event/messages in Windows 2000.
> How can I do this?
> Can I assign the "printscreen" functionality to a different key?

type
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    Label2: TLabel;
  private
    { Private declarations }
    procedure wmHotkey( Var msg: TWMHotkey );
      message WM_HOTKEY;
    procedure WMActivate( Var msg: TWMActivate );
      message WM_ACTIVATE;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure tform1.wmHotkey( Var msg: TWMHotkey );
begin
  if msg.HotKey = IDHOT_SNAPWINDOW Then
    label1.caption := 'PrintScr pressed';
    // would print form from here
end;

procedure TForm1.WMActivate( Var msg: TWMActivate );
begin
  If msg.Active <> WA_INACTIVE Then
    RegisterHotkey( Handle, IDHOT_SNAPWINDOW, 0, VK_SNAPSHOT )
  Else begin
    UnRegisterHotkey( Handle, IDHOT_SNAPWINDOW );
    label1.caption := '';
  end;
  inherited;
end;

This would "hook" the key only while your form is the active form. But 
RegisterHotkey also works for a background application.

--
Peter Below (TeamB)  
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be
Technical Details
Message-ID: <VA.0000967b.005ca801@antispam.compuserve.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-06!sn-xit-04!supernews.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed1.cidera.com!Cidera!news.uni-x.net!newsgroups.borland.com!not-for-mail
References: <3de01f20@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f94dd,23c561d43814c3b4
X-Google-Attributes: gidf94dd,public
X-Google-ArrivalTime: 2002-11-24 01:15:38 PST
Date: Sun, 24 Nov 2002 10:04:08 +0100
Newsgroups: borland.public.delphi.nativeapi
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
X-Newsreader: Virtual Access by Atlantic Coast PLC, http://www.atlantic-coast.com/va
Organization: TeamB
Message-ID: <VA.0000967b.005ca801@antispam.compuserve.com>
Subject: Re: Howto listen for key-event?
From: "Peter Below (TeamB)" <100113.1101@compuXXserve.com>
Reply-To: 100113.1101@compuXXserve.com
References: <3de01f20@newsgroups.borland.com>
NNTP-Posting-Host: 172.185.191.136
X-Trace: newsgroups.borland.com 1038128637 172.185.191.136 (24 Nov 2002 01:03:57 -0800)
Lines: 57
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-06!sn-xit-04!supernews.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed1.cidera.com!Cidera!news.uni-x.net!newsgroups.borland.com!not-for-mail