Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get input from keyboard while not focussed Delphi

I would like to know how to get keyboard input in my delphi application while its not focussed. The application i am programming is going to be taking a screenshot while i am in game.

I have wrote the screen capture code but i am missing this last piece any advice would be appreciated.

like image 343
Kobus Vdwalt Avatar asked Dec 03 '12 15:12

Kobus Vdwalt


2 Answers

You can register a hotkey (using the RegisterHotKey and UnregisterHotKey functions) and use the WM_HOTKEY message to intercept when the key is pressed.

Try this sample

type
  TForm3 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
  public
     procedure WMHotKey(var Message: TMessage); message WM_HOTKEY;
  end;

var
  Form3: TForm3;

implementation


{$R *.dfm}


{ TForm3 }

const
  SaveScreeenHK=666;

procedure TForm3.FormCreate(Sender: TObject);
begin
 RegisterHotKey(Handle, SaveScreeenHK , MOD_CONTROL, VK_F10);
end;

procedure TForm3.FormDestroy(Sender: TObject);
begin
  UnregisterHotKey(Handle, SaveScreeenHK);
end;

procedure TForm3.WMHotKey(var Message: TMessage);
begin
 //call your method here
end;
like image 145
RRUZ Avatar answered Oct 29 '22 04:10

RRUZ


I have since been busy and created a library for getting keystrokes in delphi. You can find it here : https://github.com/Kobusvdwalt/DelphiKeylogger

It still needs documentation but basicly you just call the olgetletter function.

like image 1
Kobus Vdwalt Avatar answered Oct 29 '22 05:10

Kobus Vdwalt