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
| procedure SendKeys(s : string);
var
i : integer;
flag : bool;
w : word;
begin
// Get the state of the caps lock key
flag := not GetKeyState(VK_CAPITAL) and 1 = 0;
// If the caps lock key is on then turn it off
if flag then
begin
SimulateKeystroke( VK_CAPITAL, 0 );
end;
for i := 1 to Length(s) do
begin
w := VkKeyScan(s[i]);
// If there is not an error in the key translation
if ((HiByte(w) <> $FF) and (LoByte(w) <> $FF)) then
begin
// If the key requires the shift key down - hold it down
if HiByte(w) and 1 = 1 then
begin
SimulateKeyDown( VK_SHIFT );
end;
// Send the VK_KEY
SimulateKeystroke( LoByte(w), 0 );
// If the key required the shift key down - release it
if HiByte(w) and 1 = 1 then
begin
SimulateKeyUp(VK_SHIFT);
end;
end;
end;
// if the caps lock key was on at start, turn it back on
if flag then
begin
SimulateKeystroke( VK_CAPITAL, 0 );
end;
end; |
Partager