Recent

Author Topic: XKeyInput of LazMouseAndKeyInput package  (Read 1725 times)

Tony Stone

  • Sr. Member
  • ****
  • Posts: 279
XKeyInput of LazMouseAndKeyInput package
« on: November 18, 2023, 02:14:34 am »
I have added some key mappings to the XKeyInput unit of the LazMouseAndKeyInput package.  I would like to see if some one can explain the following issues I am having.  Several of the keymappings give me a duplicate case label error when compiling.  Not sure I am able to figure out why as none of theConstants I am using are actually being duplicated.  Also I am wondering if the developers can add my additional keymappings(Ihave tested and they work) to the actual source so when I update with FPCUpDeluxe I don't have to replace with my changed files again.  I personally have no idea how to attempt to contribute patches yet and GIT confuses me a bit too much still to even try.


Code: Pascal  [Select][+][-]
  1.  
  2. function VirtualKeyToXKeySym(Key: Word): TKeySym;
  3. begin
  4.   case Key of
  5.     VK_BACK: Result := XK_BackSpace;
  6.     VK_TAB: Result := XK_Tab;
  7.     VK_CLEAR: Result := XK_Clear;
  8.     VK_RETURN: Result := XK_Return;
  9.     VK_SHIFT: Result := XK_Shift_L;
  10.     VK_CONTROL: Result := XK_Control_L;
  11.     VK_MENU: Result := XK_VoidSymbol; // alt key crashes app, XK_Alt_R;
  12.     VK_CAPITAL: Result := XK_Caps_Lock;
  13.  
  14.  
  15.     VK_ESCAPE: Result := XK_Escape;
  16.     VK_SPACE: Result := XK_space;
  17.     VK_PRIOR: Result := XK_Prior;
  18.     VK_NEXT: Result := XK_Next;
  19.     VK_END: Result := XK_End;
  20.     VK_HOME: Result := XK_Home;
  21.     VK_LEFT: Result := XK_Left;
  22.     VK_UP: Result := XK_Up;
  23.    // VK_RIGHT: Result := XK_Right;    // causes duplicate case label error
  24.     VK_DOWN: Result := XK_Down;
  25.     VK_SELECT: Result := XK_Select;
  26.     VK_PRINT: Result := XK_Print;
  27.     VK_EXECUTE: Result := XK_Execute;
  28.  
  29.  
  30.    // VK_INSERT: Result := XK_Insert; // causes duplicate case label error
  31.    // VK_DELETE: Result := XK_Delete;  // causes duplicate case label error
  32.    // VK_HELP: Result := XK_Help;     // causes duplicate case label error
  33.     VK_0: Result := XK_0;
  34.     VK_1: Result := XK_1;
  35.     VK_2: Result := XK_2;
  36.     VK_3: Result := XK_3;
  37.     VK_4: Result := XK_4;
  38.     VK_5: Result := XK_5;
  39.     VK_6: Result := XK_6;
  40.     VK_7: Result := XK_7;
  41.     VK_8: Result := XK_8;
  42.     VK_9: Result := XK_9;
  43.  
  44.  
  45.     VK_A: Result := XK_a;
  46.     VK_B: Result := XK_b;
  47.     VK_C: Result := XK_c;
  48.     VK_D: Result := XK_d;
  49.     VK_E: Result := XK_e;
  50.     VK_F: Result := XK_f;
  51.     VK_G: Result := XK_g;
  52.     VK_H: Result := XK_h;
  53.     VK_I: Result := XK_i;
  54.     VK_J: Result := XK_j;
  55.     VK_K: Result := XK_k;
  56.     VK_L: Result := XK_l;
  57.     VK_M: Result := XK_m;
  58.     VK_N: Result := XK_n;
  59.     VK_O: Result := XK_o;
  60.     VK_P: Result := XK_p;
  61.     VK_Q: Result := XK_q;
  62.     VK_R: Result := XK_r;
  63.     VK_S: Result := XK_s;
  64.     VK_T: Result := XK_t;
  65.     VK_U: Result := XK_u;
  66.     VK_V: Result := XK_v;
  67.     VK_W: Result := XK_w;
  68.     VK_X: Result := XK_x;
  69.     VK_Y: Result := XK_y;
  70.     VK_Z: Result := XK_z;
  71.  
  72.  
  73.     //VK_NUMPAD0: Result := XK_KP_0;    // causes duplicate case label error
  74.     VK_NUMPAD1: Result := XK_KP_1;
  75.     VK_NUMPAD2: Result := XK_KP_2;
  76.     VK_NUMPAD3: Result := XK_KP_3;
  77.     VK_NUMPAD4: Result := XK_KP_4;
  78.     VK_NUMPAD5: Result := XK_KP_5;
  79.     VK_NUMPAD6: Result := XK_KP_6;
  80.     VK_NUMPAD7: Result := XK_KP_7;
  81.     VK_NUMPAD8: Result := XK_KP_8;
  82.     VK_NUMPAD9: Result := XK_KP_9;
  83.     VK_MULTIPLY: Result := XK_KP_Multiply;
  84.     VK_ADD: Result := XK_KP_Add;
  85.     VK_SEPARATOR: Result := XK_KP_Separator;
  86.     VK_SUBTRACT: Result := XK_KP_Subtract;
  87.     VK_DECIMAL: Result := XK_KP_Decimal;
  88.     VK_DIVIDE: Result := XK_KP_Divide;
  89.     VK_F1: Result := XK_F1;
  90.     VK_F2: Result := XK_F2;
  91.     VK_F3: Result := XK_F3;
  92.     VK_F4: Result := XK_F4;
  93.     VK_F5: Result := XK_F5;
  94.     VK_F6: Result := XK_F6;
  95.     VK_F7: Result := XK_F7;
  96.     VK_F8: Result := XK_F8;
  97.     VK_F9: Result := XK_F9;
  98.     VK_F10: Result := XK_F10;
  99.     VK_F11: Result := XK_F11;
  100.     VK_F12: Result := XK_F12;
  101.     VK_F13: Result := XK_F13;
  102.     VK_F14: Result := XK_F14;
  103.     VK_F15: Result := XK_F15;
  104.     VK_F16: Result := XK_F16;
  105.     VK_F17: Result := XK_F17;
  106.     VK_F18: Result := XK_F18;
  107.     VK_F19: Result := XK_F19;
  108.     VK_F20: Result := XK_F20;
  109.     VK_F21: Result := XK_F21;
  110.     VK_F22: Result := XK_F22;
  111.     VK_F23: Result := XK_F23;
  112.     VK_F24: Result := XK_F24;
  113.     VK_NUMLOCK: Result := XK_Num_Lock;
  114.     VK_SCROLL: Result := XK_Scroll_Lock;
  115.  
  116.  
  117.  
  118.  
  119.     VK_LCL_TILDE: Result := XK_grave;                // Added by TS
  120.     VK_LCL_MINUS: Result := XK_minus;                // Added by TS
  121.     VK_LCL_EQUAL: Result := XK_equal;                // Added by TS
  122.     VK_LCL_OPEN_BRACKET: Result := XK_bracketleft;   // Added by TS
  123.     VK_LCL_CLOSE_BRACKET: Result := XK_bracketright; // Added by TS
  124.     VK_LCL_BACKSLASH: Result := XK_backslash;        // Added by TS
  125.     VK_LCL_SEMI_COMMA: Result := XK_semicolon;       // Added by TS
  126.     VK_LCL_QUOTE: Result := XK_quoteright;           // Added by TS
  127.     VK_LCL_COMMA: Result := XK_comma;                // Added by TS
  128.     VK_LCL_POINT: Result := XK_period;               // Added by TS
  129.     VK_LCL_SLASH: Result := XK_slash;                // Added by TS
  130.  
  131.  
  132.   else
  133.     Result := XK_VoidSymbol;
  134.   end;
  135.  
  136.  
  137. end;  
  138.  


