Recent

Author Topic: MouseAndKeyInput  (Read 2654 times)

Tony Stone

  • Full Member
  • ***
  • Posts: 143
MouseAndKeyInput
« on: December 27, 2021, 06:27:26 am »
I am trying to use MouseAndKeyInput to simulate key presses.  However when i call KeyInput.Press(myString); and myString contains symbols the application crashes with exit code 1.  It also doesnt seem to type any uppercase characters when the original character is uppercase.  I am currently running linux.  Not sure how it works on Windows.

Any chance anyone can have a look at the package and point me in the right direction to fix this?

Tony Stone

  • Full Member
  • ***
  • Posts: 143
Re: MouseAndKeyInput
« Reply #1 on: January 24, 2022, 05:28:11 am »
So tonight I revisited this package and issues I was having.  I made several modifications and made the package work the way I would have expected it to work.  Now I am pretty new to this stuff so I hope I don't embarrass myself but I want to upload it here so actual professionals can check this out.  If it is a quality improvement I want to look at how to have it submitted as a patch on GitLab or however you make contributions to Lazarus!  :D

So it seems to work for typing every character ON MY 102 key US keyboard.  I don't think this helps people with non US keyboards, however I think I can solve that too.  My goal was to eliminate the need for an external tool called XDoTool to simulate keyboard input on linux.  This does the trick... although it still relies on Xtst library(I don't know how to get around that)

I am also wondering if it would be beneficial to have all of these virtual key codes in the LCL ?
https://cgit.freedesktop.org/xorg/proto/x11proto/tree/keysymdef.h

I think it would be to cover non US keyboards...  Again... I am NO EXPERT in ANY of this.... this is why I come to all of you first!  :-[


Tony Stone

  • Full Member
  • ***
  • Posts: 143
Re: MouseAndKeyInput
« Reply #2 on: January 24, 2022, 05:59:34 am »
So... I am going to bed.  But as I did a little more playing around it occurred to me that adding all of the same Virtual Key constants to the LCL that you find in the x11 library may be problematic.  My first issue is that pascal is not case sensitive so VK_A and VK_a would be the same.  I wonder if it would make sense to have VK_AA for upper case A?  and VK_A for lower case A?  I also see potential problems and breaking peoples existing code if you were to change any of that in the LCLTypes....  so I now wonder if I am simply trying to solve a problem no one else has ran into.  I will revisit this post over the next few days before I go adding thousands of Virtual Key codes to my LCLType file.  In reality the work I did so far makes my program do exactly what i expected and needed.  So maybe I leave well enough alone and not try making contributions to a huge project like Lazarus where I could be the blame for creating future issues. lol

Thaddy

  • Hero Member
  • *****
  • Posts: 11517
Re: MouseAndKeyInput
« Reply #3 on: January 24, 2022, 06:29:05 am »
I believe that they are already somewhere in the FPC RTL, but just in case, here is the h2pas conversion. Not much work, took less than 0.1 second. Know your tools  :D

Code: Bash  [Select][+][-]
  1. h2pas keysymdef.h
No need for h2pas options.

Note that there is a define per code page, so you should map those XK_<xxx> defines to the language families you want or set the define manually. Easy.

One remark more: the copyright is last changed in 1998 and there have been many, many additions after that, especially for unicode.
I suspect that keysymdef.h is an old version, but it will still work for the things that ARE included.. (e.g. smilies are not included)

[edit]
The key mappings are in ./rtl/charmaps, ./rtl/ucmaps and ./rtl/objpas in the fpc source directory rtl root. It may be that additionally the Lazarus LCL has specific mappings for UTF8, since the rtl does not directly support UTF8 (But it does support UTF16)
« Last Edit: January 24, 2022, 06:52:47 am by Thaddy »
Путин преступник. Россияне дезинформированы.

Tony Stone

  • Full Member
  • ***
  • Posts: 143
Re: MouseAndKeyInput
« Reply #4 on: January 24, 2022, 02:38:05 pm »
 :-[  lol .... welp!  You see... as I said... I don't truly know what I am doing.  And you honestly lost me with the UTF8 and UTF16 encoding(I continue running into issues where I need to fully understand this part as well)....  I will continue my studies on this subject though.  I guess my question now is simply this:  Would it be beneficial to have the VK_ contants in the LCLTypes include all of these gazillion key codes? 

On one other note... I also realized my little patch in the MouseAndKeyInput package would need to be patched for more than just the Linux platform.  So while my modifications are good for me I don't think they would be worthy of having patched for everyone.   %) 




I believe that they are already somewhere in the FPC RTL, but just in case, here is the h2pas conversion. Not much work, took less than 0.1 second. Know your tools  :D

Code: Bash  [Select][+][-]
  1. h2pas keysymdef.h
No need for h2pas options.

Note that there is a define per code page, so you should map those XK_<xxx> defines to the language families you want or set the define manually. Easy.

One remark more: the copyright is last changed in 1998 and there have been many, many additions after that, especially for unicode.
I suspect that keysymdef.h is an old version, but it will still work for the things that ARE included.. (e.g. smilies are not included)

[edit]
The key mappings are in ./rtl/charmaps, ./rtl/ucmaps and ./rtl/objpas in the fpc source directory rtl root. It may be that additionally the Lazarus LCL has specific mappings for UTF8, since the rtl does not directly support UTF8 (But it does support UTF16)

Tony Stone

  • Full Member
  • ***
  • Posts: 143
Re: MouseAndKeyInput
« Reply #5 on: January 24, 2022, 03:06:51 pm »
Know your tools  :D

Code: Bash  [Select][+][-]
  1. h2pas keysymdef.h
No need for h2pas options.



Uhm yeah... wow... After reading your reply a second time I get what you mean by know your tools.   I initially didnt realize you converted the file I posted!  So... yeah... very cool.  Thanks for that.  :)

But I still think there would be a problem with case sensitivity.  Unless I am wrong and pascal is case sensitive for constant names?   But XK_a is the same as XK_A   .....  anyway... please correct me if I am wrong on that.

I think I just need to move on to a simpler mission for today! :D
« Last Edit: January 24, 2022, 03:10:54 pm by Tony Stone »

 

TinyPortal © 2005-2018