unit addeventwin;

interface

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

type
  Taddeventdlg = class(TForm)
    GroupBox1: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    ComboBox1: TComboBox;
    ComboBox2: TComboBox;
    Edit1: TEdit;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    Function Execute(Var Event: String; Var Mods: String; Var Command: String): Boolean;
    Function EventStringToIndex(Str: String): Integer;
    Function EventIndexToString(Index: Integer): String;
    Function ModStringToIndex(Str: String): Integer;
    Function ModIndexToString(Index: Integer): String;
  end;

var
  addeventdlg: Taddeventdlg;

implementation

{$R *.dfm}

{ Taddeventdlg }

function Taddeventdlg.EventIndexToString(Index: Integer): String;
begin
 Result := '';
 Case Index of
  0: Result := 'OnMouseLeftDown';
  1: Result := 'OnMouseLeftUp';
  2: Result := 'OnMouseMiddleDown';
  3: Result := 'OnMouseMiddleUp';
  4: Result := 'OnMouseRightDown';
  5: Result := 'OnMouseRightUp';
  6: Result := 'OnMouseWheelDown';
  7: Result := 'OnMouseWheelUp';
  8: Result := 'OnMouseWheelAny';
  9: Result := 'OnMouseMove';
 end;
end;

function Taddeventdlg.EventStringToIndex(Str: String): Integer;
begin
 Result := -1;
 If uppercase(Str) = uppercase('OnMouseLeftDown') then begin
  Result := 0;
 end;
 If uppercase(Str) = uppercase('OnMouseLeftUp') then begin
  Result := 1;
 end;
 If uppercase(Str) = uppercase('OnMouseMiddleDown') then begin
  Result := 2;
 end;
 If uppercase(Str) = uppercase('OnMouseMiddleUp') then begin
  Result := 3;
 end;
 If uppercase(Str) = uppercase('OnMouseRightDown') then begin
  Result := 4;
 end;
 If uppercase(Str) = uppercase('OnMouseRightUp') then begin
  Result := 5;
 end;
 If uppercase(Str) = uppercase('OnMouseWheelDown') then begin
  Result := 6;
 end;
 If uppercase(Str) = uppercase('OnMouseWheelUp') then begin
  Result := 7;
 end;
 If uppercase(Str) = uppercase('OnMouseWheelAny') then begin
  Result := 8;
 end;
 If uppercase(Str) = uppercase('OnMouseMove') then begin
  Result := 9;
 end;
end;

function Taddeventdlg.Execute(var Event, Mods: String; Var Command: String): Boolean;
begin
 Combobox1.ItemIndex := EventStringToIndex(Event);
 Combobox2.ItemIndex := ModStringToIndex(Mods);
 Edit1.Text := Command;
 Result := ShowModal = mrOK;
 If Result then begin
  Command := Edit1.Text;
  Event := EventIndexToString(Combobox1.ItemIndex);
  Mods := ModIndexToString(Combobox2.ItemIndex);
 end;
end;

function Taddeventdlg.ModIndexToString(Index: Integer): String;
begin
 Result := '';
 Case Index of
  0: Result := 'None';
  1: Result := 'Shift';
  2: Result := 'Ctrl';
  3: Result := 'Alt';
  4: Result := 'Alt+Shift';
  5: Result := 'Alt+Ctrl';
  6: Result := 'Ctrl+Shift';
  7: Result := 'Alt+Ctrl+Shift';
  8: Result := 'Any';
 end;
end;

function Taddeventdlg.ModStringToIndex(Str: String): Integer;
begin
 Result := -1;
 If uppercase(Str) = uppercase('(None)') then begin
  Result := 0;
 end;
 If uppercase(Str) = uppercase('None') then begin
  Result := 0;
 end;
 If uppercase(Str) = uppercase('Shift') then begin
  Result := 1;
 end;
 If uppercase(Str) = UppercasE('Ctrl') then begin
  Result := 2;
 end;
 If uppercase(str) = uppercase('Alt') then begin
  Result := 3;
 end;
 If uppercase(str) = uppercase('Alt+Shift') then begin
  Result := 4;
 end;
 If uppercase(str) = uppercase('Alt+Ctrl') then begin
  Result := 5;
 end;
 If uppercase(str) = uppercase('Ctrl+Shift') then begin
  Result := 6;
 end;
 If uppercase(str) = uppercase('Alt+Ctrl+Shift') then begin
  Result := 7;
 end;
 If uppercase(str) = uppercase('Any') then begin
  Result := 8;
 end;

end;

procedure Taddeventdlg.Button1Click(Sender: TObject);
begin
 If combobox1.Text = '' then begin
  combobox1.SetFocus;
  exit;
 end;
 If combobox2.Text = '' then begin
  Combobox2.SetFocus;
  exit;
 end;
 If edit1.text = '' then begin
  Edit1.SelectAll;
  Edit1.SetFocus;
  exit;
 end;
 ModalResult := mrOK;
end;

end.
