Autor Beitrag
MephistoFFF
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 60

Win 7

BeitragVerfasst: Fr 08.08.08 11:29 
Hallo!

Ich hab vor kurzem einen Taschenrechner programmiert. Also einen ganzen simplen - wie der WIndows Taschenrechner im StandartModus... halt zum "üben"

Jetzt wollte ich das Ding auch per Numpad steuern können... geht soweit auch... mit Onkeydown...

ausblenden Delphi-Quelltext
1:
2:
3:
4:
if (key = VK_DIVIDE) then B_DurchClick(B_Durch);
if (key = VK_SUBTRACT) then B_MinusClick(B_Minus);
if (key = VK_ADD) then B_PlusClick(B_Plus);
if (key = VK_Multiply) then B_MalClick(B_Mal);


Das funktioniert wunderbar, aber
ausblenden Delphi-Quelltext
1:
if (key = VK_RETURN) then B_ErgebnisClick(B_Ergebnis);					

funktioniert eben nicht. Da kann ich "enter" drücken wie ich will, er macht nur einen "klick" auf den aktuell aktiven button... die hotkey-funktion funktioniert aber nicht.

Was hab ich ich falsch gemacht, bzw vergessen?

Bin für jede Hilfe dankbar.

mfG
Hidden
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2242
Erhaltene Danke: 55

Win10
VS Code, Delphi 2010 Prof.
BeitragVerfasst: Fr 08.08.08 11:58 
Hi,

Erstmal ein Vorschlag: Du kannst deine vielen If-Abfragen durch eine Case-Verzweigung ersetzen ;)

Nun zu deinem Problem: Es gibt unter den Eigenschaften der Form eine Eigenschaft 'KeyPreview', das sollte helfen.

Es wäre allerdings performanter, ein Edit-Feld zu verwenden; dort könnte der User den Therm dann eintippen und mit Enter bestätigen ;)

mfG,

_________________
Centaur spears can block many spells, but no one tries to block if they see that the spell is a certain shade of green. For this purpose it is useful to know some green stunning hexes. (HPMoR)
MephistoFFF Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 60

Win 7

BeitragVerfasst: Fr 08.08.08 12:01 
KeyPreview ist aktiviert, ist es deaktiviert geht garkein Hotkey mehr.

Und das mit dem Therm eingeben... so wollte ich das eben grade nicht^^
Hidden
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2242
Erhaltene Danke: 55

Win10
VS Code, Delphi 2010 Prof.
BeitragVerfasst: Fr 08.08.08 15:01 
Hi,

