Autor Beitrag
The-FoX
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 203

Win XP
D6 Pers
BeitragVerfasst: So 16.05.04 23:03 
Hi,

Ich habe das Tutorial von Andreas Pfau gelesen, über die funktion RegisterHotkey. Ich möchte jetzt, dass der Benutzer selbst wählen kann welchen Hotkey er möchte.

Das sieht dann in etwa so aus:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
var b : string;
begin
b := form3.Memo1.lines[1];
RegisterHotKey(Handle, 2, MOD_SHIFT, Ord(b));
end;


Da bekomme ich aber leider inkompatible typen. Welche Variable muss ich wählen damit es klappt?
toms
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1099
Erhaltene Danke: 2



BeitragVerfasst: Mo 17.05.04 06:44 
Hi,

Probier's so:

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:
  private
    { Private declarations }
    Hotkey1: ATOM;
    procedure WMHotKey(var Msg: TWMHotKey); message WM_HOTKEY;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.WMHotKey(var Msg: TWMHotKey);
begin
  ShowMessage('Hotkey entdeckt.');
end;
procedure TForm1.FormCreate(Sender: TObject);
var
  KeyCode: Char;
begin
  Hotkey1 := GlobalAddAtom(PChar(ParamStr(0)+'Hotkey1'));
  KeyCode := form3.Memo1.lines[0][1];
  RegisterHotKey(Handle, Hotkey1, MOD_SHIFT , Ord(VKKeyScan(KeyCode)));
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  UnRegisterHotKey(Handle, 1);
  GlobalDeleteAtom(Hotkey1);
end;


Moderiert von user profile iconPeter Lustig: DF- durch Delphi-Tags ersetzt :lol: Was für ein Sucbegriff!
Karlson
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 2088



BeitragVerfasst: Mo 17.05.04 13:49 
toms hat folgendes geschrieben:
Hi,

Probier's so:

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:
  private
    { Private declarations }
    Hotkey1: ATOM;
    procedure WMHotKey(var Msg: TWMHotKey); message WM_HOTKEY;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.WMHotKey(var Msg: TWMHotKey);
begin
  ShowMessage('Hotkey entdeckt.');
end;
procedure TForm1.FormCreate(Sender: TObject);
var
  KeyCode: Char;
begin
  Hotkey1 := GlobalAddAtom(PChar(ParamStr(0)+'Hotkey1'));
  KeyCode := form3.Memo1.lines[0][1];
  RegisterHotKey(Handle, Hotkey1, MOD_SHIFT , Ord(VKKeyScan(KeyCode)));
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  UnRegisterHotKey(Handle, 1);
  GlobalDeleteAtom(Hotkey1);
end;



Hi, hab mal df in delphi geändert ;) Danke für die Antwort, genau das gleiche habe ich auch grad gesucht :)

Ich hätte aber nochmal ne Frage:
Was macht diese Zeile? Und wofür braucht man die?
Zitat:

Hotkey1 := GlobalAddAtom(PChar(ParamStr(0)+'Hotkey1'));


Also so wie ich das sehe gibt sie die ID für den Hotkey an. Aber warum auf dem weg und nicht einfacher?

edit: Hab einen kleinen Fehler entdeckt, es muss so heissen:
ausblenden Delphi-Quelltext
1:
RegisterHotKey(Handle, Hotkey1, MOD_SHIFT , Ord(KeyCode));					


Ohne das Vkkeyscan.
MathiasSimmack
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 17.05.04 15:09 
Karlson hat folgendes geschrieben:
Also so wie ich das sehe gibt sie die ID für den Hotkey an. Aber warum auf dem weg und nicht einfacher?

Aus dem Platform SDK von Microsoft:
Zitat:
The GlobalAddAtom function adds a character string to the global atom table and returns a unique value (an atom) identifying the string.

Mit anderen Worten: Auf der Basis des Dateinamens und des Begriffs "Hotkey1" generiert toms eine einzigartige ID, die es im ganzen System dann nur dieses eine Mal gibt.

@toms: Das ist ja mal ein langer Suchbegriff. :mrgreen: