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).
Pingback: Sending virtual keystrokes on OS X | Delphi Haven
Very nice, any thoughts of doing this with mouse movement or window selection?
Hmm, good idea, mouse moves at least shouldn’t be too hard to add, or at least, do on a very similar basis.
Reblogged this on Dinesh Ram Kali..