Questo "funzione" simula la pressione di un tasto (di qualsiasi tipo) della tastiera.
EDIT: funziona solo in Windows e dovete aggiungere la Unit Windows fra le Uses ::)
Agisce come la tastiera sul controllo che ha il focus (ATTENZIONE: CONTROLLO DI UNA QUALSIASI APPLICAZIONE, NON E' LEGATA A QUESTA).
Se create un progetto, vi aggiungete un Timer a 5 secondi e lo "agganciate" all'evento in coda, avrete una pressione del tasto PgDown ogni 5 secondi sull'applicazione attiva in quel momento (sia esso un browser che un'altra app).
Uso questo codice da vent'anni o giù di lì (o meglio lo usavo perchè è da molto che non lo rispolveravo). Dovrebbe probabilmente trovarsi ancora su qualche forum su Internet.
procedure SimulaPressioneTasto(key: Word; const shift: TShiftState; specialkey: Boolean);
type
TShiftKeyInfo = record
shift: Byte;
vkey: Byte;
end;
byteset = set of 0..7;
const
shiftkeys: array [1..3] of TShiftKeyInfo =
((shift: Ord(ssCtrl); vkey: VK_CONTROL),
(shift: Ord(ssShift); vkey: VK_SHIFT),
(shift: Ord(ssAlt); vkey: VK_MENU));
var
flag: DWORD;
bShift: ByteSet absolute shift;
i: Integer;
begin
for i := 1 to 3 do
begin
if shiftkeys[i].shift in bShift then
keybd_event(shiftkeys[i].vkey, MapVirtualKey(shiftkeys[i].vkey, 0), 0, 0);
end;
if specialkey then
flag := KEYEVENTF_EXTENDEDKEY
else
flag := 0;
keybd_event(key, MapvirtualKey(key, 0), flag, 0);
flag := flag or KEYEVENTF_KEYUP;
keybd_event(key, MapvirtualKey(key, 0), flag, 0);
for i := 3 downto 1 do
begin
if shiftkeys[i].shift in bShift then
keybd_event(shiftkeys[i].vkey, MapVirtualKey(shiftkeys[i].vkey, 0),
KEYEVENTF_KEYUP, 0);
end;
end;
// Per eseguire la simulazione:
procedure TForm1.Timer1Timer(Sender: TObject);
begin
SimulaPressioneTasto(VK_NEXT, [], False);
end;
Ciao ciao