winkeyinput problem lazarus / 34-Windows ---------------------------------------------------------------------- vonskie · 2014-03-31 19:06 Trying to get the below code working not sure I am using it correctly. I want to be able to read a serial device and put the output to whatever app is open like notepad. The below gets a segfault at line 52 function dodown in keyinputintf.pas Uses winkeyinput procedure TForm1.Timer1Timer(Sender: TObject); var  keyaction:TWinKeyInput; begin   keyaction.Press('Sample Reading from Serial device'); end;            What am I doing wrong and how would I do this? ---------------------------------------------------------------------- vonskie · 2014-03-31 21:34 how to use Inserttext('Hello'); Just place the cursor in whatever app you want and it will do the rest. uses windows This works like a charm procedure tform1.InsertText(keystring:string); var i:integer;     j:integer;     ch:byte;     str:string; begin   i:=1;   while i<=Length(keystring) do   begin     ch:=byte(keystring);     if Windows.IsDBCSLeadByte(ch) then        begin          Inc(i);          str:=inttostr(MakeWord(byte(keystring), ch));          keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 0), 0, 0);          j:=1;          while j<=Length(str) do          begin                keybd_event(96+strtoint(str[j]), MapVirtualKey(96+strtoint(str[j]), 0), 0, 0);                keybd_event(96+strtoint(str[j]), MapVirtualKey(96+strtoint(str[j]), 0), 2, 0);                j:=j+1;          end;          keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 0), KEYEVENTF_KEYUP, 0);        end     else begin            keybd_event(VkKeyScan(keystring),0,0,0);            keybd_event(VkKeyScan(keystring),0,2,0);          end;     Inc(i);   end; end; ---------------------------------------------------------------------- engkin · 2014-04-01 08:21 Quote from: vonskie on March 31, 2014, 09:06:23 pmWhat am I doing wrong and how would I do this? You declared a variable: Code: [Select] keyaction:TWinKeyInput; and you used it: Code: [Select]  keyaction.Press('Sample Reading from Serial device'); before assigning a value to it: Code: [Select]  keyaction := TWinKeyInput.Create; On the other hand, if you replace winkeyinput with MouseAndKeyInput you can use KeyInput and MouseInput: Code: [Select]uses ..., MouseAndKeyInput; ... procedure TForm1.Timer1Timer(Sender: TObject); begin   KeyInput.Press('Sample Reading from Serial device'); end;