如何使用应用程序菜单选择截取整个桌面的屏幕截图?

kar*_*k87 14 screenshot

我想使用应用程序菜单选项截取整个桌面的屏幕截图。如何执行此操作?

Sid*_*Sid 22

  • 应用程序 > 附件 > 截屏 > 抓取整个桌面 > 延迟 5 秒后抓取(比如说)

替代文字

  • 做你的应用程序菜单选择。等待。


小智 5

其实,这可以做到这一点没有延迟,但也有一些黑客来代替。我写了一个小脚本,可以让你毫不拖延地做到这一点。这是一个很大的技巧,但它确实有效并且(对我而言)肯定比使用延迟更可取。

#!/bin/bash
######################################################################################
# Simple script to enable users to make screenshots of tooltips/menus/etc...         # 
# without timers                                                                     #
######################################################################################

######################################################################################
# Configuration Section (defaults)                                                   #
######################################################################################
SCREENSHOT_COMMAND="shutter -s"

# The keys can be found out using xinput test "keyboard name"
MODIFIER_KEY=133 #The <Super> Key (aka. Meta or Windows Key)f
CANCEL_KEY=54 # C
CAPTURE_KEY=27 # R

DAEMON_MODE="false" # change to true if you want to keep the script running after the screenshot was taken
VERBOSE="true" #Change this to any value if you dont want to have notifications

######################################################################################

######################################################################################
# Command parsing                                                                    #
######################################################################################

function usage {
    echo "$0 [-hemrcdn]"
    echo "-h prints this message"
    echo "-e <command> - execute that command instead of shutter"
    echo "-m <int> - The modifier key to use. Use xinput test <keyboar> to find out what is what"
    echo "-r <int> - The key to use for capture."
    echo "-c <int> - The key used for cancelling (only valid in non daemon mode)"
    echo "-d - daemon mode. Will keep on running after a screenshot was taken. to kill the daemon, use \"killall xinput\""
    echo "-n - disables notifications"
    exit;
}

while getopts "he:m:r:c:dn" flag
do
    if [ "$flag" == "h" ]; then
        usage
    fi
    if [ "$flag" == "e" ]; then
        SCREENSHOT_COMMAND=$OPTARG
    fi
    if [ "$flag" == "m" ]; then
        CAPTURE_KEY=$OPTARG
    fi
    if [ "$flag" == "r" ]; then
        SCREENSHOT_COMMAND=$OPTARG
    fi
    if [ "$flag" == "c" ]; then
        CANCEL_KEY=$OPTARG
    fi
    if [ "$flag" == "d" ]; then
        DAEMON_MODE="true"
    fi
    if [ "$flag" == "n" ]; then
        VERBOSE="false"
    fi
done

######################################################################################

KEYBOARDS=`xinput list | grep "slave" | grep "keyboard" | sed "s/[^a-zA-Z]*\(.*\)id=.*/\1/" | sed "s/[\t ]*$//"`

function run {
    MODIFIER_PRESSED="false"
    while read line;
    do
        COMMAND=`echo $line | awk '{print $2;}'`
        KEY=`echo $line | awk '{print $3;}'`
        if [ "$KEY" == "$MODIFIER_KEY" ]; then
            if [ "$COMMAND" == "press" ]; then
                MODIFIER_PRESSED="true"
            else 
                MODIFIER_PRESSED="false"
            fi
        fi 
        if [ "$KEY" == "$CAPTURE_KEY" -a "$MODIFIER_PRESSED" == "true" -a "$COMMAND" == "press" ]; then
            bash -c $SCREENSHOT_COMMAND
            if [ "$VERBOSE" == "true" ]; then
                notify-send "Taking Screenshot"     
            fi
            if [ "$DAEMON_MODE" == "false" ]; then
                quit
            fi
        fi
        if [ "$KEY" == "$CANCEL_KEY" -a "$MODIFIER_PRESSED" == "true" -a "$COMMAND" == "press" -a "$DAEMON_MODE" == "false" ]; then
            if [ "$VERBOSE" == "true" ]; then   
                notify-send "Canceling Screenshot"
            fi
            quit
        fi
    done;
}

function quit {
    killall -9 xinput
    exit
}

if [ "$VERBOSE" == "true" ]; then
    notify-send "Screenshot script waiting. Press Meta + R to capture the screenshot"
fi
IFS=$'\n'
for i in $KEYBOARDS
do
    unbuffer xinput test "$i" | run & 
done
Run Code Online (Sandbox Code Playgroud)

在您实际使用脚本之前(在 ubuntu 上),您需要确保您有xinputunbuffer。要做到这一点,只需执行以下操作:

sudo apt-get install xinput expect-dev
Run Code Online (Sandbox Code Playgroud)

然后就可以运行脚本了。首先使用 -h 选项运行它以查看可能的配置选项。默认情况下,脚本只会运行一次,并且您必须在每次屏幕截图后重新启动脚本(例如通过键盘快捷键)。这是因为脚本可能会影响性能。如果您想将它作为“守护进程”运行,请使用该-d选项运行它。

默认情况下,它也会使用快门。如果您想使用其他东西,请使用该-e选项,例如script.sh -c "ksnapshot"

默认情况下,捕获按钮将为Meta+ R。您可以使用配置选项更改它。