Einzelnen Beitrag anzeigen

Benutzerbild von kuba
kuba

Registriert seit: 26. Mai 2006
Ort: Arnsberg
588 Beiträge
 
Delphi 11 Alexandria
 
#4

AW: Taste bzw Tastenkombination bei OSX abfragen

  Alt 10. Aug 2016, 23:17
Delphi-Quellcode:
unit Unit1;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  System.IniFiles, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
  FMX.StdCtrls, Posix.Stdlib, FMX.Menus, Macapi.AppKit, Macapi.CoreGraphics,
  FMX.Edit, FMX.Controls.Presentation;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    OpenDialog1: TOpenDialog;
    Label1: TLabel;
    Label2: TLabel;
    Timer1: TTimer;
    Button3: TButton;
    MainMenu1: TMainMenu;
    MenuItem1: TMenuItem;
    MenuItem2: TMenuItem;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    Button7: TButton;
    Button8: TButton;
    Button9: TButton;
    Button10: TButton;
    Button11: TButton;
    Button12: TButton;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Timer2: TTimer;
    MenuItem3: TMenuItem;
    MenuItem4: TMenuItem;
    MenuItem5: TMenuItem;
    procedure Button1Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure MenuItem2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
    procedure Button9Click(Sender: TObject);
    procedure Button10Click(Sender: TObject);
    procedure Button11Click(Sender: TObject);
    procedure Button12Click(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Timer2Timer(Sender: TObject);
    procedure MenuItem4Click(Sender: TObject);
  private
    { Private-Deklarationen }
    FIniFile: TCustomIniFile;
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.fmx}

uses NoActivateForm, CCR.PrefsIniFile, ShellUtils, Unit2;

var
  F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12 :string;


procedure TForm1.Button10Click(Sender: TObject);
begin
    F10:='';
    if Opendialog1.Execute then F10:=Opendialog1.FileName;
    Label10.Text:=F10;
    FIniFile.WriteString('FKeys', 'F10', F10);
    FIniFile.UpdateFile;
end;

procedure TForm1.Button11Click(Sender: TObject);
begin
    F11:='';
    if Opendialog1.Execute then F11:=Opendialog1.FileName;
    Label11.Text:=F11;
    FIniFile.WriteString('FKeys', 'F11', F11);
    FIniFile.UpdateFile;
end;

procedure TForm1.Button12Click(Sender: TObject);
begin
    F12:='';
    if Opendialog1.Execute then F12:=Opendialog1.FileName;
    Label12.Text:=F12;
    FIniFile.WriteString('FKeys', 'F12', F12);
    FIniFile.UpdateFile;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
    F1:='';
    if Opendialog1.Execute then F1:=Opendialog1.FileName;
    Label1.Text:=F1;
    FIniFile.WriteString('FKeys', 'F1', F1);
    FIniFile.UpdateFile;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
    F2:='';
    if Opendialog1.Execute then F2:=Opendialog1.FileName;
    Label2.Text:=F2;
    FIniFile.WriteString('FKeys', 'F2', F2);
    FIniFile.UpdateFile;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
    F3:='';
    if Opendialog1.Execute then F3:=Opendialog1.FileName;
    Label3.Text:=F3;
    FIniFile.WriteString('FKeys', 'F3', F3);
    FIniFile.UpdateFile;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
    F4:='';
    if Opendialog1.Execute then F4:=Opendialog1.FileName;
    Label4.Text:=F4;
    FIniFile.WriteString('FKeys', 'F4', F4);
    FIniFile.UpdateFile;
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
    F5:='';
    if Opendialog1.Execute then F5:=Opendialog1.FileName;
    Label5.Text:=F5;
    FIniFile.WriteString('FKeys', 'F5', F5);
    FIniFile.UpdateFile;
end;

procedure TForm1.Button6Click(Sender: TObject);
begin
    F6:='';
    if Opendialog1.Execute then F6:=Opendialog1.FileName;
    Label6.Text:=F6;
    FIniFile.WriteString('FKeys', 'F6', F6);
    FIniFile.UpdateFile;
end;

procedure TForm1.Button7Click(Sender: TObject);
begin
    F7:='';
    if Opendialog1.Execute then F7:=Opendialog1.FileName;
    Label7.Text:=F7;
    FIniFile.WriteString('FKeys', 'F7', F7);
    FIniFile.UpdateFile;
end;

