Was recently asked to convert some code, but I have a minimalistic ammount of knowledge of delphi and I wasn't able to convert this code. If you could help me out it would be great.

void TypeStr(char *lpszString)
{
  char cChar;
  while((cChar=*lpszString++)) // loops through chars
  {
    short vk=VkKeyScan(cChar); // keycode of char
    if((vk>>8)&1){keybd_event(VK_LSHIFT,0,0,0);} // hold shift if necessary
    keybd_event((unsigned char)vk,0,0,0); // key in
    keybd_event((unsigned char)vk,0,KEYEVENTF_KEYUP,0); // key out
    if((vk>>8)&1){keybd_event(VK_LSHIFT,0,KEYEVENTF_KEYUP,0);} // release shift if necessary
  }
}

Eh, why not?

uses SysUtils, Windows;

procedure TypeStr( lpszString: pChar );
  var
    cChar: char;
    vk:    word;
  begin
  cChar := lpszString^;
  while cChar <> #0 do
    begin
    inc( lpszString );

    vk := VkKeyScan( cChar );
    if ((vk shr 8) and 1) <> 0 then keybd_event( VK_LSHIFT, 0, 0, 0 );
    keybd_event( vk and $7F, 0, 0, 0 );
    keybd_event( vk and $7F, 0, KEYEVENTF_KEYUP, 0 );
    if ((vk shr 8) and 1) <> 0 then keybd_event( VK_LSHIFT, 0, KEYEVENTF_KEYUP, 0 );

    cChar := lpszString^
    end
  end;

Enjoy.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.