[SOLVED] Need help with xdotool – keymaps or something…
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I’m using xdotool to type text for me. That text is written on a Spanish keyboard into a text editor.
The text contains special characters which are not produced identically and are not located on the same keys across keyboards.
My workflow now involves saving the text to to a file and have a script feed that text to xdotool for typing into the text fields of an application that runs on a (Windows) terminal server which I access via RDP (I user Remmina, in case that is relevant). The remote machine has German localisation.
When I type into those text fields manually, I have no issues, i.e. all special characters are typed correctly.
However, if xdotool does the typing none of the special characters work correctly. Umlauts, ß and things like square and curly braces which on a German keyboard are not located at he same positions, do not get typed correctly or do not get typed at all.
I have tried setxkbmap de without success.
Thanks for reading and grateful for any pointers you may have.
I do not really understand the situation, but if I understand well:
the Spanish chars you wanted to enter do not exist if you use German local. Probably I would try to switch to the same local on both sides or use a common/international settings.
(see the command locale)
IIRC, xdotool lets you specify keystrokes as X Keysym definitions. I assume you're specifying ß as ssharp, right? E.g. the German word Straße (street) should be fed to xdotool as
I have/produce text on a machine with Spanish localisation. The Spanish keyboard allows me to type, for example ä, ö, ß and so on, so I can write German text with it. On the Spanish keyboard, however, the keys to type those characters are composite - I first type " then a to get ä, or CTRL+s to get ß, for instance. On a German keyboard you have separate keys for those characters. The keyboard layout is different.
Something similar happens with other characters, such as [ and ] and { and } and also #. Also, y/Y and z/Z are swapped around, presumably because the Spanish keyboard is QWERTY and the German one QERTZ.
In the RDP session while using the remote application (a homebrew content management system) I can type those characters just like I would on my local system, from my keyboard.
I can't copy/paste into The remote application and so in order to avoid having to retype existing text, I want to save the text file locally and use xdotool to type that text. So I use a script to read the text from file and feed it into xdotool. This works well, except for the fact that characters are getting changed. For example, y becomes z, # becomes ç and so on.
(I'm not on my work computer right now, but I'll post examples when I get back - meanwhile, I hope this helps).
PS: I wonder whether the Spanish localisation has anything to do wit this. If I copy text from a German website into a text editor and pass that to xdotool via the script, the same thing happens..
This is the expected output. This works on my local machine. So I produce this text file on the local computer and have xdotool type it into an editor on the local machine.
This is the output I obtain when xdotool types the above into the remote application.
I never was able to find a solution to this. I tried hard to debug this, and to the best of my knowledge, xdotool is doing the right things. My best guess is that there is some bug between xkbcommon and X11's keyboard map where things fall out of sync somehow and xdotool is given incorrect information about the current keyboard mapping -- the strongest hypothesis I had was that Xorg has a bug. I haven't pursued this in years, so it's possible my memory is incorrect.
For users, I'd like this to be resolved, but I have run out of energy to try and fix this specific issue. Most users are able to compensate for this issue by running setxkbmap themselves to fix whatever misalignment happens in Xorg such that xdotool receives the correct key mapping.
(offtopic)
I remember there was a similar issue (in 1992, on SCO unix). Depending on the keyboard and locale settings the remote X terminal did something similar, the keypress or char from file was converted to something strange, so the displayed text was quite similar to the example in post #5. (there was no utf, xdotool that time). Now the situation is even more difficult, because we have now RDP, utf (or something similar), much better X, xdotool and probably windows involved.
Try setxkbmap -synch de before issuing the xdotool command.
No fun, I'm afraid. Instead of typing nothing, y and z get switched around and characters in the positions on the German keyboard are replaced by the ones on the Spanish keyboard at that same position. Interesting... but alas I'm not smart enough to do anything with that information.
I'm afraid that doesn't mean much to me. I'll try though:
Quote:
Remote machine...etc
You tested a remote RDP session on a machine with German localisation? I assume that's what the first code block means?
In my case, I only have access to the remote application. I can't do anything else on the remote machine.
Quote:
In the German keyboard layout ...etc
You typed, on your local machine as if you were using a German keyboard? Sent that to the remote machine via xdotool and it came out correctly?
Sorry if I got that wrong, but I'm not all that savvy.
This is what I tried - it wokred, but...
I did get the expected output when I reconfigured the keyboard systemwide using
Code:
sudo dpkg-reconfigure keyboard-configuration
and set everything to German. Not pretty plus it requires a reboot. But in a pinch...
So if you could elaborate on what you did, I'd be grateful.
I have a remote machine running Xubuntu 20.04 with German localization, yes. But the keyboard layout for my user there was set to us via xfce4-settings. The setxkbmap -query command shows the current keyboard layout for my user account.
That remote machine has xrdp and xorgxrdp installed, so I can login there using RDP via an RDP client. I tried three of such clients (xfreerdp, rdesktop, remmina), but there was no difference.
After logging in, I opened the terminal, and issued the xdotool type '{hello}' command.
When I was logged in locally (well, technically that remote machine is in the next room), it worked as expected, and I got {hello} as output.
But when logging in from another Linux machine via an RDP client and doing the same, the output was 7hello0 as if the machine were configured to use the German keyboard layout (it wasn't, or rather it was, but not for the logged-in user). That was unexpected. setxkbmap -synch fixed this, but only until I logged out.
Looks like setxkbmap de does work after all. Although I'm not sure because at this point I was just fooling around and trying a bunch of things, I think that adding the German keyboard layout in the xfce settings manager did the trick.
So thanks again to @shruggy and @pan64 for their help.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.