procedure TForm1.Button8Click(Sender: TObject);
begin
    F8:='';
    if Opendialog1.Execute then F8:=Opendialog1.FileName;
    Label8.Text:=F8;
    FIniFile.WriteString('FKeys', 'F8', F8);
    FIniFile.UpdateFile;
end;

procedure TForm1.Button9Click(Sender: TObject);
begin
    F9:='';
    if Opendialog1.Execute then F9:=Opendialog1.FileName;
    Label9.Text:=F9;
    FIniFile.WriteString('FKeys', 'F9', F9);
    FIniFile.UpdateFile;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Timer2.Enabled:=true;
  FIniFile := CreateUserPreferencesIniFile(TWinLocation.IniFile);
  Label1.Text := FIniFile.ReadString('FKeys', 'F1', '');
  F1 := Label1.Text;
  Label2.Text := FIniFile.ReadString('FKeys', 'F2', '');
  F2 := Label2.Text;
  Label3.Text := FIniFile.ReadString('FKeys', 'F3', '');
  F3 := Label3.Text;
  Label4.Text := FIniFile.ReadString('FKeys', 'F4', '');
  F4 := Label4.Text;
  Label5.Text := FIniFile.ReadString('FKeys', 'F5', '');
  F5 := Label5.Text;
  Label6.Text := FIniFile.ReadString('FKeys', 'F6', '');
  F6 := Label6.Text;
  Label7.Text := FIniFile.ReadString('FKeys', 'F7', '');
  F7 := Label7.Text;
  Label8.Text := FIniFile.ReadString('FKeys', 'F8', '');
  F8 := Label8.Text;
  Label9.Text := FIniFile.ReadString('FKeys', 'F9', '');
  F9 := Label9.Text;
  Label10.Text := FIniFile.ReadString('FKeys', 'F10', '');
  F10 := Label10.Text;
  Label11.Text := FIniFile.ReadString('FKeys', 'F11', '');
  F11 := Label11.Text;
  Label12.Text := FIniFile.ReadString('FKeys', 'F12', '');
  F12 := Label12.Text;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  FIniFile.Free;
end;

procedure TForm1.MenuItem2Click(Sender: TObject);
begin
  Close;
end;

procedure TForm1.MenuItem4Click(Sender: TObject);
begin
  Form2.Show;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  //if TNSEvent.OCClass.modifierFlags = NSControlKeyMask then showmessage('test');
  if (CGEventSourceKeyState(0, 122) <> 0) then _system(PAnsiChar('open ' + '"' + AnsiString(F1) + '"'));
  if (CGEventSourceKeyState(0, 120) <> 0) then _system(PAnsiChar('open ' + '"' + AnsiString(F2) + '"'));
  if (CGEventSourceKeyState(0, 99) <> 0) then _system(PAnsiChar('open ' + '"' + AnsiString(F3) + '"'));
  if (CGEventSourceKeyState(0, 118) <> 0) then _system(PAnsiChar('open ' + '"' + AnsiString(F4) + '"'));
  if (CGEventSourceKeyState(0, 96) <> 0) then _system(PAnsiChar('open ' + '"' + AnsiString(F5) + '"'));
  if (CGEventSourceKeyState(0, 97) <> 0) then _system(PAnsiChar('open ' + '"' + AnsiString(F6) + '"'));
  if (CGEventSourceKeyState(0, 98) <> 0) then _system(PAnsiChar('open ' + '"' + AnsiString(F7) + '"'));
  if (CGEventSourceKeyState(0, 100) <> 0) then _system(PAnsiChar('open ' + '"' + AnsiString(F8) + '"'));
  if (CGEventSourceKeyState(0, 101) <> 0) then _system(PAnsiChar('open ' + '"' + AnsiString(F9) + '"'));
  if (CGEventSourceKeyState(0, 109) <> 0) then _system(PAnsiChar('open ' + '"' + AnsiString(F10) + '"'));
  if (CGEventSourceKeyState(0, 103) <> 0) then _system(PAnsiChar('open ' + '"' + AnsiString(F11) + '"'));
  if (CGEventSourceKeyState(0, 111) <> 0) then _system(PAnsiChar('open ' + '"' + AnsiString(F12) + '"'));
end;

procedure TForm1.Timer2Timer(Sender: TObject);
begin
  Timer2.Enabled:=false;
  WindowState := TWindowState.wsMinimized;
end;

end.
Stefan Kubatzki
E=mc2

Geändert von kuba (11. Aug 2016 um 20:33 Uhr)
  Mit Zitat antworten Zitat