Advanced Delphi Systems- sendkey

Yazdığınız makaleleri ve üyelerimizin işine yarayacağını düşündüğünüz kodlarınızı gönderebilirsiniz. Bu foruma soru sormayın!
Cevapla
Kullanıcı avatarı
Asri
Kıdemli Üye
Mesajlar: 767
Kayıt: 16 Eyl 2003 09:54
Konum: istanbul

Advanced Delphi Systems- sendkey

Mesaj gönderen Asri »

Aşağıdaki unit'i unit1'de uses olarak ekleyip bu unit içindeki procedure ve function'ları kullanbilirsiniz.

Bu unit program sendkey işleminde kullanılır.

Kod: Tümünü seç

unit ads_sendkey;
{Copyright(c)2000 Advanced Delphi Systems

 Richard Maley
 Advanced Delphi Systems
 12613 Maidens Bower Drive
 Potomac, MD 20854 USA
 phone 301-840-1554
 maley@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 maley@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
*)

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;

implementation

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.}
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.}
Function KeySend(VirtualKey: Word): Boolean;
Begin
  Result := SendKey(VirtualKey);
End;

end.

Öğrenmek ve öğretmek, akıntıya karşı yüzmek gibidir ilerleyemediğiniz taktirde gerilersiniz.
Cevapla