Configure a keyboard shortcut in Lubuntu 18.04 to take a screenshot of a screen region

As installed, Lubuntu 18.04 is configured so that the user can capture a screenshot of the whole screen by pressing the PrtScrn key, and a screenshot of the active window by pressing Alt+PrtScrn. However, no keyboard shortcut is configured to enable the user to capture a user-specified region of the screen.

Now, as it happens, the ‘-s‘ option of the scrot command allows a region of the screen to be captured and saved. The man page for scrot tells us:

-s, --select
Interactively select a window or rectangle with the mouse.

So here is how to configure a keyboard shortcut to do that in Lubuntu 18.04.

Open the file ~/.config/openbox/lubuntu-rc.xml in a text editor (either nano from the command line or LXTerminal from the GUI) and look for the following lines:

    <keybind key="Print">
      <action name="Execute">
        <command>lxsession-default screenshot</command>
      </action>
    </keybind>
    <keybind key="A-Print">
      <action name="Execute">
        <command>lxsession-default screenshot window</command>
      </action>
    </keybind>

Append the following lines to that group of lines:

    <keybind key="C-A-Print">
      <action name="Execute">
        <command>scrot -s</command>
      </action>
    </keybind>

The new group of lines should then look like this:

    <keybind key="Print">
      <action name="Execute">
        <command>lxsession-default screenshot</command>
      </action>
    </keybind>
    <keybind key="A-Print">
      <action name="Execute">
        <command>lxsession-default screenshot window</command>
      </action>
    </keybind>
    <keybind key="C-A-Print">
      <action name="Execute">
        <command>scrot -s</command>
      </action>
    </keybind>

Now logout and login again.

If you now press Ctrl+Alt+PrtScrn and use your mouse to select a rectangular region of the screen, a screenshot of that region will be saved automatically to your home directory. Simple.

You just have to remember:

PrtScrn — Captures the entire screen.
Alt+PrtScrn — Captures the active window.
Ctrl+Alt+PrtScrn — Captures the area of the screen you select with the mouse.

Advertisements

About Fitzcarraldo
A Linux user with an interest in all things technical.

4 Responses to Configure a keyboard shortcut in Lubuntu 18.04 to take a screenshot of a screen region

  1. Rusty says:

    I wonder if there is a way (on an ubuntu-like machine) to have a KB shortcut copy a user-selected rectangular section to the clipboard?

    • Fitzcarraldo says:

      There is. Install GNOME Screenshot:

      $ sudo apt-get install gnome-screenshot
      

      To take a screenshot of a rectangular area of the screen and save it in ~/Pictures directory:

      $ gnome-screenshot -a
      

      To copy a rectangular area of the screen and save it on the clipboard so that you can paste it into other applications:

      $ gnome-screenshot -ac
      

      You just need to set up a keyboard shortcut in the usual way for the Desktop Environment, so that the shortcut runs that command.

      See the link below for a tutorial on using GNOME Screenshot.

      https://www.howtoforge.com/tutorial/taking-screenshots-in-linux-using-gnome-screenshot/

      If you prefer KDE applications, Spectacle can do it from the GUI:

      $ sudo apt-get install kde-spectacle
      

      https://www.kde.org/images/screenshots/spectacle.png

    • Fitzcarraldo says:

      Here’s yet another way to do it…

      Install xclip if it is not already installed:

      $ sudo apt-get install xclip
      

      The following command will allow you to select any region and it will save it to the clipboard and to your home directory:

      $ scrot -s -e 'xclip -selection clipboard -target image/png -in $f'
      

      You just need to set up a keyboard shortcut in the usual way for the Desktop Environment, so that the shortcut runs that command.

      If you do not want the image to be saved to your home directory as well, change the above command to:

      $ scrot -s -e 'xclip -selection clipboard -target image/png -in $f && rm $f'
      
  2. Rusty says:

    Thanks, I hadn’t used screenshotting in Linux much (if ever) and those worked great!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.