MML: SendKeys (win), Better way to do it.

This commit is contained in:
John P (Dgby714) 2011-07-23 18:00:23 -04:00
parent 3fbeab9a0b
commit 8acb244ec3
1 changed files with 19 additions and 26 deletions

View File

@ -368,36 +368,29 @@ end;
procedure TWindow.SendString(str: string); procedure TWindow.SendString(str: string);
var var
I, L: Integer; I, L: integer;
K: Byte; C: Byte;
HoldShift: Boolean; ScanCode, VK: Word;
Shift: boolean;
begin begin
HoldShift := False;
L := Length(str); L := Length(str);
for I := 1 to L do for I := 1 to L do
begin begin
if (((str[I] >= 'A') and (str[I] <= 'Z')) or VK := VkKeyScan(str[I]);
((str[I] >= '!') and (str[I] <= '&')) or Shift := (Hi(VK) > 0);
((str[I] >= '(') and (str[I] <= '+')) or C := LoByte(VK);
(str[I] = ':') or ScanCode := MapVirtualKey(C, 0);
((str[I] >= '<') and (str[I] <= '@')) or
((str[I] >= '^') and (str[I] <= '_')) or WriteLn(ScanCode);
((str[I] >= '{') and (str[I] <= '~'))) then
begin if (Shift) then
HoldKey(VK_SHIFT); Keybd_Event(VK_SHIFT, $2A, 0, 0);
HoldShift := True;
end; Keybd_Event(C, ScanCode, 0, 0);
Keybd_Event(C, ScanCode, KEYEVENTF_KEYUP, 0);
K := GetKeyCode(str[I]);
HoldKey(K); if (Shift) then
Sleep(20); Keybd_Event(VK_SHIFT, $2A, KEYEVENTF_KEYUP, 0);
ReleaseKey(K);
if (HoldShift) then
begin
HoldShift := False;
ReleaseKey(VK_SHIFT);
end;
end; end;
end; end;