any way to take screenshots with a keyboard key?

I'm looking for something of the effect of, Prt Screen key, then pasting it into GIMP (or another program). Is there any way to do this? Or do I have to set up a screenshot terminal command on timers?
 
pkg install xbindkeys

touch .xbindkeysrc file and put whatever screenshot program you want in quotes and Print after like this
Code:
"scrot"
  Print
then type xbindkeys and now when you press printscreen key it will take a screenshot
add xbindkeys to your .xinitrc or whatever so it's always there
 
It should already be working if you have KDE or Mate. Have you tried pressing the Prt Screen key yet?
 
I'm looking for something of the effect of, Prt Screen key, then pasting it into GIMP (or another program).
I'm using icewm.
I use IceWM from time to time. x11-wm/icewm has a keys configuration file (per user or global, see icewm-keys(5) for location), where a keybinding can be set to take a screenshot with a screenshot utility, no additional keybind utility necessary.

For example with graphics/maim (that's what I use on my system ), per user, ~/.icewm/keys file, "Print Screen" (or PrtSc) key:
Rich (BB code):
key    "Print"        maim -su  $HOME/Pictures/Screenshots/Screenshot-`date '+%F-%T'`.png
EDIT: Please see comment #7 for key configuration.

The above graphics/maim can be combined with x11/xclip to copy to clipboard and pasted into GIMP.

Other screenshot utilities can send the screenshot directly to the clipboard, deskutils/gnome-screenshot for example.

gnome-screenshot(1)
Code:
OPTIONS
       -c, --clipboard
          Send the grab directly to    the clipboard.

There might be other utilities which can do the same, I haven't investigated.
 
Last edited:
My system is also icewm with no desktop. My keyboard (Keychron V1) doesn't have a Print key or a PrtScr key. My keys file:

Code:
# print screen
key "Alt+Ctrl+s"  maim -u  ~/Pictures/Screenshots/Screenshot-`date '+%F-%T'`.png

# print active window
key "Alt+Ctrl+w"  maim -ui $(xdotool  getactivewindow)  ~/Pictures/Screenshots/Screenshot-`date '+%F-%T'`.png

#test
key "Alt+Ctrl+t" xterm

maim as in both lines in the keys file works from a terminal but not from the keyboard. The key combination for opening a terminal does work. I put maim in my .xinitrc with no effect. Not sure whether just adding maim & to the line above exec wm-session is the way to do that. Also tried using icesh which didn't work either. Could it be a problem with the keyboard?
 
The key configuration from comment #5 doesn't work for me either.

Looking closer into the issue, Icewm apparently doesn't read the icewm-keys(5) file as a executable script, which is necessary to set the users login directory environment variable $HOME (or ~/ ) in the snapshot image file path, and to execute the date(1) sub-command. Removing $HOME ( ~/ ) from image file path takes a screenshot, but no date is appended.

I've checked a couple of old test user accounts running Icewm, none of them has a maim key configuration as shown in comment #5. It's quite possible I wrote the key configuration in the comment from memory, duplicating from another WM and not tested it actually in Icewm. Usually I test such configurations before posting in forums, perhaps I didn't have access to a system at the time I wrote this comment, I don't recall.

Probably I remembered the key configuration from x11-wm/herbstluftwm (located under the same user account), which has such a configuration and reads its configuration file (called "autostart") as a executable (bash) script.

Please excuse the misinformation. I have corrected my comment above.


Use a shell script to define the maim command instead, place it under ~/bin (which is in the user's $PATH) and have the script executed by the Icewm key configuration.

Example script:

~/bin/maims.sh
Code:
#!/bin/sh

maim -u  ~/Pictures/Screenshots/Screenshot-`date '+%F-%T'`.png

chmode 700 ~/bin/maims.sh

~/.config/icewm/keys (or ~/.icewm/keys)
Code:
key "Alt+Ctrl+s"  maims.sh

Create another script for "Alt+Ctrl+w" (i.e. file name maimw.sh)

I myself use maim scripts on my main WM (Openbox) for screenshot keyboard shortcut configuration, specified in Openbox configuration file.
 
  • Thanks
Reactions: bga
I do screenshots with x11/xwd xwd(1) (used that on xfce and now on fvwm)

To have a bit more comfort I have a key-combo bind to activate a tiny script,
which also renames and converts the screenshots:

Code:
#!/bin/sh
# do the screenshot with my options (see man xwd)
xwd -nobdrs -silent -out ~/path/to/folder/screenshot.xwd

# wanna have the timestamp as filename, so generate a temp file 't'
# it's ugly that way, but it works
date "+%Y%m%d_%T" > ~/path/to/folder/t
i=`cat ~/path/to/folder/t`

# now use ImageMagick's tool convert to make a JPG out of the .xwd
convert ~/path/to/folder/screenshot.xwd ~/path/to/folder/screenshot_${i}.JPG

# clean up the garbage
rm ~/path/to/folder/screenshot.xwd
rm ~/path/to/folder/t

exit 0

Could be done more elegant, above all to have the path/to/folder being within a variable, and not coded fixed.
But those are the results if you once started while being a bloody newb on scripting, and never took the time to 'update' a working piece of code :cool:
 
  • Thanks
Reactions: bga
I was thinking to use a script but didn't know exactly how I would do it yet; T-Daemon did it for me. Thanks. --also showed, I think, that better to use the environmental variable $HOME instead of ~/ in a script.
Thanks too to %pupil - skeptical.
 
if using x11-wm/i3 and graphics/scrot you can:

Code:
$ fgrep -i print .config/i3/config
bindsym Print exec beep -g 90 && scrot "${HOME}/Desktop/%Y-%m-%d-%H%M%S-_--_screen_$(uname -n).png" && notify-send -t 1000 --app-name scot screenshot
bindsym Ctrl+Print exec beep -g 90 && scrot --focused "${HOME}/Desktop/%Y-%m-%d-%H%M%S-_--_screen_$(uname -n).png" && notify-send -t 1000 --app-name scot screenshot
bindsym Shift+Ctrl+Print exec beep -g 90 && scrot --select "${HOME}/Desktop/%Y-%m-%d-%H%M%S-_--_screen_$(uname -n).png" && notify-send -t 1000 --app-name scot screenshot
 
1724374717646.pngThe Print (Print Scrn) key is the default shortcut to launch Spectacle in Plasma:
 
For what it does, the script does look strikingly baroque.
It is.
I am totally aware of that.
I'm pretty sure I said and admitted it.
Today of course I would do it better, 'cause I learned since then.
(And you don't even need a script for that. You could bind that pipe directly to a key)
It's ugly, very noobish, but it works though.

I post such primitive, non-elegant things to encourage newcomers to dare to write scripts on themselves.
'Okay, got the idea. But this rubbish can be done better.'
Not just copy-paste from the internet.

I think it's easier to comprehend for a starter what is done, if it's done step by step,
while pipes may look cryptic to a beginner, especially when variables in sh/bash style are involved, may put one off.

Avoid doing anything unless you're perfect will make you do nothing.
One has to start somewhere. The earlier, the better.

And we're not talking release such as a port.
I'm talking 'doing it for youself on your machine for your own purposes, only.'
If it works for you, it's okay. Nobody will judge, 'cause nobody will see it :sssh:
Except of course you dare posting it in the forums 😂
But I can stand it.
By now I also know how to do it better.
 
Back
Top