程序运行时禁用密钥

重复问题如何在特定程序运行时禁用密钥? ,从未回答过。 (哪个选项更糟糕的是,我重新发布了同样的问题,或者我将旧post发送给死者?)

无论如何,有没有办法在特定程序运行时禁用特定键? 或者,在特定程序运行时禁用Dash?

简单解决方案

创建两个快捷方式,一个用于禁用超级密钥,另一个用于随意恢复。

转到系统设置 – >键盘 – >快捷方式 – >自定义,然后单击+按钮。 将新快捷方式命名为“Disable Dash”。 命令是

gsettings set org.compiz.unityshell:/org/compiz/profiles/unity/plugins/unityshell/ show-launcher 'Disabled' 

要创建重新启用脚本的快捷方式,请重复上述步骤,但命令应该是

  gsettings set org.compiz.unityshell:/org/compiz/profiles/unity/plugins/unityshell/ show-launcher '' 

脚本解决方案

当用户指定的程序具有焦点时,下面的脚本将禁用超级键。 请注意,用户仍然可以使用鼠标单击短划线图标来调用Dash。 程序名称必须是单引号,并且与Unity Launcher中显示的完全相同。 可以使用以空格分隔的相同格式指定多个窗口

在此处输入图像描述

例如,要在每次firefox窗口都有焦点时禁用超级密钥,必须将脚本调用为

 disable_super_key.sh 'Firefox Web Browser' 

要同时禁用firefoxgnome-terminal

 disable_super_key.sh 'Firefox Web Browser' 'Terminal' 

如何获取脚本

用户可以在此处复制源代码,也可以按照以下说明从github获取源代码:

  1. sudo apt-get install git
  2. cd /opt ; sudo git clone https://github.com/SergKolo/sergrep.git
  3. sudo chmod -R +x sergrep

该脚本将位于/opt/sergrep/disable_super_key.sh

要使脚本在每次登录时自动启动,请参阅如何在登录时自动启动应用程序? 。 提供/opt/sergrep/disable_super_key.sh (完整路径)作为命令

脚本来源

 #!/usr/bin/env bash # ########################################################### # Author: Serg Kolo , contact: 1047481448@qq.com # Date: April 12 , 2016 # Purpose: Disable super key that brings up Unity Dash # per specific application # # Written for: https://askubuntu.com/q/754884/295286 # Tested on: Ubuntu 14.04 LTS ########################################################### # Copyright: Serg Kolo , 2016 # # Permission to use, copy, modify, and distribute this software is hereby granted # without fee, provided that the copyright notice above and this permission statement # appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. ARGV0="$0" ARGC=$# enable_dash_key() { gsettings set org.compiz.unityshell:/org/compiz/profiles/unity/plugins/unityshell/ show-launcher '' } disable_dash_key() { gsettings set org.compiz.unityshell:/org/compiz/profiles/unity/plugins/unityshell/ show-launcher 'Disabled' } get_active_app() { qdbus org.ayatana.bamf \ /org/ayatana/bamf/matcher \ org.ayatana.bamf.matcher.ActiveApplication } get_active_app_name() { qdbus org.ayatana.bamf \ $(get_active_app) \ org.ayatana.bamf.view.Name } check_active_app() { active_name=$(get_active_app_name) local is_found for win in "${windows_list[@]}" do if [ "$active_name" = "$win" ] ; then is_found=true break else is_found=false fi done if $is_found ; then disable_dash_key else enable_dash_key fi } print_usage() { cat << EOF Copyright Serg Kolo , 2016 Usage: disable_super_key.sh 'App Name 1' [ 'App Name 2' 'App Name 3' ... ] The script disables the Super key for the specified set of applications under Ubuntu's Unity environment. The list of windows must be space separated, each app name single quoted and exactly as it appears on the launcher (or as it appears in the .desktop file of that app), so spelling and spacing matter. Note that the script only disables the Super key as shortcut for Dash. The user still will be able to invoke Dash by manually clicking on the Ubuntu icon in the launcher EOF } main() { if [ $ARGC -eq 0 ]; then print_usage exit fi local windows_list windows_list=( "$@" ) dbus-monitor --profile "type='signal',member='FocusedWindowChanged'" |\ while read line do case "$line" in *FocusedWindowChanged*) check_active_app ;; esac done } main "$@"