프로그램이 실행 중일 때 키 비활성화

프로그램이 실행 중일 때 키 비활성화

다음 대상에 질문이 중복됩니다.특정 프로그램이 실행되는 동안 키를 비활성화하는 방법은 무엇입니까?, 답변이 없습니다. (같은 질문을 다시 게시하는 것, 아니면 이전 게시물을 necro로 스레드하는 것 중 어떤 옵션이 더 나쁩니까?)

그런데 특정 프로그램이 실행 중일 때 특정 키를 비활성화하는 방법이 있나요? 아니면 특정 프로그램이 실행 중일 때 Dash를 비활성화하시겠습니까?

답변1

간단한 솔루션

두 개의 바로가기를 만듭니다. 하나는 Super키를 비활성화하기 위한 것이고 다른 하나는 원하는 대로 복원하기 위한 것입니다.

시스템 설정 -> 키보드 -> 단축키 -> 사용자 정의로 이동하여 +버튼을 클릭하세요. 새 단축키의 이름을 "대시 비활성화"로 지정합니다. 명령은

 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 '<Super>'

스크립팅 솔루션

아래 스크립트는 Super사용자가 지정한 프로그램에 포커스가 있을 때 키를 비활성화합니다. 사용자는 여전히 대시를 호출하기 위해 마우스로 대시 아이콘을 클릭할 수 있습니다. 프로그램 이름은 작은따옴표로 묶어야 하며 Unity Launcher에 표시되는 것과 정확히 동일해야 합니다. 여러 창을 공백으로 구분하여 동일한 형식으로 지정할 수 있습니다.

여기에 이미지 설명을 입력하세요

예를 들어, Firefox 창에 포커스가 있을 때마다 슈퍼 키를 비활성화하려면 스크립트를 다음과 같이 호출해야 합니다.

disable_super_key.sh 'Firefox Web Browser'

둘 다 비활성화 firefox하고 gnome-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: [email protected] 
# 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 '<Super>'
}

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 "$@"

관련 정보