Guest User

Untitled

a guest
Jun 17th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.58 KB | None | 0 0
  1. procedure TForm1.SendKeys(sText: String);
  2.  
  3. var
  4.  i             : Integer;
  5.  shift         : Boolean;
  6.  vk, scancode   : Word;
  7.  ch            : Char;
  8.  c, s          : Byte;
  9. const
  10.  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);
  11.  vk_shft       : Array[0..2] of Byte=(VK_SHIFT, VK_CONTROL, VK_MENU);
  12.  flags         : Array[FALSE..TRUE] of Integer = (KEYEVENTF_KEYUP, 0);
  13.  C_ALTGRS = ['\','@','~','²','³','€','{','}','[',']'];
  14.  
  15. begin
  16.  shift:=FALSE;
  17.  for i:=1 to Length(sText) do begin
  18.    ch:=sText[i];
  19.      if (ch>=#250) then begin
  20.      s:=Ord(ch)-250;
  21.      shift:=NOT Odd(s);
  22.      c:=vk_shft[s shr 1];
  23.      scancode:=MapVirtualKey(c, 0);
  24.      Keybd_Event(c, scancode, flags[shift], 0);
  25.    end else begin
  26.      vk:=0;
  27.      if (ch>=#240) then
  28.        c:=vk_keys[Ord(ch)-240]
  29.      else if (ch>=#228) then
  30.        c:=Ord(ch)-116
  31.      else if (ch<#32) then
  32.        c:=Ord(ch)
  33.      else begin
  34.        vk:=VkKeyScan(ch);
  35.        c:=LoByte(vk);
  36.      end;
  37.  
  38.      scancode:=MapVirtualKey(c, 0);
  39.  
  40.      if (sText[i] in C_AltGRS) then Keybd_Event(VK_RMENU, MapVirtualKey(VK_RMENU,0), 0, 0)
  41.      else if (NOT shift AND (Hi(vk)>0)) then Keybd_Event(VK_SHIFT, $2A, 0, 0 );
  42.      Keybd_Event( c, scancode, 0, 0 );
  43.      Keybd_Event( c, scancode, KEYEVENTF_KEYUP, 0 );
  44.      if (sText[i] in C_AltGRS) then Keybd_Event(VK_RMENU,MapVirtualKey(VK_RMENU,0), KEYEVENTF_KEYUP, 0)
  45.      else if (NOT shift AND (Hi(vk)>0)) then Keybd_Event(VK_SHIFT, $2A, KEYEVENTF_KEYUP, 0);
  46.  
  47.    end;
  48.    Application.ProcessMessages;
  49.  end;
  50. end;
Add Comment
Please, Sign In to add comment