Einzelnen Beitrag anzeigen

NicoDE
(Gast)

n/a Beiträge
 
#2

Re: @ bzw. Alt GR + Q abfangen

  Alt 31. Mär 2006, 10:16
Versuch's damit:
Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Controls, Forms, Dialogs;

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

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
const
  MOD_ALTGR = MOD_ALT or MOD_CONTROL; // [Alt Gr] ist intern [Alt+Strg]
begin
  FHotKeyID := GlobalAddAtom('MyUniqueHotKeyID');
  if 0 = FHotKeyID then
    ShowMessage('GlobalAddAtom: ' + SysErrorMessage(GetLastError()))
  else
    if not RegisterHotKey(Handle, FHotKeyID, MOD_ALTGR, Ord('Q')) then
      ShowMessage('RegisterHotKey: ' + SysErrorMessage(GetLastError()));
end;

procedure TForm1.WMHotKey(var Msg: TWMHotKey);
begin
  if Msg.HotKey = FHotKeyID then
    ShowMessage('@ gedrückt.');
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  if FHotKeyID <> 0 then
  begin
    UnregisterHotKey(Handle, FHotKeyID);
    GlobalDeleteAtom(FHotKeyID);
  end;
end;

end.
  Mit Zitat antworten Zitat