There was only a handful(maybe 10 keys I added) and then I made some changes in the TKeyInput.Press procedure of KeyInputIntf unit to handle uppercase and lower case letters but I had an issue with testing on Windows with the new line character.  So if anyone knows how to fix my issues or sees the issue imediatley I woud appreciate the feedback to correct and if someone has the ability to patch this into Lazarus I think it would be useful for all users of Lazarus.

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


Thank you,
Tony Stone

Tony Stone

  • Sr. Member
  • ****
  • Posts: 279
Re: XKeyInput of LazMouseAndKeyInput package
« Reply #1 on: November 24, 2023, 01:11:16 am »
Well this is as far as I got and it does pretty much any character now on my system and uses the unicode character code for characters without a mapping.  I put together a crummy little test program... the package is included.  As far as I can tell it is way more functional than the original package included with Lazarus.  I have not been able to test on Mac or Windows... but if anyone is interested I think this could be a useful package... specially if a real programmer can go through my changes and correct or point out issues.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4660
  • I like bugs.
Re: XKeyInput of LazMouseAndKeyInput package
« Reply #2 on: November 24, 2023, 11:35:14 am »
Your project does not compile.
 unit1.pas(46,12) Error: identifier idents no member "PressString"

If you want to fix or extend LazMouseAndKeyInput package, you must learn to make a patch (or a merge request).
A patch is easy.
Clone the sources from GitLab.
Create a local feature branch "git switch -c mybranch".
Make your changes, then commit them.
Then create a patch with "git format-patch main".
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

