Sign in Join
Wiki copytemporary

MouseAndKeyInput

English · Français

About

MouseAndKeyInput package is a tool for cross-platform manipulation with mouse and key input. You can move mouse cursor to specified location, send clicks and do key presses. It is suitable for GUI testing or program control demonstration.

Package is preinstalled in Lazarus in folder "components/mouseandkeyinput".

Author: Tom Gregorovic

License: GPL

Change Log

Restrictions

Carbon

Gtk1/2

Under Debian and Ubuntu the library libxtst-dev contains Xtst: sudo apt install libxtst-dev

Usage

After opening your project:

In your unit.pas add in the Uses clause:

pascal
Uses
  ..., MouseAndKeyInput, LCLType;

To simulate press of F1 from a button:

pascal
procedure TForm1.HelpButtonClick(Sender: TObject);
begin
  KeyInput.Apply([ssCtrl]);
  KeyInput.Press(VK_F1);                // This will simulate press of F1 function key.
  KeyInput.Unapply([ssCtrl]); 
end;

VK- definitions are found here: http://lazarus-ccr.sourceforge.net/docs/lcl/lcltype/index-2.html

Mouse control:

pascal
  MouseInput.Click(mbLeft,[],300,300);   // Left click on X:=300 , Y:=300
  MouseInput.Click(mbRight,[],1365,2);   // Right click on X:=1365 , Y:=2

From the Free Pascal wiki, page "MouseAndKeyInput", as it stood on 2022-12-10 after a change by Kapibara, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 1, last changed by WikiArchive .

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.