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).

Advertisements

4 thoughts on “CCR.VirtualKeying – virtual keystroke interface for Windows and OS X

  1. Pingback: Sending virtual keystrokes on OS X | Delphi Haven

    • Hmm, good idea, mouse moves at least shouldn’t be too hard to add, or at least, do on a very similar basis.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s