From 3fbeab9a0bb78cfdb8b27fd41c1bfe1dbcc82cf0 Mon Sep 17 00:00:00 2001 From: "John P (Dgby714)" Date: Sat, 23 Jul 2011 17:14:04 -0400 Subject: [PATCH 1/3] MML: SendKeys, added more shift characters. --- Units/MMLCore/os_linux.pas | 52 +++++++++++++++++++---------------- Units/MMLCore/os_windows.pas | 53 ++++++++++++++++++++---------------- 2 files changed, 59 insertions(+), 46 deletions(-) diff --git a/Units/MMLCore/os_linux.pas b/Units/MMLCore/os_linux.pas index 59014e4..94bdeed 100644 --- a/Units/MMLCore/os_linux.pas +++ b/Units/MMLCore/os_linux.pas @@ -413,34 +413,40 @@ implementation result := xmask and ButtonP > 0; end; - procedure TWindow.SendString(str: string); - var - i: integer; - key: byte; - HoldShift : boolean; +procedure TWindow.SendString(str: string); +var + I, L: Integer; + K: Byte; + HoldShift: Boolean; +begin + HoldShift := False; + L := Length(str); + for I := 1 to L do begin - HoldShift := false; - for i := 1 to length(str) do + 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 - if((str[i] >= 'A') and (str[i] <= 'Z')) then - begin - HoldKey(VK_SHIFT); - HoldShift:= True; - str[i] := lowerCase(str[i]); - end else - if HoldShift then - begin - HoldShift:= false; - ReleaseKey(VK_SHIFT); - end; - key:= GetKeyCode(str[i]); - HoldKey(key); - //BenLand100: You should probably wait here... - ReleaseKey(key); + HoldKey(VK_SHIFT); + HoldShift := True; end; - if HoldShift then + + K := GetKeyCode(str[I]); + HoldKey(K); + Sleep(20); + ReleaseKey(K); + + if (HoldShift) then + begin + HoldShift := False; ReleaseKey(VK_SHIFT); + end; end; +end; procedure TWindow.HoldKey(key: integer); begin diff --git a/Units/MMLCore/os_windows.pas b/Units/MMLCore/os_windows.pas index 41a7e1a..c382cd2 100644 --- a/Units/MMLCore/os_windows.pas +++ b/Units/MMLCore/os_windows.pas @@ -366,34 +366,41 @@ begin end; end; - procedure TWindow.SendString(str: string); - var - i: integer; - key: byte; - HoldShift : boolean; +procedure TWindow.SendString(str: string); +var + I, L: Integer; + K: Byte; + HoldShift: Boolean; +begin + HoldShift := False; + L := Length(str); + for I := 1 to L do begin - HoldShift := false; - for i := 1 to length(str) do + 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 - if((str[i] >= 'A') and (str[i] <= 'Z')) then - begin - HoldKey(VK_SHIFT); - HoldShift:= True; - str[i] := lowerCase(str[i]); - end else - if HoldShift then - begin - HoldShift:= false; - ReleaseKey(VK_SHIFT); - end; - key:= GetKeyCode(str[i]); - HoldKey(key); - //BenLand100 note: probably should wait here - ReleaseKey(key); + HoldKey(VK_SHIFT); + HoldShift := True; end; - if HoldShift then + + K := GetKeyCode(str[I]); + HoldKey(K); + Sleep(20); + ReleaseKey(K); + + if (HoldShift) then + begin + HoldShift := False; ReleaseKey(VK_SHIFT); + end; end; +end; + procedure TWindow.HoldKey(key: integer); begin keyinput.Down(key); From 8acb244ec36471db4b7fa8148be83c491be41b5f Mon Sep 17 00:00:00 2001 From: "John P (Dgby714)" Date: Sat, 23 Jul 2011 18:00:23 -0400 Subject: [PATCH 2/3] MML: SendKeys (win), Better way to do it. --- Units/MMLCore/os_windows.pas | 45 +++++++++++++++--------------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/Units/MMLCore/os_windows.pas b/Units/MMLCore/os_windows.pas index c382cd2..d7520d6 100644 --- a/Units/MMLCore/os_windows.pas +++ b/Units/MMLCore/os_windows.pas @@ -368,36 +368,29 @@ end; procedure TWindow.SendString(str: string); var - I, L: Integer; - K: Byte; - HoldShift: Boolean; + I, L: integer; + C: Byte; + ScanCode, VK: Word; + Shift: boolean; begin - HoldShift := False; L := Length(str); for I := 1 to L do begin - 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 - HoldKey(VK_SHIFT); - HoldShift := True; - end; - - K := GetKeyCode(str[I]); - HoldKey(K); - Sleep(20); - ReleaseKey(K); - - if (HoldShift) then - begin - HoldShift := False; - ReleaseKey(VK_SHIFT); - end; + VK := VkKeyScan(str[I]); + Shift := (Hi(VK) > 0); + C := LoByte(VK); + ScanCode := MapVirtualKey(C, 0); + + WriteLn(ScanCode); + + if (Shift) then + Keybd_Event(VK_SHIFT, $2A, 0, 0); + + 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; From 2faecb4966d556b2501b4faaf02133de517d5327 Mon Sep 17 00:00:00 2001 From: "John P (Dgby714)" Date: Sat, 23 Jul 2011 18:01:13 -0400 Subject: [PATCH 3/3] MML: SendKeys (win), Removed a WriteLn and added a small check. --- Units/MMLCore/os_windows.pas | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Units/MMLCore/os_windows.pas b/Units/MMLCore/os_windows.pas index d7520d6..6d6f77a 100644 --- a/Units/MMLCore/os_windows.pas +++ b/Units/MMLCore/os_windows.pas @@ -380,8 +380,8 @@ begin Shift := (Hi(VK) > 0); C := LoByte(VK); ScanCode := MapVirtualKey(C, 0); - - WriteLn(ScanCode); + if (ScanCode = 0) then + Continue; if (Shift) then Keybd_Event(VK_SHIFT, $2A, 0, 0);