Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Key in ComboBox (https://www.delphipraxis.net/130008-key-combobox.html)

thomas2009 1. Mär 2009 21:21


Key in ComboBox
 
Hallo

wie kann ich keys wie F1, F2 oder wie VK_LEFT in ComboBox eingeben ?
Mit Buchstaben und Zahlen wie 0,1,2, A,B,C funktioniert :
Delphi-Quellcode:
...
key := Ord(Combobox1.Items[Combobox1.ItemIndex][1]);

sx2008 2. Mär 2009 06:12

Re: Key in ComboBox
 
Das geht nicht, da es im Windows Zeichensatz diese Tastencodes nicht gibt.
Aber es gibt die Komponente THotKey (Auf Seite "Win32") mit der man Tastendrücke wie z.B. Shift-F12 aufzeichnen kann.
Diesen Hotkey kann man dann z.B. einer Action zuweisen.

thomas2009 2. Mär 2009 11:46

Re: Key in ComboBox
 
Es gibt aber bestimmt ein Trick
schaue hier, wo einige Programme den Combobox verwenden:
http://www.smartsoundrecorder.com/onlinehelp/hotkey.png

Luckie 2. Mär 2009 12:13

Re: Key in ComboBox
 
Das werden ganz normale Eingaben sein wie: "[F1]".

Satty67 2. Mär 2009 12:35

Re: Key in ComboBox
 
Evtl. so lösen:
Delphi-Quellcode:
  if Combobox1.Items[Combobox1.ItemIndex] = '[ LINKS ]' then key := vk_Left;

thomas2009 2. Mär 2009 12:40

Re: Key in ComboBox
 
Zitat:

Zitat von Luckie
Das werden ganz normale Eingaben sein wie: "[F1]".

Ich habe gerade in ComboBox den Wert [F1] eingegeben und getestet aber es funktioniert nicht

Meflin 2. Mär 2009 12:42

Re: Key in ComboBox
 
Zitat:

Zitat von thomas2009
Ich habe gerade in ComboBox den Wert [F1] eingegeben und getestet aber es funktioniert nicht

Bei dir? Nein, natürlich funktioniert das nicht. dazu müsstest du ja erst noch die Funktionalität ergänzen...

DeddyH 2. Mär 2009 12:42

Re: Key in ComboBox
 
Was hast Du wo wie eingegeben und was funktioniert nicht?

Luckie 2. Mär 2009 12:42

Re: Key in ComboBox
 
Was willst du denn eingeben? Bei deinem Beispiel dient die Combobox der Auswahl.

Satty67 2. Mär 2009 12:53

Re: Key in ComboBox
 
Vielleicht wird es deutlicher, wenn ich seine Code-Zeile mit rein nehmen:
Delphi-Quellcode:
// Hier Spezialtasten auswerten
if Combobox1.Items[Combobox1.ItemIndex] = '[F1]' then key := vk_F1
  // ansonsten normale Zeichen
  else key := Ord(Combobox1.Items[Combobox1.ItemIndex][1]);

thomas2009 2. Mär 2009 13:28

Re: Key in ComboBox
 
Nun funktioniert :
Delphi-Quellcode:
//...
             if Combobox1.Items[Combobox1.ItemIndex] = 'F1' then begin key := vk_F1; end
        else if Combobox1.Items[Combobox1.ItemIndex] = 'F2' then begin key := vk_F2; end
        else if Combobox1.Items[Combobox1.ItemIndex] = 'F3' then begin key := vk_F3; end
        else if Combobox1.Items[Combobox1.ItemIndex] = 'F4' then begin key := vk_F4; end
        else if Combobox1.Items[Combobox1.ItemIndex] = 'F5' then begin key := vk_F5; end
        else if Combobox1.Items[Combobox1.ItemIndex] = 'F6' then begin key := vk_F6; end
        else if Combobox1.Items[Combobox1.ItemIndex] = 'F7' then begin key := vk_F7; end
        else if Combobox1.Items[Combobox1.ItemIndex] = 'F8' then begin key := vk_F8; end
        else if Combobox1.Items[Combobox1.ItemIndex] = 'F9' then begin key := vk_F9; end
        else if Combobox1.Items[Combobox1.ItemIndex] = 'F10' then begin key := vk_F10; end
        else if Combobox1.Items[Combobox1.ItemIndex] = 'F11' then begin key := vk_F11; end
        else if Combobox1.Items[Combobox1.ItemIndex] = 'F12' then begin key := vk_F12; end

        else if Combobox1.Items[Combobox1.ItemIndex] = 'RETURN' then begin key := VK_RETURN; end
        else if Combobox1.Items[Combobox1.ItemIndex] = 'SPACE' then begin key := VK_SPACE; end
// ...
        else if Combobox1.ItemIndex < 35 then begin

          key := Ord(Combobox1.Items[Combobox1.ItemIndex][1]); end;

jaenicke 2. Mär 2009 13:41

Re: Key in ComboBox
 
Das geht so viel einfacher, da werden die auch automatisch aufgelistet:
http://fhasovic.blogspot.com/2004/08...key-codes.html
Die entsprechenden Zahlenwerten kann man auch einfach als Objekt zu dem String einfügen statt sichtbar.
Und man kann natürlich auch nur die gewünschten Wertebereiche auflisten lassen.

thomas2009 2. Mär 2009 15:38

Re: Key in ComboBox
 
Nun habe ich noch ein Problem
Wenn ich die Hotkey als String in ini Datei speichern möchte, dann welchen Wert muss ich speichern?

Hotkey_id ?
wenn ja, wie kann ich zum Beispiel beim Programm-Start die Hotkey nach dem Laden von Ini-Datei registrieren ?

Delphi-Quellcode:
var
  IniFile1 : TIniFile;
  hotkey1: Integer;
begin

FName := ExtractFilePath(Application.ExeName) + 'test.ini';
IniFile1 := TIniFile.Create(FName);
hotkey1 := StrToInt(MyIniFile.ReadString('hotkeys','hotkey1',''));
RegisterHotKey( ???
...

IniFile1.free;

DeddyH 2. Mär 2009 15:44

Re: Key in ComboBox
 
Man hat Dich schon einmal gefragt, wieso Du den Hotkey als String speichern willst. Das macht doch keinen Sinn, da es sich um eine Zahl handelt.

thomas2009 2. Mär 2009 15:50

Re: Key in ComboBox
 
Zahl kann man in String konvertieren und dann in ini speichern
Beim laden von String in Integer wieder zurücksetzen. wo ist das Problem ?

Satty67 2. Mär 2009 15:51

Re: Key in ComboBox
 
Das verwirrt mich doch sehr:
Delphi-Quellcode:
hotkey1 := StrToInt(MyIniFile.ReadString('hotkeys','hotkey1',''));
warum nicht so?
Delphi-Quellcode:
hotkey1 := MyIniFile.ReadInteger('hotkeys','hotkey1',0);
Zitat:

Zitat von thomas2009
wo ist das Problem ?

In INIs kann man direkt Zahlen speichern, also warum die Umwandlung in einen String?

DeddyH 2. Mär 2009 15:56

Re: Key in ComboBox
 
Zitat:

Zitat von thomas2009
Nun habe ich noch ein Problem
Wenn ich die Hotkey als String in ini Datei speichern möchte, dann welchen Wert muss ich speichern?

Zitat:

Zitat von thomas2009
wo ist das Problem ?

Du widersprichst Dir selbst :mrgreen:

thomas2009 2. Mär 2009 20:10

Re: Key in ComboBox
 
Meine Frage ist :
Zitat:

Zitat von thomas2009
wie kann ich zum Beispiel beim Programm-Start die Hotkey nach dem Laden von Ini-Datei registrieren ?

Ich möchte also die in INI-Datei gespeicherte Hotkey, registrieren

mein Versuch hat nicht geklappt:
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var
          Key : Word;
          Modifiers: UINT;
            FName: String;
  IniFile1 : TIniFile;
  hotkey1: Integer;
begin

FName := ExtractFilePath(Application.ExeName) + 'test.ini';
IniFile := TIniFile.Create(FName);
hotkey1 := StrToInt(MyIniFile.ReadString('hotkeys','hotkey1',''));
          Modifiers := 0;
          key := hotkey1;
          Hotkey_id := GlobalAddAtom('MyHotKey_1');
          RegisterHotKey(Handle, Hotkey_id, Modifiers, Key);
IniFile1.free;
end;


Alle Zeitangaben in WEZ +1. Es ist jetzt 11:52 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz