1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| PROCEDURE TForm3.OnWmCopyData(var Msg : TMessage);
TYPE
TPCopyDataStruct = ^TCopyDataStruct;
TPDataEnvoyes = ^TDataEnvoyes;
VAR
DataEnvoyes : TDataEnvoyes;
PDataEnvoyes : TPDataEnvoyes;
PCopyDataStruct : TPCopyDataStruct;
KeyState : TKeyState;
BEGIN
PCopyDataStruct := TPCopyDataStruct(Msg.LPARAM);
PDataEnvoyes := PCopyDataStruct^.lpData;
DataEnvoyes := PDataEnvoyes^;
KeyState := GetEtatTouche(DataEnvoyes.State);
passkey := DataEnvoyes.State;
Keypressed := KeyState.Pressed;
Keyreaded := DataEnvoyes.Key;
IF (Keyreaded = ord('B')) AND (Keypressed) THEN
Permission := NOT Permission;
Msg.Result := 1;
IF (Permission) THEN
Msg.Result := 0;
{ pour mise au point }
if (Permission) then
begin
if NOT KeyState.PrevPressed then
Memo1.Lines.Add('Clavier autorisé touche = ' + chr(Keyreaded));
// Memo1.Lines.Add('Touche étendue = '+BoolToStr(KeyState.ExtendedKey)) ;
// Memo1.Lines.Add('Touche ALT = '+BoolToStr(KeyState.Alt)) ;
// Memo1.Lines.Add('Touche pressée auparavant = '+BoolToStr(KeyState.PrevPressed)) ;
// Memo1.Lines.Add('');
end else begin
Memo1.Lines.Add('Clavier bloqué');
Memo1.Lines.Add('');
{ si touche relachée : émettre un message }
Permission := True;
Msg.Result := 0;
// keybd_event(ord('A'),0,0,0);
EnvoiChaine(Msg, 'Hello world !');
Msg.Result := 1;
end;
END; // ROCEDURE TForm3.OnWmCopyData
{ ---------------------------------------------------------------- }
PROCEDURE TForm3.EnvoiChaine(var Msg : TMessage; s : String);
var
LongChaine, i : Integer;
sChar : Char;
begin
LongChaine := length(s);
for i := 1 to LongChaine do
begin
sChar := s[ i ];
keybd_event(ord(sChar), 0, 0, 0);
keybd_event(ord(sChar), 0, KEYEVENTF_KEYUP, 0);
Sleep(10);
end;
end; |
Partager