Eventuell bringt ein Wechsel auf ein anderes Key-Event etwas.. Definitiv solltest du den Key danach aber zerstören(Key := #0), da sonst zusätzlich der Button betätigt wird.

Imho ist das übrigens immernoch der falsche Ansatz: Ein Term wird nicht über Hotkeys eingegeben, sondern über ein Edit-Feld. Hotkeys sind wirklich nur für Shortcuts da :?

mfG,

_________________
Centaur spears can block many spells, but no one tries to block if they see that the spell is a certain shade of green. For this purpose it is useful to know some green stunning hexes. (HPMoR)
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Fr 08.08.08 15:05 
@Hidden: Dafür sind doch grad die Tasten auf dem Nummernblock da - und Hotkeys sind das nicht. Außerdem schon den Win-Taschenrechner benutzt? Dort kann man ebenfalls die Tasten auf dem Nummernblock verwenden. Die Tastatur-Macher haben ja auch nicht umsonst da Rechenzeichen draufgemalt.

EDIT: Achso, warum Enter nicht geht: Weil Enter kein Ereignis auslöst. Siehe Delphi-Hilfe zu "KeyPreview".

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Fr 08.08.08 15:45 
Hallo,

das Auslösen des OnClick-Events des Buttons der den Focus hat ist Windows-Standard, und auch gut so. In dem Fall wird der Key direkt an den Button geschickt, er wird auch bei KeyPreview = True nicht erkannt. Wenn man das verhindern will muss man sich vorher einklinken(Stichwort CM_DIALOGKEY) oder dafür sorgen das kein Button den Focus hat, z.B. Focus auf ein Edit setzen.

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
MephistoFFF Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 60

Win 7

BeitragVerfasst: Fr 08.08.08 15:49 
das mit dem fokus klingt gut... und wie funktioniert das beides? also den fokus setzen und das mit dem dialogkey?

mfG
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Fr 08.08.08 20:14 
Hallo,

4 Minuten, hast ja lange mit dem Stichwort, das ich Dir gegeben habe, gesucht :?
Ich hab hier im Forum schon mal einen Code dazu gepostet, sollte man finden können.
:arrow: VK_TAB geht nicht (fast) alle anderen schon


zur Alternative :arrow: z.B. Edit1.SetFocus;

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
MephistoFFF Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 60

Win 7

BeitragVerfasst: Sa 09.08.08 12:30 
Danke für die Hilfe.

Allerdings funtioniert das noch nicht so richitg. Wenn ich die Procedure so einbaue wie du es beshcirben hast, dann funktioniert die Tast auch, allerdings nur solnage ich nicht anderes im Programm gemacht habe... also nach dem starten drücke ich Enter auf dem Nummerblock und es kommt ne Message ( zum testen ) ... sobald ich aber irgendwas anderes mache funktioniert die entertaste nicht mehr...

mfG
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Sa 09.08.08 19:41 
Hallo,

user profile iconMephistoFFF hat folgendes geschrieben:
...allerdings nur solnage ich nicht anderes im Programm gemacht habe...
... sobald ich aber irgendwas anderes mache funktioniert die entertaste nicht mehr...
könntest Du das näher erläutern, mit den Infos kann man wenig anfangen :nixweiss:

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
MephistoFFF Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 60

Win 7

BeitragVerfasst: Sa 09.08.08 23:00 
Also, ich habe die procedur für das abfangen der standartfunktion + zuweisen neuer funktion für die entertaste genau so, wie es in deinem verlinkten thread stand, "eingabaut"...

zum test habe ich auf die entertaste einen "showmessage" befehl gelegt.
Wenn ich das programm jetzt starte und nichts anklicke bzw mache, dann funktioniert die entertaste und die message wird angezeigt. Drücke ich jetzt allerdings irgendeinen button oder eine andere taste auf dem nummernblock funktioniert die funktion der entertaste danach nicht mehr.

Ich hoffe du verstehst mein problem^^

danke im vorraus

mfG
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Sa 09.08.08 23:15 
Hallo,

kannst Du Deinen Code hier mal reinsetzen, wenn es zuviel ist, dann als Anhang.
Ich schau mir das dann mal an.

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
MephistoFFF Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 60

Win 7

BeitragVerfasst: So 10.08.08 00:03 
Ok, hier mal das komplette Zeugs... wie gesagt, es ist nix besonderes... nur zum rumprobieren und "üben" ^^

( Es gibt bestimmt einiges was man hätte weniger umständlich lösen können^^ )
Einloggen, um Attachments anzusehen!
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: So 10.08.08 01:37 
Hallo,

Du nutzt in Deinem Code beide Varianten die ich vorgeschlagen habe.
Nimm das SetFocus mal raus, dann funktioniert es.

Bei jedem Botton-Click setzt Du den Focus auf das Edit.
Die Eigenschaft Edit.WantReturns hast Du auf True stehen, also wird der Enter-Key dort aufgefangen, ist also sozusagen kein DialogKey mehr.

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
MephistoFFF Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 60

Win 7

BeitragVerfasst: So 10.08.08 10:27 
Ok, das mit dem Fokus werde ich mal rausnehmen...

Gibt es irgendeine möglichkeit den fokus zu deaktivieren? weil ich finde es nicht grade optisch schön wenn ein button anders aussieht als alle anderen, eben weil er fokusiert ist...

Danke^^

mfG
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: So 10.08.08 12:24 
Hallo,

indem Du den Focus auf eine andere Komponente setzt(SetFocus) oder:
ausblenden Delphi-Quelltext
1:
ActiveControl := nil;					

dann ist keine Komponente focusiert.

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )