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:
| procedure SendKeys(sText: String);
var i : Integer; shift : Boolean; vk, scancode : Word; ch : Char; c, s : Byte; const vk_keys : Array[0..9] of Byte=(VK_HOME, VK_END, VK_UP, VK_DOWN, VK_LEFT, VK_RIGHT, VK_PRIOR, VK_NEXT, VK_INSERT, VK_DELETE); vk_shft : Array[0..2] of Byte=(VK_SHIFT, VK_CONTROL, VK_MENU); flags : Array[FALSE..TRUE] of Integer = (KEYEVENTF_KEYUP, 0); C_ALTGRS = ['\','@','~','²','³','€','{','}','[',']'];
begin shift:=FALSE; for i:=1 to Length(sText) do begin ch:=sText[i]; if (ch>=#250) then begin s:=Ord(ch)-250; shift:=NOT Odd(s); c:=vk_shft[s shr 1]; scancode:=MapVirtualKey(c, 0); Keybd_Event(c, scancode, flags[shift], 0); end else begin vk:=0; if (ch>=#240) then c:=vk_keys[Ord(ch)-240] else if (ch>=#228) then c:=Ord(ch)-116 else if (ch<#32) then c:=Ord(ch) else begin vk:=VkKeyScan(ch); c:=LoByte(vk); end;
scancode:=MapVirtualKey(c, 0);
if (sText[i] in C_AltGRS) then Keybd_Event(VK_RMENU, MapVirtualKey(VK_RMENU,0), 0, 0) else if (NOT shift AND (Hi(vk)>0)) then Keybd_Event(VK_SHIFT, $2A, 0, 0 ); Keybd_Event( c, scancode, 0, 0 ); Keybd_Event( c, scancode, KEYEVENTF_KEYUP, 0 ); if (sText[i] in C_AltGRS) then Keybd_Event(VK_RMENU,MapVirtualKey(VK_RMENU,0), KEYEVENTF_KEYUP, 0) else if (NOT shift AND (Hi(vk)>0)) then Keybd_Event(VK_SHIFT, $2A, KEYEVENTF_KEYUP, 0);
end; Application.ProcessMessages; end; end; |