I have a Lenovo L13 Yoga and Lenovo ThinkPad Pen Pro with Ubuntu 19.10 installed on it.
I'd like to be able to use certain keyboard shortcuts while the notebook is folded down (especially shift + prt screen, to select an area with my stylus to screenshot).
Is there a way to achieve this, preferably other than using an on-screen keyboard?


The easiest way I could come up with was to create a shortcut on the sidebar, that would launch a script in Python which would send the required keystrokes that would trigger, in turn, the screenshotting function.

First, you would have to install the prerequisites: python3-pip - a Python package installer, and python3 itself if you don't have it installed already. You can do that by executing the following line in the terminal:

sudo apt -y install python3 python3-pip

Next step would be to install the required package, pynput, which will send the keystrokes. This can be done by executing the following command in the terminal:

pip3 install pynput --user

Next, create a script named script.py which sends the required keystrokes in the home folder containing the following content:

from pynput.keyboard import Key, Controller

keyboard = Controller()


The last step would be to create a shortcut which can be later added to the dock for ease of access. This can be done by creating a file in the /usr/share/applications folder. For the sake of this example, I will name it shortcut.desktop (the extension here is important). Next, add the following lines to the file:

#!/usr/bin/env xdg-open
[Desktop Entry]
Exec=python3 /home/username/script.py  # change username to match your username

Now, when searching for Shortcut in the list of applications (The lowest button on the dock) you should find your shortcut which sends these keystrokes. You can also add it to your favourites.

  • @user51497, was this helpful? – Cornul11 Feb 18 '20 at 3:00

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.