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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
| unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure envoi(maphrase : string; monhandle : hwnd);
procedure caps_lock();
procedure alt_gr_Bas();
procedure alt_gr_haut();
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
const ctrlg = 17;
altg = 18;
capslock = 20;
shift = 16;
touchedown = 0;
toucheup = 2;
touchegmaj = 71;
toucheenter = 13;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var handle : hwnd;
phrase : string;
(*------------------------*)
procedure envoitsurhandle();
begin
phrase := edit1.text;
setlength(phrase,length(phrase));
envoi(phrase,handle);
caps_lock();
end;
(*------------------------*)
begin
handle := findwindow(nil, 'sans titre - notepad2');
if handle = 0 then
begin
// juste pour qu'il puisse continué a ecrire dans le bloc.
handle := findwindow(nil, '* sans titre - notepad2');
if handle = 0 then showmessage('Aucun Handle Actif...')
else envoitsurhandle();
end
else envoitsurhandle();
end;
procedure TForm1.envoi(maphrase : string; monhandle : hwnd);
var i : integer;
etatmaj, codetouche_hightbyte, codetouche_lowbyte : byte;
begin
setforegroundwindow(monhandle);
// on mémorise si le caps lock est actif ou non.
etatmaj := getkeystate(capslock);
// si le caps lock est actif on le désactive.
if etatmaj = 1 then caps_lock();
// parcour la chaine de caractères.
for i := 1 to length(maphrase) do
begin
// on verifie le flag de la touche (lettre majuscules, lettre faites avec
// un alt gr, lettre minuscule, ...).
codetouche_hightbyte := hibyte(vkkeyscan(maphrase[i]));
// code asci de la touche par exemple 65 pour A.
codetouche_lowbyte := lobyte(vkkeyscan(maphrase[i]));
// enfonce la touche shift.
if codetouche_hightbyte = 1 then keybd_event(shift, 0, touchedown, 0);
// simule la touche alt gr selon la version xp ou 98.
if codetouche_hightbyte = 6 then alt_gr_bas();
// enfonce une touche.
keybd_event(codetouche_lowbyte,0,touchedown,0);
// lache une touche.
keybd_event(codetouche_lowbyte, 0,toucheup,0);
// lache la touche Shift.
if codetouche_hightbyte = 1 then keybd_event(shift, 0, toucheup, 0);
// simule la touche alt gr selon la version xp ou 98.
if codetouche_hightbyte = 6 then alt_gr_haut();
end;
// ici il remet pas toujours le caps lock... je sais pas encore pourquoi.
// si avant la manipulation la touche caps lock était active, on la réactive.
if etatmaj = 1 then caps_lock();
// on va a la ligne.
keybd_event(toucheenter,0,touchedown,0);
keybd_event(toucheenter, 0,toucheup,0);
end;
procedure TForm1.caps_lock();
begin
// enfonce la touche caps lock.
keybd_event(capslock, 0, touchedown, 0);
// lache la touche caps lock.
keybd_event(capslock, 0, toucheup, 0);
end;
procedure TForm1.alt_gr_bas();
begin
// win 98
if (win32majorversion = 4) and (win32minorversion = 10) then
begin
// enfonce la touche G majuscule.
keybd_event(altg, 0, touchedown, 0);
// lache la touche ctrl gauche.
keybd_event(touchegmaj, 0, touchedown, 0);
end
// win xp et autres (Aucun test fait sur NT 4.0 et 95...)
else
begin
// enfonce la touche alt gauche.
keybd_event(altg, 0, touchedown, 0);
// enfonce la touche ctrl gauche.
keybd_event(ctrlg, 0, touchedown, 0);
end;
end;
procedure TForm1.alt_gr_haut();
begin
// Win 98
if (win32majorversion = 4) and (win32minorversion = 10) then
begin
// lache la touche G majuscule.
keybd_event(touchegmaj, 0, toucheup, 0);
// lache la touche alt gauche.
keybd_event(altg, 0, toucheup, 0);
end
// win xp et autres (aucun test fait sur NT 4.0 et 95...)
else
begin
// lache la touche ctrl gauche.
keybd_event(ctrlg, 0, toucheup, 0);
// lache la touche alt gauche.
keybd_event(altg, 0, toucheup, 0);
end;
end;
end. |
Partager