//
unit ads_sendkey;
{Copyright(c)2016 Advanced Delphi Systems
Richard Maley
Advanced Delphi Systems
12613 Maidens Bower Drive
Potomac, MD 20854 USA
phone 301-840-1554
dickmaley@advdelphisys.com
The code herein can be used or modified by anyone. Please retain references
to Richard Maley at Advanced Delphi Systems. If you make improvements to the
code please send your improvements to dickmaley@advdelphisys.com so that the
entire Delphi community can benefit. All comments are welcome.
}
(*
This is will only work in a 32 byte environment, i.e.,
Delphi 2.0 or Delphi 3.0
*)
(*UnitIndex Master Index Implementation Section Download UnitsDescription: ads_Sendkey.pas This unit contains the following routines.
AltPrintScreen KeySend PostVirtualKeyEvent SendKey SimulateKeystroke
*)
interface
Uses WinTypes;
{!~ Allows the programmer to simulate
a keyboard press of a virtual key.
Only one key at a time.}
Function SendKey(VirtualKey: Word): Boolean;
{!~ Allows the programmer to simulate
a keyboard press of a virtual key.
Only one key at a time.}
Function KeySend(VirtualKey: Word): Boolean;
procedure AltPrintScreen();
implementation
//Unit Description UnitIndex Master Indexprocedure SimulateKeystroke(Key : byte; extra : DWORD); Begin keybd_event(Key, extra, 0, 0); keybd_event(Key, extra, KEYEVENTF_KEYUP, 0); End; //Unit Description UnitIndex Master Index
procedure AltPrintScreen(); Begin SimulateKeystroke(VK_SNAPSHOT,1); End; //Unit Description UnitIndex Master Index
procedure PostVirtualKeyEvent(vk: Word; fUp: Bool);
const
ButtonUp: array[False..True] of Byte = (0, KEYEVENTF_KEYUP);
var
ScanCode: Byte;
begin
if vk <> vk_SnapShot then
ScanCode := MapVirtualKey(vk, 0)
else
ScanCode := 0;
Keybd_Event(vk, ScanCode, ButtonUp[fUp], 0);
end;
{Allows the programmer to simulate
a keyboard press of a virtual key.
Only one key at a time.}
//Unit Description UnitIndex Master Index
Function SendKey(VirtualKey: Word): Boolean;
Begin
Try
PostVirtualKeyEvent(VirtualKey,False);
PostVirtualKeyEvent(VirtualKey,True);
Result := True;
Except
Result := False;
End;
End;
{Allows the programmer to simulate
a keyboard press of a virtual key.
Only one key at a time.}
//Unit Description UnitIndex Master IndexFunction KeySend(VirtualKey: Word): Boolean; Begin Result := SendKey(VirtualKey); End; end. //