Autor Beitrag
jaenschi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 89

Win XP, Debian
D7
BeitragVerfasst: Fr 07.01.05 11:05 
Hallo,
Ich hab mit Hilfe der Beispiele aus diesem Forum zum Thema Hotkeys mal folgendes Programm geschrieben. Es soll die Tasten F1 -
F11 als Hotkeys registrieren und beim Drücken der F1-Taste die Farbe des Programmfensters ändern und eine Nachricht ausgeben.
Allerdings passiert das nur, wenn ich alle Tasten, die ich registriert hab drücke, das heißt, dass ich die Tasten F1 bis F11 nacheinander drücken muss, damit eben meine erwünschte Meldung kommt.
Wo steckt da der Fehler?

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:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
unit F-Tasten;

interface

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

var
  HotKeyId : array[1..11] of integer;

type
  TForm1 = class(TForm)
    ApplicationEvents1: TApplicationEvents;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private-Deklarationen }
    procedure WmHotkey(var Msg: TMessage); message WM_HOTKEY;
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}


procedure TForm1.WmHotkey(var Msg: TMessage);
var i:integer;
begin
  if (Msg.WParam = HotKeyId[1]) then
  begin
    Form1.Color:=clblue;
    showmessage('F1-Taste gedrückt!');
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var i:integer;
begin
  for i:=1 to 11 do
  begin
  if (not RegisterHotKey(Handle, HotKeyId[i], 0, VK_F1+i-1)) then
    ShowMessage('Der Hotkey konnte nicht registreiert werden.');
  end;
end;

procedure TForm1.FormDestroy(Sender: TObject);
var i:integer;
begin
  for i:=1 to 11 do
  UnregisterHotKey(Handle, HotKeyId[i]);
end;

end.


THX
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Fr 07.01.05 11:12 
Kann man einer Form überhaupt mehrere HotKeys zuweisen :gruebel:
Probier mal nur F11.
Eventuell hat deine Routine nur den letzten HotKey zugewiesen (nämlich F11).
Wenn du dann alle durch probiert hast, passiert bei F1 - F10 nichts und erst F11 funktioniert.
jaenschi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 89

Win XP, Debian
D7
BeitragVerfasst: Fr 07.01.05 11:22 
Hab das mal so gemacht, wie du das gemeint hast und wenn ich nur F11 benutze funktioniert das tatsächlich. :D thx

Nur dann frag ich mich, wie die Giga-F-Tasten-Programme funktionieren.
Weil hier hat RoterFruchtZwerg behauptet, dass er das mit Delphi und RegisterHotKey gemacht hat.
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Fr 07.01.05 11:29 
Für Hotkeys gilt:
Zitat:

Wer zu erst kommt, mahlt zu erst.

Sprich, hat ein Programm vor deinem schon einen Hotkey registriert, kannst du ihn nicht für dein Programm Registrieren.
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Fr 07.01.05 11:33 
Dann hat RoterFruchtZwerg gelogen.
Die Delphi-Hilfe schreibt:
Zitat:
If the window identified by the hWnd parameter already registered a hot key with the same identifier as that specified by the id parameter, the new values for the fsModifiers and vk parameters replace the previously specified values for these parameters.
jaenschi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 89

Win XP, Debian
D7
BeitragVerfasst: Fr 07.01.05 11:37 
Gibt es dann noch eine andere Möglichkeit ALLE F-Tasten abzufangen.
Mit Hooks würde das zwar gehen, dann würde die Nachricht aber trotzdem weiter gesendet werden!?
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Fr 07.01.05 11:42 
Schau dir mal OnKeyDown an.
jaenschi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 89

