Is it possible to launch a command by pressing Ctrl twice? Is there any AHK-like program available in Linux which can do this?
Assuming you are using X11 (and not Wayland), there are many tools to "spy" on the keyboard events. One example is cnee. If run with
cnee --record --keyboard
when you press a key, such as Control_Right, you will get output such as
6,2,0,0,0,105,0,299533174,3,Virtual core keyboard
which has fields giving details about the event including if up or down (2), the keycode (105 in my case), and the time of the event in milliseconds (299533174). A simple script can look for two successive down events for the same keycode that occur in, say, less than 500 milliseconds, and run some command. For example,
cnee --record --keyboard 2>/dev/null |
awk -F, -v wanted=105 '$1==7{
down = ($2==2); keycode = $6; tod = $8;
if(keycode==wanted){
if(down){
diff = tod-last
if(diff>500){ last = tod; next } # note time of first press
else{
#printf "%s %s %d\n",down?"down":"up",keycode,diff
system("echo hello")
}
}else next
}
last = 0
}'
Note, you will need to change the wanted=105
value to the appropriate keycode, and the $1==7
to match your keyboard's index.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments