Ads 468x60px

Smaller time frame always follow the bigger time frame. It's better wait be patience to enter in position than risk with BIG SL. Having strong trading discipline and taking losses when necessary is a sign of serious trading approach

Wednesday, May 30, 2012

How to use the THotKey component to register a global Hotkey

Title: How to use the THotKey component to register a global Hotkey

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

type
  TForm1 = class(TForm)
    HotKey1: THotKey;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
    Hotkey_id : Integer;
    procedure WMHotKey(var Msg: TWMHotKey); message WM_HOTKEY;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;



implementation

{$R *.dfm}

// WM_HOTKEY Hotkey Handler
procedure TForm1.WMHotKey(var Msg: TWMHotKey);
begin
  if Msg.HotKey = Hotkey_id then
    ShowMessage('Hotkey empfangen');
end;

// Transform TShortCut to use for RegisterHotKey
// TShortCut für RegisterHotKey umwandeln
procedure ShortCutToHotKey(HotKey: TShortCut; var Key : Word; var Modifiers: Uint);
var
  Shift: TShiftState;
begin
  ShortCutToKey(HotKey, Key, Shift);
  Modifiers := 0;
  if (ssShift in Shift) then
  Modifiers := Modifiers or MOD_SHIFT;
  if (ssAlt in Shift) then
  Modifiers := Modifiers or MOD_ALT;
  if (ssCtrl in Shift) then
  Modifiers := Modifiers or MOD_CONTROL;
end;

// Register Hotkey
// Hotkey registrieren
procedure TForm1.Button1Click(Sender: TObject);
var
  Key : Word;
  Modifiers: UINT;
begin
  ShortCutToHotKey(HotKey1.HotKey, Key, Modifiers);
  Hotkey_id := GlobalAddAtom('MyHotKey_1');
  RegisterHotKey(Handle, Hotkey_id, Modifiers, Key);
end;

// Remove Hotkey
// Hotkey entfernen
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  UnRegisterHotKey(Handle, Hotkey_id);
  GlobalDeleteAtom(Hotkey_id);
end;






Source comments