Autor Beitrag
R4id
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 28

Win XP Home, Win XP Prof.
D7 Prof., D2006 Arch., BCB2006 Arch.
BeitragVerfasst: Do 27.08.09 01:06 
Hallo.

Ich will merken, wie man über RegisterHotkey usw. merken kann wann VK_SPACE gedrückt bzw. losgelassen wird.

Ich hab im moment folgenden Code:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
  private
    FHotKeyID: TAtom;
    procedure WMKeyDown(var Msg: TWMKeyDown); message WM_KEYDOWN;
    procedure WMKeyUp(var Msg: TWMKeyUp); message WM_KEYUP;

[...]

procedure TForm1.FormCreate(Sender: TObject);
begin
  FHotKeyID := GlobalAddAtom('MyUniqueHotKeyID');
  if 0 = FHotKeyID then
    ShowMessage('GlobalAddAtom: ' + SysErrorMessage(GetLastError()))
  else
    if not RegisterHotKey(Handle, FHotKeyID, 0, Ord(' ')) then
      ShowMessage('RegisterHotKey: ' + SysErrorMessage(GetLastError()));
end;

procedure TForm1.WMKeyDown(var Msg: TWMKeyDown);
begin
  if Msg.CharCode = FHotKeyID then
    ShowMessage('down');
end;

procedure TForm1.WMKeyUp(var Msg: TWMKeyUp);
begin
  if Msg.CharCode = FHotKeyID then
    ShowMessage('up');
end;

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


Ich bekomms irgentwie nich auf die reihe :gruebel:

Gruß
rd3
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Do 27.08.09 10:50 
das hat bei mir funktioniert:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
unit Unit2;

interface

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

type
  TForm2 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    ID: Integer;
    procedure WMHotKey(var Msg: TWMHotKey); message WM_HOTKEY;
  public

    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.FormCreate(Sender: TObject);
begin
  // Space
  ID := GlobalAddAtom('Hotkey1');
  RegisterHotKey(Handle, ID, 0, VK_SPACE);
end;

procedure TForm2.FormDestroy(Sender: TObject);
begin
  UnRegisterHotKey(Handle, ID);
  GlobalDeleteAtom(ID);
end;

procedure TForm2.WMHotKey(var Msg: TWMHotKey);
begin
  if Msg.HotKey = ID then
    ShowMessage('Space wurde gedrückt!');
end;

end.


EDIT: Das mit dem loslassen habe ich überlesen...

---Moderiert von user profile iconNarses: Beiträge zusammengefasst---

s. auch www.swissdelphicente.../showcode.php?id=147
R4id Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 28

Win XP Home, Win XP Prof.
D7 Prof., D2006 Arch., BCB2006 Arch.
BeitragVerfasst: Do 27.08.09 12:04 
Diesen Hotkey zu registrieren funktioniert ja, ich will nur eine seperate Procedure für KeyDown und KeyUp.
Nicht die KeyDown/KeyUp funktion der TForm

---Moderiert von user profile iconNarses: Beiträge zusammengefasst---

Keine ne Idee? :(
Boldar
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1555
Erhaltene Danke: 70

Win7 Enterprise 64bit, Win XP SP2
Turbo Delphi
BeitragVerfasst: Do 27.08.09 20:47 
Schreib einen globalen getmessage hook, damit dürfte das gehen, da hatte ich mal ein Beispiel (Ich findes aber grade leider nicht mehr).
Siehe dazu assarbads Hook und IPC Tutorial.
Vielleicht reicht dir auch ein einfacher Keybordhook.
mfg Boldar