How to define pressing Ctrl twice as a keyboard shortcut in Linux (to launch a command)

Alice

Is it possible to launch a command by pressing Ctrl twice? Is there any AHK-like program available in Linux which can do this?

meuh

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to launch an application with a keyboard shortcut?

From Dev

How to add keyboard shortcut to launch terminal program?

From Dev

How to define keyboard shortcut to suspend Xubuntu 12.04?

From Dev

How to define keyboard shortcut to suspend Xubuntu 12.04?

From Dev

What is the function of the keyboard shortcut Ctrl+Y under Linux?

From Dev

How to create a keyboard shortcut for a terminal command

From Dev

How to execute a Ctrl+,,f keyboard shortcut in Sublime Text?

From Dev

How to change keyboard layout shortcut to ctrl+shift on Debian 9?

From Dev

How to make desktop icon for keyboard shortcut (linux)

From Dev

Keyboard shortcut for ls command?

From Dev

How to define a keyboard shortcut for building the default project in VC++ IDE?

From Dev

How can I define a keyboard shortcut for inserting a multilevel list in Word?

From Dev

How to define a custom screenshot in Gnome 3 and to assign it to a keyboard shortcut?

From Dev

How do I define a file context options keyboard shortcut?

From Dev

Let user define keyboard shortcut

From Dev

How to "debug" a keyboard in Linux? Like pressing a key and seeing a code in a terminal

From Dev

Define keyboard shortcut to a series of keyboard shotcuts

From Dev

Launch file manager from terminal with a keyboard shortcut

From Dev

Ubuntu Keyboard shortcut to launch terminal is very slow

From Dev

Is it possible to configure (really) global keyboard shortcut in Linux (like ctrl+alt+fN)?

From Dev

In zsh how do I bind a keyboard shortcut to run the last command?

From Dev

How can I open a command prompt in current folder with a keyboard shortcut?

From Dev

In zsh how do I bind a keyboard shortcut to run the last command?

From Dev

How to fix ctrl space shortcut for my IDE using Linux Mint?

From Dev

How to disable Ctrl+Q shortcut in Firefox on Linux

From Dev

Disable ctrl-b keyboard shortcut in Firefox?

From Dev

What is the keyboard shortcut opposite to Ctrl+k?

From Dev

Delay when using ctrl + s keyboard shortcut

From Dev

Setting a keyboard shortcut for a vim command

Related Related

  1. 1

    How to launch an application with a keyboard shortcut?

  2. 2

    How to add keyboard shortcut to launch terminal program?

  3. 3

    How to define keyboard shortcut to suspend Xubuntu 12.04?

  4. 4

    How to define keyboard shortcut to suspend Xubuntu 12.04?

  5. 5

    What is the function of the keyboard shortcut Ctrl+Y under Linux?

  6. 6

    How to create a keyboard shortcut for a terminal command

  7. 7

    How to execute a Ctrl+,,f keyboard shortcut in Sublime Text?

  8. 8

    How to change keyboard layout shortcut to ctrl+shift on Debian 9?

  9. 9

    How to make desktop icon for keyboard shortcut (linux)

  10. 10

    Keyboard shortcut for ls command?

  11. 11

    How to define a keyboard shortcut for building the default project in VC++ IDE?

  12. 12

    How can I define a keyboard shortcut for inserting a multilevel list in Word?

  13. 13

    How to define a custom screenshot in Gnome 3 and to assign it to a keyboard shortcut?

  14. 14

    How do I define a file context options keyboard shortcut?

  15. 15

    Let user define keyboard shortcut

  16. 16

    How to "debug" a keyboard in Linux? Like pressing a key and seeing a code in a terminal

  17. 17

    Define keyboard shortcut to a series of keyboard shotcuts

  18. 18

    Launch file manager from terminal with a keyboard shortcut

  19. 19

    Ubuntu Keyboard shortcut to launch terminal is very slow

  20. 20

    Is it possible to configure (really) global keyboard shortcut in Linux (like ctrl+alt+fN)?

  21. 21

    In zsh how do I bind a keyboard shortcut to run the last command?

  22. 22

    How can I open a command prompt in current folder with a keyboard shortcut?

  23. 23

    In zsh how do I bind a keyboard shortcut to run the last command?

  24. 24

    How to fix ctrl space shortcut for my IDE using Linux Mint?

  25. 25

    How to disable Ctrl+Q shortcut in Firefox on Linux

  26. 26

    Disable ctrl-b keyboard shortcut in Firefox?

  27. 27

    What is the keyboard shortcut opposite to Ctrl+k?

  28. 28

    Delay when using ctrl + s keyboard shortcut

  29. 29

    Setting a keyboard shortcut for a vim command

HotTag

Archive