Saturday, April 27, 2024
 Popular · Latest · Hot · Upcoming
11
rated 0 times [  11] [ 0]  / answers: 1 / hits: 5795  / 2 Years ago, fri, december 24, 2021, 8:45:37

How can I attach a middle button press to a specific key in my laptop?
I can do middle-button if I tap on the top right corner of the touchpad, but I would like to associate it to a key, like the "windows" key or the "menu" key.



Is there a way to do that?



The current answer doesn't work for Ubuntu 11.10 with a classic gnome-failsafe desktop. I would need someone to figure out how can this be done for the updated Ubuntu version.


More From » keyboard

 Answers
4

To remap the menu key you will need to-do the following.



install prerequisites



Install package xkbset:



sudo apt-get install xkbset


define keyboard layout



Next you need to define what keyboard layout you are using. In my case gb for a british/united kingdom keyboard layout or us for United States



setxkbmap -layout gb


Note: if you run



setxkbmap -query


it will give you the output as follows - if the model and layout is your keyboard then you are using the correct layout



rules:      evdev
model: pc105
layout: gb


Next define that we will be next mapping mouse keys:



xkbset m
xkbset exp =m


find Menu key-code



Map the Menu key. To do this we need the Menu key-code. In a terminal run xev, move your mouse inside the square and press the Menu key.



enter image description here



End Result



In my case my Menu key-code is the value 135 and this will be mapped to Mouse Button 2



xmodmap -e "keycode 135 = Pointer_Button2"


Tested as follows:




  1. Copy some text in a terminal - Paste action initiated

  2. Hover mouse over title bar - Window move to background






Putting this all together:



Ok, once we've worked out the correct keycodes, we can put this together to start from login.



First create a file in your home folder called remapkeys



gedit ~/remapkeys


now copy and paste the following



#!/bin/sh
setxkbmap -layout gb
xkbset m
xkbset exp =m
xmodmap -e "keycode 135 = Pointer_Button2"


Save. Give the file execute rights



chmod +x ~/remapkeys


Then from Dash search for Startup Applications or if using Gnome Classic - Applications - Other - Startup Applications



Add a new Startup Applications entry



enter image description here



The command should be:



bash -c "sleep 5 && ~/remapkeys"


The command sleeps for 5 seconds to allow your desktop to appear before running your new script - if your desktop doesnt appear within 5 seconds (maybe you are using a slow netbook?) then increase this timeout to 10 or 15 seconds.
Logout and login to test.


[#44977] Saturday, December 25, 2021, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
losbu

Total Points: 71
Total Questions: 124
Total Answers: 106

Location: Honduras
Member since Sat, Jul 24, 2021
3 Years ago
losbu questions
Mon, Jan 31, 22, 21:41, 2 Years ago
Tue, Nov 22, 22, 01:27, 1 Year ago
Wed, Jan 25, 23, 00:28, 1 Year ago
Wed, May 11, 22, 08:41, 2 Years ago
;