Use single keyboard shortcut for Term and Apps in Awesome

Requirements

  • sxhkd
  • xdotool
  • awk
  • xvkbd
  • urxvt (perl script)

Concepts

Use sxhkd to listen to a specific key combination sequence that does not conflict with any other key combinations(in every environment). Use shell script to obtain the current window name and compare it against a list. To substitute the used key combination with the actual one.

Configuration

The configuration has three parts ## Shell script

#!/bin/sh

curwin=$(ps -e | grep $(xdotool getwindowpid $(xdotool getwindowfocus)) | grep -v grep | awk '{print $4}');
if [ $curwin == "urxvt" ]; then
  xvkbd -xsendevent -text "\C\A${1}" #"\{Super_L}${1}"
else 
  xvkbd -xsendevent -text "\C${1}"
fi

sxhkd

super + c
  swapkey.sh c

super + v
  swapkey.sh v

URxvt

URxvt.keysym.Control-Mod4-c: perl:clipboard:copy
URxvt.keysym.Control-Mod4-v: perl:clipboard:paste