1

I am using ubuntu 19.04. in windows i have used autohotkey to make keyboard right alt and ctrl behave as mouse left and right click. But i am unable to do this in ubuntu. I have tried editting /usr/share/X11/xkb/symbols/pc with text editor. I have sucessfuly made ctrl behave like menu key, but unable to make behave like mouse button. I am doing this because my laptop mouse buttons are not working.

3 Answers3

2

For this to work, you need to install the terminal tools xdotool and xcape.

1) First create "normal" hotkeys that emulate the mouse buttons. You can do this in "Settings" - "Devices" - "Keyboard shortcuts". You can use crazy key combinations you otherwise will never use.

At the bottom of the pane, press the "+" button. Provide a name, provide the following command:

xdotool keyup ctrl+alt+shift+z click 1

and assign the shortcut Shift+Ctrl+Alt+z. The keyup part simulates a release of the hotkey that triggers the command, so make sure it matches the hotkey you use.

Continue in a similar way for the right click. This time, the command is

xdotool keyup ctrl+alt+shift+x click 3

which is assigned to Shift+Ctrl+Alt+x.

2) Now use xcape to redirect pressing and releasing modifier keys on their own to one of these commands.

xcape -e 'ISO_Level3_Shift=Shift_L|Control_L|Alt_L|z;Control_R=Shift_L|Control_L|Alt_L|x'" 

What follows after the option -e is the remapping. In this example, the right Alt key is remapped to the hotkey we set up for the left click. After the semi colon ; the right Ctrl key is being remapped to the one for the right click.

Find out the names of your modifier keys using xev | grep keysym (installed by default). Start this tool in the terminal. When you press or release a key, a line is generated containing the name of the key.

3) If it works well, you will want to have the command automatically executed during login. In your .desktop file, insert the command sh -c "sleep 0.3 ; xcape -e 'ISO_Level3_Shift=Shift_L|Control_L|Alt_L|z;Control_R=Shift_L|Control_L|Alt_L|x'" on the Exec= line.

vanadium
  • 88,010
1

I have done this before using both xbindkeys and xmacro

this is basically the same setup as AHK for linux.

create these three files

~/rightclick.macro

ButtonPress 2 Delay 100 ButtonRelease 2

~/leftclick.macro

ButtonPress 1 Delay 100 ButtonRelease 1

~/.xbindkeysrc

#right control mouse click "cat ~/rightclick.macro|xmacroplay :0" Control_R

#right alt mouse click "cat ~/leftclick.macro |xmacroplay :0" Alt_R

now run xbindkeys

if you want this to start as soon as you log in everytime add the xbindkeys command to ~/.xinitrc

you may need to install both xbindkeys and xmacro packages if you haven't already :)

  • Another way to skin a cat. Thank you for sharing. Your approach looks more simple than mine. – vanadium Dec 27 '19 at 09:52
  • thank you, your solution is interesting i havent used xcape before – Radical Edward Dec 27 '19 at 09:58
  • xcape allows to have the action triggered only after releasing the key, so the modifier key can still be used normally in combination with other keys. I guess you can also do that with xbindkeys, appending + release after the key. – vanadium Dec 27 '19 at 10:05
1

If you are still facing the problem, there is a tool called Keymapper. it is a gui tool to easily remap anything from keyboards to joysticks and even touchpad buttons.

IKONIK
  • 29