CCR.VirtualKeying – virtual keystroke interface for Windows and OS X

  

I’ve just added to GitHub a little virtual keystroke interface for Windows and OS X – on the former it wraps the SendInput API, on the latter the CGEvent functions:
https://github.com/chrisrolliston/CCR.VirtualKeying
Virtually typing some text into the active window is a one-liner:

TVirtualKeySequence.Execute(‘¡Hola!’);

Alternatively, you can build up a sequence of keystrokes to perform by working with an explicit IVirtualKeySequence instance:

var
Sequence: IVirtualKeySequence;
begin
Sequence := TVirtualKeySequence.Create;
Sequence.AddKeyPresses(‘Привет!’);
{$IFDEF MACOS}
Sequence.Add(vkA, [ssCommand], [keDown, keUp]);
{$ELSE}
Sequence.Add(vkA, [ssCtrl], [keDown, keUp]);
{$ENDIF}
Sequence.Execute;

For more on the available methods, check out the readme at the above link. The repository also includes a simple demo in FMX and VCL forms (code is essentially the same).

Comments are closed.