unit ecHotKeyEdit;

interface

uses
  Windows, Messages, Classes, Controls, StdCtrls, Menus;

type
  TecHotKey = class(TCustomEdit)
    procedure WMGetDlgCode(var Message: TWMGetDlgCode); message WM_GETDLGCODE;
  private
    FHotKey: TShortCut;
    procedure SetHotKey(const Value: TShortCut);
  protected
    procedure KeyDown(var Key: Word; Shift: TShiftState); override;
  public
    constructor Create(AOwner: TComponent); override;
    property Text;
  published
    property HotKey: TShortCut read FHotKey write SetHotKey;
    property Anchors;
    property AutoSelect;
    property AutoSize;
    property BevelEdges;
    property BevelInner;
    property BevelKind default bkNone;
    property BevelOuter;
    property BiDiMode;
    property BorderStyle;
    property CharCase;
    property Color;
    property Constraints;
    property Ctl3D;
    property DragCursor;
    property DragKind;
    property DragMode;
    property Enabled;
    property Font;
    property HideSelection;
    property ImeMode;
    property ImeName;
    property MaxLength;
    property OEMConvert;
    property ParentBiDiMode;
    property ParentColor;
    property ParentCtl3D;
    property ParentFont;
    property ParentShowHint;
    property PasswordChar;
    property PopupMenu;
    property ShowHint;
    property TabOrder;
    property TabStop;
    property Visible;
    property OnChange;
    property OnClick;
    property OnContextPopup;
    property OnDblClick;
    property OnDragDrop;
    property OnDragOver;
    property OnEndDock;
    property OnEndDrag;
    property OnEnter;
    property OnExit;
    property OnKeyDown;
    property OnKeyPress;
    property OnKeyUp;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
    property OnStartDock;
    property OnStartDrag;
  end;

implementation

{ TecHotKey }

constructor TecHotKey.Create(AOwner: TComponent);
begin
  inherited;
  ControlStyle := ControlStyle - [csSetCaption];
end;

procedure TecHotKey.KeyDown(var Key: Word; Shift: TShiftState);
var sc: Word;
    msg: tagMsg;
begin
  if (Key <> VK_SHIFT) and (Key <> VK_CONTROL) and (Key <> VK_MENU) and (Key <> 0) then
    begin
      sc := Key;
      if ssShift in Shift then sc := sc or scShift;
      if ssCtrl in Shift then sc := sc or scCtrl;
      if ssAlt in Shift then sc := sc or scAlt;
      HotKey := TShortCut(sc);
      Key := 0;
      PeekMessage(msg, Handle, WM_CHAR, WM_CHAR, PM_REMOVE);
    end;
  inherited;
end;

procedure TecHotKey.SetHotKey(const Value: TShortCut);
begin
  FHotKey := Value;
  Text := ShortCutToText(FHotKey);
end;

procedure TecHotKey.WMGetDlgCode(var Message: TWMGetDlgCode);
begin
  Message.Result := DLGC_WANTALLKEYS or
                    DLGC_WANTARROWS or
                    DLGC_WANTCHARS or
                    DLGC_WANTMESSAGE or
                    DLGC_WANTTAB;
end;

end.
