Recent

Author Topic: winkeyinput problem  (Read 3287 times)

vonskie

  • Full Member
  • ***
  • Posts: 184
winkeyinput problem
« on: March 31, 2014, 09:06:23 pm »
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

  • Full Member
  • ***
  • Posts: 184
Re: winkeyinput problem
« Reply #1 on: March 31, 2014, 11:34:31 pm »
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

  • Hero Member
  • *****
  • Posts: 3112
Re: winkeyinput problem
« Reply #2 on: April 01, 2014, 10:21:27 am »
What 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;             

 

TinyPortal © 2005-2018