Recent

Author Topic: lazMouseandKeyInput - Trying to fix the Press(StringValue) Procedure  (Read 124 times)

Tony Stone

  • Full Member
  • ***
  • Posts: 176
I have made some changes to the KeyInputInt.pas to properly type a string value.  This works great now on my Linux installs I have tested on.  I tested on a Windows Machine and I am running into issues with Carriage Returns/Line Feeds.  I am out of ideas for now how to correct it for Windows.  The following code is mainly what I changed:

KeyInputIntf.pas:
Code: Pascal  [Select][+][-]
  1. procedure TKeyInput.Press(StringValue: string);
  2. var
  3.   i: integer;
  4.   needShiftKey: boolean = False;
  5.   keySym: word;
  6.   ch: char;
  7. begin
  8.   i := 1;
  9.   while (i <= Length(StringValue)) do
  10.   begin
  11.     if StringValue[i] in ['A'..'Z', '~', '!', '@', '#', '$', '%', '^',
  12.       '&', '*', '(', ')', '_', '+', '{', '}', '|', ':', '"', '<', '>', '?'] then
  13.       needShiftKey := True;
  14.  
  15.     ch := UpCase(StringValue[i]);
  16.     case ch of
  17.       'A'..'Z': keySym := VK_A + (Ord(ch) - Ord('A'));
  18.       '0'..'9': keySym := VK_0 + (Ord(ch) - Ord('0'));
  19.  
  20.       '!': keySym := VK_1;
  21.       '@': keySym := VK_2;
  22.       '#': keySym := VK_3;
  23.       '$': keySym := VK_4;
  24.       '%': keySym := VK_5;
  25.       '^': keySym := VK_6;
  26.       '&': keySym := VK_7;
  27.       '*': keySym := VK_8;
  28.       '(': keySym := VK_9;
  29.       ')': keySym := VK_0;
  30.  
  31.       '~', '`': keySym := VK_LCL_TILDE;
  32.       '_', '-': keySym := VK_LCL_MINUS; //$2d;
  33.       '+', '=': keySym := VK_LCL_EQUAL; //$3d;
  34.       '{', '[': keySym := VK_LCL_OPEN_BRACKET; //$5b;
  35.       '}', ']': keySym := VK_LCL_CLOSE_BRACKET; //$5d;
  36.       '|', '\': keySym := VK_LCL_BACKSLASH; //$5c;
  37.       ':', ';': keySym := VK_LCL_SEMI_COMMA; //$3b;
  38.       '"', '''': keySym := VK_LCL_QUOTE; //$27;
  39.       '<', ',': keySym := VK_LCL_COMMA; //$2c;
  40.       '>', '.': keySym := VK_LCL_POINT; //$2e;
  41.       '?', '/': keySym := VK_LCL_SLASH; //$2f;
  42.  
  43.       #32: keySym := VK_SPACE;
  44.       #9: keySym := VK_TAB;
  45.  
  46.       //Cannot handle Windows this way.  Due to way windows needs a CR?
  47.       #10: keySym := VK_RETURN;
  48.       #13: keySym := VK_RETURN;
  49.     end;
  50.  
  51.     if needShiftKey then Apply([ssShift]);
  52.     Press(keySym);
  53.  
  54.     //if (needShiftKey) or (keySym = VK_RETURN) then // Testing something on Windows
  55.     if (needShiftKey) then
  56.     begin
  57.       Unapply([ssShift]);
  58.       needShiftKey := False;
  59.     end;
  60.  
  61.     Inc(i);
  62.   end;
  63. end;    
  64.  

And for the XKeyInput I made some additions in the VirtualKeyToXKeySym function so at least on linux I can fully automate typing every key on my keyboard at least.  I looked at the WinKeyInput and I wonder if something can be changed there to handle the carriage returns?  If you are interested please look at my test project included here and I am open to any suggestions to improve it.  Last year I really wanted this package to work as advertised and I ran out of time trying to solve it.  I ended up using xdotool to finish my project.  In the future I would really like the Lazarus packages to just work... I am hoping to put together a clean and proper solution here so it can possibly be patched and updated for all.  Thanks for taking the time to look.

 

TinyPortal © 2005-2018