2

I want to write a script that changes the window focus, and sends keyboard commands, such as print screen, and arrow keys, to the system. As in I need print screen to capture my desktop, not the script window.

I can do it manually, but it is tedious, as I have a lot of screenshots to take.

I see that I can use xdotool for this. What is the key name for print-screen? (I am away from my Linux terminal, and I can't use xev remotely) alternatively, how can I figure out the names of keys, using something besides xev?

2
  • please state your question Commented Nov 5, 2014 at 20:11
  • Depends which OS you are on. osascript can do this easily although I'm not sure your OS has it. Commented Nov 5, 2014 at 20:20

1 Answer 1

2

No need to "invoke" the PrtSrn button, if you install ImageMagick then you can do the following in your script:

import -window root output.png 

If you want a particular window you can try to find its id first with wmctrl (the following captures the Firefox window displaying this post, the grep-ed string has to be unique.):

id=$(wmctrl -l | grep -F 'bash - simulate' | cut -d ' ' -f 1) import -window $id window.png 

Alternatively, if you know the part of the screen you need is on a particular place, you can grab the whole screen and then use convert -chop to cut out what you need from the desktop image.

ImageMagick is normally installed using a package named imagemagick

10
  • is that python? Commented Nov 5, 2014 at 20:18
  • No that actually a command that is part of the ImageMagick suite. Commented Nov 5, 2014 at 20:19
  • Do you know how I might specify a particular area of the screen? I just started reading the man page Commented Nov 5, 2014 at 20:23
  • How do I get the window ID? Commented Nov 5, 2014 at 20:27
  • The window ID is not so easy to get you can use wmctrl to extract it based on the window title. If the window is positioned on the same spot every time, I would grab the screen and use convert -chop to select the part you need. Commented Nov 5, 2014 at 20:30

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.