LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This 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


Reply
  Search this Thread
Old 03-03-2021, 03:22 AM   #1
Garn
LQ Newbie
 
Registered: Sep 2012
Posts: 9

Rep: Reputation: Disabled
Need help with xdotool – keymaps or something…


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.
 
Old 03-03-2021, 06:20 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,691

Rep: Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274
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)
 
Old 03-03-2021, 07:05 AM   #3
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
I do not really understand the situation
I do not either. An example would be helpful.

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
Code:
xdotool key S t r a ssharp e

Last edited by shruggy; 03-07-2021 at 08:51 AM.
 
Old 03-03-2021, 08:04 AM   #4
Garn
LQ Newbie
 
Registered: Sep 2012
Posts: 9

Original Poster
Rep: Reputation: Disabled
I'll try and clarify:

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..
 
Old 03-03-2021, 09:39 AM   #5
Garn
LQ Newbie
 
Registered: Sep 2012
Posts: 9

Original Poster
Rep: Reputation: Disabled
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.

Click image for larger version

Name:	expected-output.jpg
Views:	94
Size:	20.4 KB
ID:	35776

This is the output I obtain when xdotool types the above into the remote application.

Click image for larger version

Name:	obtained-output.jpg
Views:	59
Size:	15.0 KB
ID:	35777
 
Old 03-03-2021, 09:53 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,691

Rep: Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274
would be nice to see exactly how did you use "xdotool to type that text". Can you show us that script (or the relevant part)?
 
Old 03-03-2021, 09:54 AM   #7
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
Ok, this is an old xdotool bug that rears its ugly head now and again.

Try setxkbmap -synch de before issuing the xdotool command.

Here is the statement from xdotool author:
Quote:
Originally Posted by jordansissel
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.
 
1 members found this post helpful.
Old 03-03-2021, 10:16 AM   #8
Garn
LQ Newbie
 
Registered: Sep 2012
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
would be nice to see exactly how did you use "xdotool to type that text". Can you show us that script (or the relevant part)?
Sure:

Code:
while read line
do
	xdotool type --delay 50 "$line"
	xdotool key Return
done < $1
$1 is the name of the textfile I pass to the script.
 
Old 03-03-2021, 10:24 AM   #9
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,691

Rep: Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274
(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.
 
1 members found this post helpful.
Old 03-03-2021, 10:31 AM   #10
Garn
LQ Newbie
 
Registered: Sep 2012
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by shruggy View Post
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.

Click image for larger version

Name:	obtained-output1.jpg
Views:	21
Size:	17.7 KB
ID:	35778
 
Old 03-03-2021, 11:11 AM   #11
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
This is how I tested it.

Remote machine (I tried RDP sessions via remmina, xfreerdp and rdesktop: no difference)
Code:
$ grep ^PRE /etc/os-release
PRETTY_NAME="Ubuntu 20.04.2 LTS"
$ setxkbmap -query
rules:      evdev
model:      pc105
layout:     us
$ cat /etc/default/keyboard
XKBMODEL=pc105
XKBLAYOUT=de
BACKSPACE=guess
$ localectl
   System Locale: LANG=en_US.UTF-8
                  LANGUAGE=en_US:en
                  LC_NUMERIC=de_DE.UTF-8
                  LC_TIME=de_DE.UTF-8
                  LC_MONETARY=de_DE.UTF-8
                  LC_PAPER=de_DE.UTF-8
                  LC_NAME=de_DE.UTF-8
                  LC_ADDRESS=de_DE.UTF-8
                  LC_TELEPHONE=de_DE.UTF-8
                  LC_MEASUREMENT=de_DE.UTF-8
                  LC_IDENTIFICATION=de_DE.UTF-8
       VC Keymap: us
      X11 Layout: de
       X11 Model: pc105
$ echo $XDG_SESSION_TYPE
x11
In the German keyboard layout, characters { and } are accessed via AltGr+7, AltGr+0
Code:
$ xdotool type '{hello}';echo
7hello0
$ 7hello0
Code:
$ setxkbmap -synch us;xdotool type '{hello}';echo
{hello}
$ {hello}
 
1 members found this post helpful.
Old 03-03-2021, 11:34 AM   #12
Garn
LQ Newbie
 
Registered: Sep 2012
Posts: 9

Original Poster
Rep: Reputation: Disabled
@shruggy:

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.
 
Old 03-03-2021, 12:05 PM   #13
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
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.

Last edited by shruggy; 03-04-2021 at 04:52 AM.
 
1 members found this post helpful.
Old 03-03-2021, 12:45 PM   #14
Garn
LQ Newbie
 
Registered: Sep 2012
Posts: 9

Original Poster
Rep: Reputation: Disabled
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.
 
Old 03-04-2021, 01:33 AM   #15
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,691

Rep: Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274
actually I learned something new too.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to offline install xdotool on red hat 4.8 yllawwally Linux - Newbie 8 01-29-2020 06:14 PM
xdotool - intercept keystroke for only one window class. Vryali Linux - Newbie 0 07-27-2012 12:07 PM
xdotool, XSendEvent or something like them jovie Linux - Software 1 01-09-2012 10:06 AM
LXer: Trigger keyboard and mouse actions with your voice and xdotool LXer Syndicated Linux News 0 09-06-2011 02:10 AM
how to send with xdotool a window to another Desktop X number? frenchn00b Linux - General 1 10-23-2009 12:31 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration