XKeyInput of LazMouseAndKeyInput package lazarus / 31-LCL ---------------------------------------------------------------------- Tony Stone · 2023-11-18 01:14 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  function VirtualKeyToXKeySym(Key: Word): TKeySym;begin  case Key of    VK_BACK: Result := XK_BackSpace;    VK_TAB: Result := XK_Tab;    VK_CLEAR: Result := XK_Clear;    VK_RETURN: Result := XK_Return;    VK_SHIFT: Result := XK_Shift_L;    VK_CONTROL: Result := XK_Control_L;    VK_MENU: Result := XK_VoidSymbol; // alt key crashes app, XK_Alt_R;  VK_CAPITAL: Result := XK_Caps_Lock;      VK_ESCAPE: Result := XK_Escape;    VK_SPACE: Result := XK_space;    VK_PRIOR: Result := XK_Prior;    VK_NEXT: Result := XK_Next;    VK_END: Result := XK_End;    VK_HOME: Result := XK_Home;    VK_LEFT: Result := XK_Left;    VK_UP: Result := XK_Up;   // VK_RIGHT: Result := XK_Right;    // causes duplicate case label error    VK_DOWN: Result := XK_Down;    VK_SELECT: Result := XK_Select;    VK_PRINT: Result := XK_Print;    VK_EXECUTE: Result := XK_Execute;     // VK_INSERT: Result := XK_Insert; // causes duplicate case label error   // VK_DELETE: Result := XK_Delete;  // causes duplicate case label error   // VK_HELP: Result := XK_Help;     // causes duplicate case label error    VK_0: Result := XK_0;    VK_1: Result := XK_1;    VK_2: Result := XK_2;    VK_3: Result := XK_3;    VK_4: Result := XK_4;    VK_5: Result := XK_5;    VK_6: Result := XK_6;    VK_7: Result := XK_7;    VK_8: Result := XK_8;    VK_9: Result := XK_9;      VK_A: Result := XK_a;  VK_B: Result := XK_b;    VK_C: Result := XK_c;    VK_D: Result := XK_d;    VK_E: Result := XK_e;    VK_F: Result := XK_f;    VK_G: Result := XK_g;    VK_H: Result := XK_h;    VK_I: Result := XK_i;    VK_J: Result := XK_j;    VK_K: Result := XK_k;    VK_L: Result := XK_l;    VK_M: Result := XK_m;    VK_N: Result := XK_n;    VK_O: Result := XK_o;    VK_P: Result := XK_p;    VK_Q: Result := XK_q;    VK_R: Result := XK_r;    VK_S: Result := XK_s;    VK_T: Result := XK_t;    VK_U: Result := XK_u;    VK_V: Result := XK_v;    VK_W: Result := XK_w;    VK_X: Result := XK_x;    VK_Y: Result := XK_y;    VK_Z: Result := XK_z;      //VK_NUMPAD0: Result := XK_KP_0;    // causes duplicate case label error    VK_NUMPAD1: Result := XK_KP_1;  VK_NUMPAD2: Result := XK_KP_2;    VK_NUMPAD3: Result := XK_KP_3;    VK_NUMPAD4: Result := XK_KP_4;    VK_NUMPAD5: Result := XK_KP_5;    VK_NUMPAD6: Result := XK_KP_6;    VK_NUMPAD7: Result := XK_KP_7;    VK_NUMPAD8: Result := XK_KP_8;    VK_NUMPAD9: Result := XK_KP_9;    VK_MULTIPLY: Result := XK_KP_Multiply;    VK_ADD: Result := XK_KP_Add;    VK_SEPARATOR: Result := XK_KP_Separator;    VK_SUBTRACT: Result := XK_KP_Subtract;    VK_DECIMAL: Result := XK_KP_Decimal;    VK_DIVIDE: Result := XK_KP_Divide;    VK_F1: Result := XK_F1;    VK_F2: Result := XK_F2;    VK_F3: Result := XK_F3;    VK_F4: Result := XK_F4;    VK_F5: Result := XK_F5;    VK_F6: Result := XK_F6;    VK_F7: Result := XK_F7;    VK_F8: Result := XK_F8;    VK_F9: Result := XK_F9;    VK_F10: Result := XK_F10;    VK_F11: Result := XK_F11;    VK_F12: Result := XK_F12;    VK_F13: Result := XK_F13;    VK_F14: Result := XK_F14;    VK_F15: Result := XK_F15;    VK_F16: Result := XK_F16;    VK_F17: Result := XK_F17;    VK_F18: Result := XK_F18;    VK_F19: Result := XK_F19;    VK_F20: Result := XK_F20;    VK_F21: Result := XK_F21;    VK_F22: Result := XK_F22;    VK_F23: Result := XK_F23;    VK_F24: Result := XK_F24;    VK_NUMLOCK: Result := XK_Num_Lock;    VK_SCROLL: Result := XK_Scroll_Lock;        VK_LCL_TILDE: Result := XK_grave;                // Added by TS    VK_LCL_MINUS: Result := XK_minus;                // Added by TS    VK_LCL_EQUAL: Result := XK_equal;                // Added by TS    VK_LCL_OPEN_BRACKET: Result := XK_bracketleft;   // Added by TS    VK_LCL_CLOSE_BRACKET: Result := XK_bracketright; // Added by TS    VK_LCL_BACKSLASH: Result := XK_backslash;        // Added by TS    VK_LCL_SEMI_COMMA: Result := XK_semicolon;       // Added by TS    VK_LCL_QUOTE: Result := XK_quoteright;           // Added by TS    VK_LCL_COMMA: Result := XK_comma;                // Added by TS    VK_LCL_POINT: Result := XK_period;               // Added by TS    VK_LCL_SLASH: Result := XK_slash;                // Added by TS    else    Result := XK_VoidSymbol;  end;  end; 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TKeyInput.Press(StringValue: string);var  i: integer;  needShiftKey: boolean = False;  keySym: word;  ch: char;begin  i := 1;  while (i <= Length(StringValue)) do  begin    if StringValue[i] in ['A'..'Z', '~', '!', '@', '#', '$', '%', '^',      '&', '*', '(', ')', '_', '+', '{', '}', '|', ':', '"', '<', '>', '?'] then      needShiftKey := True;    ch := UpCase(StringValue[i]);    case ch of      'A'..'Z': keySym := VK_A + (Ord(ch) - Ord('A'));      '0'..'9': keySym := VK_0 + (Ord(ch) - Ord('0'));        '!': keySym := VK_1;      '@': keySym := VK_2;    '#': keySym := VK_3;      '$': keySym := VK_4;      '%': keySym := VK_5;      '^': keySym := VK_6;      '&': keySym := VK_7;      '*': keySym := VK_8;      '(': keySym := VK_9;      ')': keySym := VK_0;        '~', '`': keySym := VK_LCL_TILDE;      '_', '-': keySym := VK_LCL_MINUS; //$2d;      '+', '=': keySym := VK_LCL_EQUAL; //$3d;    '{', '[': keySym := VK_LCL_OPEN_BRACKET; //$5b;      '}', ']': keySym := VK_LCL_CLOSE_BRACKET; //$5d;      '|', '\': keySym := VK_LCL_BACKSLASH; //$5c;      ':', ';': keySym := VK_LCL_SEMI_COMMA; //$3b;      '"', '''': keySym := VK_LCL_QUOTE; //$27;      '<', ',': keySym := VK_LCL_COMMA; //$2c;      '>', '.': keySym := VK_LCL_POINT; //$2e;      '?', '/': keySym := VK_LCL_SLASH; //$2f;        #32: keySym := VK_SPACE;      #9: keySym := VK_TAB;        //Cannot handle Windows this way.  Due to way windows needs a CR?      #10: keySym := VK_RETURN;      //#13: keySym := VK_RETURN;    end;      if needShiftKey then Apply([ssShift]);    Press(keySym);      //if (needShiftKey) or (keySym = VK_RETURN) then // Testing something on Windows    if (needShiftKey) then    begin      Unapply([ssShift]);    needShiftKey := False;    end;      Inc(i);  end;end; Thank you, Tony Stone ---------------------------------------------------------------------- Tony Stone · 2023-11-24 00:11 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 · 2023-11-24 10:35 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". ---------------------------------------------------------------------- Tony Stone · 2023-11-24 13:54 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 · 2023-11-24 14:02 Retype window different lines: Input !@#$%^&*()~_+`-={}|[]\:";'<>?,./ Output: !"#¤%&/()=½_=§-0()?89+;*,';:/,.7 ---------------------------------------------------------------------- Tony Stone · 2023-11-24 14:10 Quote from: bytebites on November 24, 2023, 03:02:51 pmRetype 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 · 2023-11-24 14:32 Linux, but obviously different keyboard layout. Shift is not needed to get <-sign, but only >-sign. ---------------------------------------------------------------------- Tony Stone · 2023-11-24 16:36 Quote from: bytebites on November 24, 2023, 03:32:03 pmLinux, 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 · 2023-11-25 00:07 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.