Tony Stone

  • Sr. Member
  • ****
  • Posts: 279
Re: XKeyInput of LazMouseAndKeyInput package
« Reply #3 on: November 24, 2023, 02:54:35 pm »
Hmmm... I'll take a look tonight.  I'm quite sure I had it compiling before I cleaned it up and used the publish project tool.  So yes last night I started reading how to do a patch. This weekends goal is to learn how to make a patch.

bytebites

  • Hero Member
  • *****
  • Posts: 776
Re: XKeyInput of LazMouseAndKeyInput package
« Reply #4 on: November 24, 2023, 03:02:51 pm »
Retype window different lines:
Input !@#$%^&*()~_+`-={}|[]\:";'<>?,./

Output: !"#¤%&/()=½_=§-0()?89+;*,';:/,.7


Tony Stone

  • Sr. Member
  • ****
  • Posts: 279
Re: XKeyInput of LazMouseAndKeyInput package
« Reply #5 on: November 24, 2023, 03:10:07 pm »
Retype window different lines:
Input !@#$%^&*()~_+`-={}|[]\:";'<>?,./

Output: !"#¤%&/()=½_=§-0()?89+;*,';:/,.7



Well dang... Working perfect on my Linux machine.  I suppose it's still a start.  The original package couldn't even do upper case letters or symbols.  What platform did you test it on?  I don't have a Windows machine or a Mac to test on unfortunately.  Well I did just get a Mac but it's useless because you need to create an Apple account to install the OS 🤬.

bytebites

  • Hero Member
  • *****
  • Posts: 776
Re: XKeyInput of LazMouseAndKeyInput package
« Reply #6 on: November 24, 2023, 03:32:03 pm »
Linux, but obviously different keyboard layout.

Shift is not needed to get <-sign, but only >-sign.

Tony Stone

  • Sr. Member
  • ****
  • Posts: 279
Re: XKeyInput of LazMouseAndKeyInput package
« Reply #7 on: November 24, 2023, 05:36:37 pm »
Linux, but obviously different keyboard layout.

Shift is not needed to get <-sign, but only >-sign.

well I guess this could be a real issue I suppose. I was quite certain that keyboard layout would not matter because I thought that would be dealt with in the xtst library which is kind of the purpose of the virtual key mappings. So after a quick web search I think I am starting to understand the issue with different keyboard layouts.  My first thought to address this would be to attempt to detect the keyboard layout.... But as far as UTF 8 characters go the layout should not matter... ok anyway... my research continues tonight. :)

Tony Stone

  • Sr. Member
  • ****
  • Posts: 279
Re: XKeyInput of LazMouseAndKeyInput package
« Reply #8 on: November 25, 2023, 01:07:38 am »
So yeah, did some testing with changing my keyboard layout to an AZERTY layout and the VK mappings become useless.  So with various keyboard layouts it has now become evident that trying to detect them all will be a pretty lengthy process to make key mappings for. The Virtual Key mappings in LCLType unit are essentially meaningless unless the end user has a US English QWERTY keyboard layout.... hmmmm...  so I suppose this may be the reason no one has bothered to extend or improve the LazMouseAndKeyInput package?  Not sure how to proceed. 

 

TinyPortal © 2005-2018