Difference between revisions of "MouseAndKeyInput"

From Lazarus wiki
Jump to navigationJump to search
m (Fix heading levels; fix typos; add syntax highlighting)
Line 1: Line 1:
 
{{MouseAndKeyInput}}
 
{{MouseAndKeyInput}}
  
===About===
+
==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.
 
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.
  
===Location===
+
==Location==
 +
 
 
lazarusdir/components/mouseandkeyinput
 
lazarusdir/components/mouseandkeyinput
  
===Author===
+
==Author==
 +
 
 
[[User:Tombo|Tom Gregorovic]]  
 
[[User:Tombo|Tom Gregorovic]]  
  
===License===
+
==License==
 +
 
 
GPL
 
GPL
  
===Change Log===
+
==Change Log==
 +
 
 
* Version 0.1
 
* Version 0.1
  
===Restrictions===
+
==Restrictions==
* it is not recommended calling mouse and key input directly from events like OnClick, use [[Asynchronous_Calls|Application.QueueAsyncCall]] instead
+
 
* do not forget to set back mouse button and key state after Down method with Up method
+
* It is not recommended to call mouse and key input directly from events like OnClick, use [[Asynchronous_Calls|Application.QueueAsyncCall]] instead.
 +
* Do not forget to reset the mouse button and key state after Down method with Up method.
  
 
====Carbon====
 
====Carbon====
* pressing alpha chars is not supported
+
 
 +
* Pressing alpha chars is not supported.
  
 
====Gtk1/2====
 
====Gtk1/2====
* needs Xtst library
+
 
* ALT key pressing is not supported
+
* Needs Xtst library.
 +
* ALT key pressing is not supported.
  
 
===How to===
 
===How to===
 +
 
With your project open:
 
With your project open:
Go to the Lazarus install directory -> components -> mouseandkeyinput. 
 
There you will find: lazmouseandkeyinput.lpk. 
 
Open and compile the .lpk.
 
  
In your unit.pas add in Uses:  
+
* Go to the Lazarus install directory -> components -> mouseandkeyinput. 
MouseAndKeyInput ,LCLType
+
* There you will find: lazmouseandkeyinput.lpk. 
 +
* Open and compile the .lpk.
 +
 
 +
In your unit.pas add in the Uses clause:  
 +
 
 +
<syntaxhighlight lang=pascal>
 +
..., MouseAndKeyInput, LCLType;
 +
</syntaxhighlight>
  
 
To simulate press of F1 from a button:
 
To simulate press of F1 from a button:
  
 +
<syntaxhighlight lang=pascal>
 
procedure TForm1.HelpButtonClick(Sender: TObject);
 
procedure TForm1.HelpButtonClick(Sender: TObject);
 
begin
 
begin
Line 44: Line 58:
 
   KeyInput.Unapply([ssCtrl]);  
 
   KeyInput.Unapply([ssCtrl]);  
 
end;
 
end;
 +
</syntaxhighlight>
  
VK- def's  is found here: http://lazarus-ccr.sourceforge.net/docs/lcl/lcltype/index-2.html
+
VK- definitions are found here: http://lazarus-ccr.sourceforge.net/docs/lcl/lcltype/index-2.html
  
 
Mouse control:
 
Mouse control:
  
 +
<syntaxhighlight lang=pascal>
 
   MouseInput.Click(mbLeft,[],300,300);  // Left click on X:=300 , Y:=300
 
   MouseInput.Click(mbLeft,[],300,300);  // Left click on X:=300 , Y:=300
 
   MouseInput.Click(mbRight,[],1365,2);  // Right click on X:=1365 , Y:=2
 
   MouseInput.Click(mbRight,[],1365,2);  // Right click on X:=1365 , Y:=2
 +
</syntaxhighlight>

Revision as of 07:48, 11 August 2020

English (en) français (fr)

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.

Location

lazarusdir/components/mouseandkeyinput

Author

Tom Gregorovic

License

GPL

Change Log

  • Version 0.1

Restrictions

  • It is not recommended to call mouse and key input directly from events like OnClick, use Application.QueueAsyncCall instead.
  • Do not forget to reset the mouse button and key state after Down method with Up method.

Carbon

  • Pressing alpha chars is not supported.

Gtk1/2

  • Needs Xtst library.
  • ALT key pressing is not supported.

How to

With your project open:

  • Go to the Lazarus install directory -> components -> mouseandkeyinput.
  • There you will find: lazmouseandkeyinput.lpk.
  • Open and compile the .lpk.

In your unit.pas add in the Uses clause:

..., MouseAndKeyInput, LCLType;

To simulate press of F1 from a button:

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:

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