I'm running Fedora 22 (Linux) and have a Java application written by others that I want to send keystrokes to. I have tried to use xdotool in various ways, but I can neither set focus to the Java app nor send it keystrokes.

The app is started with javaws with the following command line:

javaws -J-XX:MaxPermSize=512M -J-d64 -J-Xms1G -J-Xmx1G /path/to/java/file

My first attempt to send it keystrokes was with this command:

xdotool search --name 'Window title' windowraise windowfocus --sync key H e l l o Return

But nothing happened. The Java window did not gain focus or see my keystrokes.

So I looked up the Java process's PID and tried identifying the process by its PID.

xdotool search --pid 1234 windowraise windowfocus --sync key H e l l o Return

Same result. Finally, I tried identifying the window with 'selectwindow'.

xdotool selectwindow windowraise windowfocus --sync key H e l l o Return

After issuing the command, the cursor changed to a square. I moved the mouse to the Java window and clicked, but this didn't work either.

To investigate further, I ran a different Java application with the following command:

java -jar appname.jar

xdotool could not set focus or send keystrokes to this window either.

Having read the xdotool documentation, I know that some programs won't accept its input. Is there something I can do, such as passing different command line arguments, to these Java apps to get them to listen to xdotool's keystrokes?

Here is some information about the versions of Java and xdotool I'm running:

$ java -version
openjdk version "1.8.0_65-debug"
OpenJDK Runtime Environment (build 1.8.0_65-debug-b17)
OpenJDK 64-Bit Server VM (build 25.65-b01-debug, mixed mode)

$ xdotool --version
xdotool version 2.20110530.1
  • xdottool is an tool that interacts with X11 windows. Java toolkits do not necessarily create proper X11 windows for every widget (though they must create at least one per top-level window). It might have something to do with that. When you say nothing happens, did you try putting another window on top of that to see whether it gets raised?
    – spectras
    Nov 6, 2015 at 5:07
  • Another possible issue would be that the application (or java or some java setting) deliberately blocks synthetic events. Some applications do this for security.
    – spectras
    Nov 6, 2015 at 5:12

1 Answer 1


Window focus is the job of the window manager. I presume you are using one. The best way to focus a window is:

xdotool search --name 'Window title' windowactivate

xdotool uses 2 mechanisms to send key events, the XTEST extension for events to send to the current focus, and XSendEvent() to send events to a given window. The latter generates events with a synthetic flag, which some applications decide means it is a security risk, so ignore the event.

However, you can still send "real" key events using xdotool, but you must not explicitly provide a window. After moving the focus to your window, use

xdotool type Hello; xdotool key Return
  • Using your suggestion, I was able to send keystrokes to the Java application's window. However, the window didn't get the keystrokes that I thought I sent. It's an authentication window (don't worry, I'm not sending a password), so maybe it's extra fussy about what characters it accepts. Because the Java application is a black box to me, I'm not going to pursue this further. Nov 10, 2015 at 23:12
  • You can try adding --clearmodifiers to the type and key commands to remove any shift or alt or caplock modifier. You can also send the actual keycodes you think the app needs (the letters you give are translated into keycodes anyway) by giving the decimal values, eg key "38+56+38" could be "aba" depending on your keyboard mapping.
    – meuh
    Nov 11, 2015 at 7:43
  • It was a good try, but it didn't help. I added --clearmodifiers and key 38 but the result didn't change. Although I only sent one key, the application must have thought I pressed Enter (or it saw something it didn't like) because it immediately displayed an error message. Nov 19, 2015 at 3:41
  • Perhaps the window id found by xdotool search is not the right one. Apps sometimes have several windows unmapped to optimise their appearance on demand. Try xwininfo -tree then click on the java app window, and check that the window ids listed match one from xdotool. You could try sending a key explicitly to each of these ids.
    – meuh
    Nov 19, 2015 at 7:11
  • The windowactivate command appears to work: the cursor blinks in a text entry field in the window where I want the keystrokes to go. And when I send a keystroke, the window that I want to receive it reacts--it just reacts the wrong way by giving me an error message. I will try xwininfo later today and let you know what I find--can't do it now. Nov 19, 2015 at 12:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.