How to get keyboard input without focusing on Delphi

I would like to know how to get keyboard input in my delphi application until it focuses. The application I'm programming will take a snapshot while I'm in the game.

I wrote a screen capture code, but I miss this last part, any advice would be appreciated.

+4
source share
2 answers

You can register a hotkey (using RegisterHotKey and UnregisterHotKey ) and use the WM_HOTKEY message to intercept when a 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; 
+5
source

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

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

0
source

All Articles