Merge pull request #31 from Dgby714/SendKeysFix

MML: SendKeys
This commit is contained in:
Merlijn Wajer 2011-07-23 15:08:58 -07:00
commit 38c8b16407
2 changed files with 55 additions and 49 deletions

View File

@ -415,31 +415,37 @@ implementation
procedure TWindow.SendString(str: string); procedure TWindow.SendString(str: string);
var var
i: integer; I, L: Integer;
key: byte; K: Byte;
HoldShift : boolean; HoldShift: Boolean;
begin begin
HoldShift := false; HoldShift := False;
for i := 1 to length(str) do L := Length(str);
for I := 1 to L do
begin begin
if((str[i] >= 'A') and (str[i] <= 'Z')) then if (((str[I] >= 'A') and (str[I] <= 'Z')) or
((str[I] >= '!') and (str[I] <= '&')) or
((str[I] >= '(') and (str[I] <= '+')) or
(str[I] = ':') or
((str[I] >= '<') and (str[I] <= '@')) or
((str[I] >= '^') and (str[I] <= '_')) or
((str[I] >= '{') and (str[I] <= '~'))) then
begin begin
HoldKey(VK_SHIFT); HoldKey(VK_SHIFT);
HoldShift := True; HoldShift := True;
str[i] := lowerCase(str[i]); end;
end else
if HoldShift then K := GetKeyCode(str[I]);
HoldKey(K);
Sleep(20);
ReleaseKey(K);
if (HoldShift) then
begin begin
HoldShift:= false; HoldShift := False;
ReleaseKey(VK_SHIFT); ReleaseKey(VK_SHIFT);
end; end;
key:= GetKeyCode(str[i]);
HoldKey(key);
//BenLand100: You should probably wait here...
ReleaseKey(key);
end; end;
if HoldShift then
ReleaseKey(VK_SHIFT);
end; end;
procedure TWindow.HoldKey(key: integer); procedure TWindow.HoldKey(key: integer);

View File

@ -368,32 +368,32 @@ end;
procedure TWindow.SendString(str: string); procedure TWindow.SendString(str: string);
var var
i: integer; I, L: integer;
key: byte; C: Byte;
HoldShift : boolean; ScanCode, VK: Word;
Shift: boolean;
begin begin
HoldShift := false; L := Length(str);
for i := 1 to length(str) do for I := 1 to L do
begin begin
if((str[i] >= 'A') and (str[i] <= 'Z')) then VK := VkKeyScan(str[I]);
begin Shift := (Hi(VK) > 0);
HoldKey(VK_SHIFT); C := LoByte(VK);
HoldShift:= True; ScanCode := MapVirtualKey(C, 0);
str[i] := lowerCase(str[i]); if (ScanCode = 0) then
end else Continue;
if HoldShift then
begin if (Shift) then
HoldShift:= false; Keybd_Event(VK_SHIFT, $2A, 0, 0);
ReleaseKey(VK_SHIFT);
Keybd_Event(C, ScanCode, 0, 0);
Keybd_Event(C, ScanCode, KEYEVENTF_KEYUP, 0);
if (Shift) then
Keybd_Event(VK_SHIFT, $2A, KEYEVENTF_KEYUP, 0);
end; end;
key:= GetKeyCode(str[i]);
HoldKey(key);
//BenLand100 note: probably should wait here
ReleaseKey(key);
end;
if HoldShift then
ReleaseKey(VK_SHIFT);
end; end;
procedure TWindow.HoldKey(key: integer); procedure TWindow.HoldKey(key: integer);
begin begin
keyinput.Down(key); keyinput.Down(key);