Win XP, Debian
D7
BeitragVerfasst: Fr 07.01.05 11:43 
Die Hotkeys sollten aber Systemweit registriert werden^^
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Fr 07.01.05 11:45 
jasocul hat folgendes geschrieben:
Dann hat RoterFruchtZwerg gelogen.
Die Delphi-Hilfe schreibt:
Zitat:
If the window identified by the hWnd parameter already registered a hot key with the same identifier as that specified by the id parameter, the new values for the fsModifiers and vk parameters replace the previously specified values for these parameters.

Das gilt für den Prozess! Das PSDKL sagt dazu:
Zitat:

RegisterHotKey fails if the keystrokes specified for the hot key have already been registered by another hot key.
jaenschi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 89

Win XP, Debian
D7
BeitragVerfasst: Fr 07.01.05 11:49 
Und was bedeutet das für mich?
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Fr 07.01.05 11:51 
Das steht so auch in der Delphi-Hilfe.
Aufgrund seines Beschreibung, habe ich das andere Problem vermutet.
@jaenschi:
Lies dir nochmal genau die Hilfe zu der Funktion durch. Dann siehst alle möglichen Hinweise selbst.
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Fr 07.01.05 13:03 
Also wenn ich mir den Code so anschau vermut ich den Fehler eher woanders... nämlich bei der Hotkey-ID!

Du hast ein globales Array für die IDs der Hotkeys. Dieses Array verwendest du um die Hotkeys zu registrieren und in der Abfrage wenn eine Hotkey-Message ankommt. ABER... wo initialisierst du dieses Array?? Soweit ich seh gar nicht, also registrierst du alle Hotkeys mit derselben ID nämlich 0. Und deswegen tritt dann das ein:
PSDK hat folgendes geschrieben:
If the window identified by the hWnd parameter already registered a hot key with the same identifier as that specified by the id parameter, the new values for the fsModifiers and vk parameters replace the previously specified values for these parameters.

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
matze.de
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 576

Win95, Win98 SE, WinXp Prof SP2
D7P, D8P, FPC2.0
BeitragVerfasst: Fr 07.01.05 13:09 
MSDN sagt zu id:
Zitat:

id
[in] Specifies the identifier of the hot key. No other hot key in the calling thread should have the same identifier. An application must specify a value in the range 0x0000 through 0xBFFF. A shared dynamic-link library (DLL) must specify a value in the range 0xC000 through 0xFFFF (the range returned by the GlobalAddAtom function). To avoid conflicts with hot-key identifiers defined by other shared DLLs, a DLL should use the GlobalAddAtom function to obtain the hot-key identifier.


mfg matze

_________________
si tacuisses, philosophus mansisses.


Zuletzt bearbeitet von matze.de am Fr 07.01.05 13:16, insgesamt 1-mal bearbeitet
jaenschi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 89

Win XP, Debian
D7
BeitragVerfasst: Fr 07.01.05 13:12 
THX @motzi das wars.
ich hab das jetzt direkt mit
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
  for i:=1 to 11 do
  begin
  if (not RegisterHotKey(Handle, i, 0, VK_F1+i-1)) then
    ShowMessage('Der Hotkey '+IntToStr(i)+'konnte nicht registreiert werden.');
  end;

gemacht und es geht! THX
RFZ
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 137

WinME, WinXP, Win2k*, Win98*, Win95*, Win3.11*, DOS* (*VMware)
D4 Prof
BeitragVerfasst: Fr 11.02.05 23:50 
Nabend,
das Problem scheint zwar gelöst, aber ich kann ja einfach mal meinen Quelltext drunter klatschen, da hier ja schon über mein Programm gesprochen wurde:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
  for i := 1 to 12 do
  begin
    HotkeyIds[i] := GlobalAddAtom(PChar('Hotkey'+InttoStr(i)));  // HotkeyIds: Array[1..12] of Integer;
    RegisterHotKey(Handle, HotkeyIds[i], 0, i+ VK_F1 - 1);
  end;


Dieser Quelltext stammt im übrigen ursprünglich aus diesem Forum :)

greetz RoterFruchtZwerg / RFZ