Autor Beitrag
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Mo 22.02.10 02:35 
Hi,

ich hab da ein Problem, bei dem es mich etwas wundert, dass die VCL dafür keinerlei vernünftige Kapselung bietet.

Folgendes: ich möchte auf ein Tastenkürzel reagieren. Konkret Ctrl-C, zum Kopieren, aber das ist erstmal egal.

Das Problem ist, sämtliche Varianten werden so lange gefeuert solange die Tasten unten sind, nicht nur einmal beim Drücken.
Probiert habe ich OnKeyDown, OnShortCut, PopupMenu/ActionList-Shortcuts, selbst RegisterHotKey.

Wie kann man das erreichen, dass nur der allererste Druck zählt? Mit Flags rumhantieren erweist sich auch als schwierig, da ich z.B. STRG-C, C loslassen (und STRG gedrückt halten), C wieder drücken als 2 Ereignisse haben will.

Gibt es da was unbekanntes fertiges? Wenn nicht, wie kann man das vernünftig lösen?
Kann doch eigentlich nicht sein, dass man so elementare Funktionen immer von Hand programmiert oder alternativ die Aktion permanent ausführt?

Danke,
Martok

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mo 22.02.10 03:59 
Key-Hook drauf ansetzen, und alle Tasten einzeln mitzählen; Statemaschine dahinter, die dir die Anzahl der Tastendrücke bearbeitet und als eigene Ereignisse raushaut.

Sprich:
- Strg drücken --> Event
- C drücken --> Event
- C loslassen --> Event
- C drücken --> Event
- C loslassen --> Event
- Str loslassen --> Event

Die Auswertung in der Form kannst Du bereits in OnKeyDown und OnKeyUp problemlos über den ShiftState und den Keycode machen.. Der Rest ergibt sich.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
jakobwenzel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: Mo 22.02.10 10:47 
Wenn ich mich jetz nich komplett irre gibts im TActionManager ne passende Action. :wink:

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
Martok Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Mi 24.02.10 00:40 
Danke für eure Hilfe. Gut, dass man immer die Antworten bekommt nach denen man fragt :roll:

Fürs Archiv:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.FormShortCut(var Msg: TWMKey; var Handled: Boolean);
begin
  if ((GetAsyncKeyState(VK_CONTROL) and $8000)>0) and   // CTRL gedrückt
     (Msg.CharCode=ord('C')) and                        // C gedrückt
     ((Msg.KeyData and $40000000)=0) then begin         // KEIN Repeat-Ereignis
    Handled:= true;                                     // nicht weiterleiten
    ShowConsole(DateTimeToStr(now)+'  Aktion');         // Kopieren etc.
  end;
end;



(Der Highlighter hat einen Bug. Im Code sind die Kommentare korrekt ausgerichtet...)

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."