Windows button in linux

How to Customize Extra Mouse Buttons in Linux

If you are using a mouse, trackball, or touchpad with extra buttons in Windows, chances are the manufacturer has created software to configure the buttons. Rarely do they create such software for Linux. Btnx (button x) can be used to configure the mouse buttons in Linux for a variety of pointing devices.

With a three button mouse, typically people keep the default settings. With a five button mouse, the extra two buttons often go unused. The default is that they typically are used to go back and forward in web browsers and file managers. This is not as handy in other programs. Other functions might be more useful; the user should decided what they need. For example, I would rather use the extra buttons to copy and paste text. Enter btnx.

Using Btnx

To install btnx, search for it in Ubuntu’s Software Center (found in the Application menu). Alternatively, you can install it from the command line.

sudo apt-get install btnx

Now you can access btnx from:

Applications > System Tools > btnx

This will bring up a GUI dialog box for you to configure you mouse. From here, click «Detect mouse & buttons» and follow the steps. It will have you test your mouse and label the buttons. Don’t forget to add your scroll wheel. It is an extra step compared to manufacturers’ software, but it only takes a minute or two. Next, click on the «Buttons» tab to configure what each button does. Usually, it is the extra mouse buttons that are the best to customize, but any can be changed.

In this case, I set the keycode on «Button-1» (named by me) to «C» and the modifier to «Ctrl.» Since this is just a case of simulating «ctrl+c» to copy something, left or right control keys are irrelevant. Naturally, I set the «Button-2» as «ctrl-v» for paste. Page Up & Page Down would also make sense. Options are not limited to key combinations. Programs and other buttons can be set as well. A wide array of functions are available for someone to choose from.

Make sure to click the «Enabled» check box. To apply the changes, restart btnx from the «Configurations» tab. If a change does not seem to be taking place, try restarting btnx or your computer.

Note: The homepage and the help files were not available. For clarification and program details, use the man pages from the Wayback Machine.

Problems and Issues

In tests, while the remapping worked, a curious side effect evolved: the buttons now work as both copy & paste and forward & back. This made them useless in websites. Further research lead to a fix: xinput. The program will let you swap or disable mouse buttons, among other things. It should come with Ubuntu and other types of Linux, but it can be installed from the terminal:

sudo apt-get install xinput

Once installed, you need to use it to list and show devices:

You should see your pointing device listed. Look for your manufacturer’s name. If the name appears twice, then you need to use the «id» number in place of the name. Once you have found this information, you can disable the extra button functionality with the following line:

xinput set-button-map «Your mouse name» 1 2 3 4 5 6 7 0 0

Now, your mouse should work as intended. Btnx will still know you are pressing the buttons, so the remap will still work. If you have problems, try running through «Detect mouse & buttons» again to make sure they were set correctly. Note: You may have to do this each time you customize the buttons.

Closing

It took some time to find the answers, but I now have perfectly functional copy & paste buttons on my trackball. These solutions where found in the forums at ubuntuforums and pinoygeek. With luck, you will not have the problems that I ran into. If you do, I hope this article saves you the trouble of having to research the solution. Please feel free to share how you remap your mouse in the comments.

About Ryan D. Lang

Disabling the Nouveau open-source Nvidia driver to use the proprietary driver in OpenSUSE Leap 15.3

Linux Mint 20.2 is now available

Ubuntu 21.04 is now available with native Microsoft Active Directory integration and Wayland as the default

Microsoft introduces support for Linux GUI apps on Windows 10

Linux Mint will inform users about important security updates but not enforce them

Microsoft Edge 91 will be the first to support syncing on Linux

Comments

Why bother with a five-button input device when there is a far more flexible 104 key input device included with every computer. Are mouse users really that desperate to keep their hands away from the keyboard? What is amusing is that in your example you remap your mouse buttons to common keyboard shortcuts that are within easy reach of your left hand. What have you gained? At least remap them to something harder to type, like performing a Google search from any application on selected text or copying a file to your Dropbox account. That would be much more interesting and useful, and might make the mouse a less useless space waster.

Читайте также:  Редактор кода кали линукс

Why use two keys when one button will do?

A better argument would be: “Why do this remap in Linux when you can just select text and middle click to paste without copying?” This remap actually is a work-around for when the Linux trick fails in certain rare instances.

When selecting text, I sometimes (not always) find it faster to use a mouse (esp. if you double click, holding the second click). This is especially true for webpages.

That said, I actually prefer the keyboard. I believe in learning as many keyboard shortcuts as possible; they are faster that a GUI typically. As a draftsman, I needed both. To enter commands, I used the keyboard; the select objects, I used the trackball. I wish I had extra buttons on that trackball. I would have found uses for them.

A better argument still is “Why move your hand to the mouse when keeping it on the keyboard saves time?” Dedicating mouse buttons to work around a rare problem just means you will rarely benefit by using them. And a single mouse button press still takes more time than pressing two keys on the keyboard since to do so you have to move your hand to and from the mouse. Of course, if your hand lives there already, that isn’t a problem. Web browsers typically encourage that, but if you are going to spend time and energy moving your hand to the mouse, or reprogramming its buttons, you should get a bigger return on that investment than you get from a simple copy and paste. That’s why I suggested a more complex action be associated with them. That way, even though you move your hand away from the keyboard, the extra time it takes for that is made up for by the complexity of the operation it initiates.

On a slightly different tangent, the web browser interface is a problem for keyboard users. Web browsers are notoriously mouse-centric, and needlessly so. They are not designed for editing or composing text, so it makes no sense for browser designers to virtually ignore the entire keyboard and focus almost exclusively on the mouse for user interaction. It’s as if they think typing text is the only thing a keyboard is good for. Vimperator and Pentadactyl help with that. They have figured out how to handle text imput when needed, but you must be familiar with vi or Vim to take advantage of them. Perhaps someone will develop a similar add-on that emulates WordStar for those who prefer it. (I’m surprised that hasn’t happened.) It is rather handy, though, to be able to use the keyboard to navigate within a web page, select text, and paste it somewhere else without the damned mouse insinuating itself into your work flow. Not to mention link navigation and tab switching by keyboard.

Now, it would be awesome if we could get the keys to change what they do based on the application the mouse is currently focused on. I have a Logitech MX Performance Mouse and on windows, the logitech software allows me to set different tasks for the buttons depending on which application was in focus. So, in a browser, the forward/back buttons were forward and back but when I was in eclipse or in vim, I changed the back/forward buttons to do vim jumps ( and ) and eclipse jumps in eclipse.

oops, I guess you can’t edit posts. But it was supposed to be vim jumps (c-o and c-i) but I had angle brackets and it ate them.

Источник

Using Windows Keyboard Media Buttons In Linux

A lot of people making the move from Windows to Linux have a Windows keyboard with extra buttons along the top. Some of these buttons control the browser, while others control audio/video playback. As many have already discovered, these buttons don’t work in Linux. At least, they don’t by default.

The problem with these buttons is that, while they communicate with the computer via keycodes like the regular keys, these codes aren’t standard ASCII. For example, the Microsoft Natural Keyboard Pro uses two keycodes for each button press. The first code is a flag to indicate that the next one will identify which button was pressed.

Читайте также:  Using windows native api

The process I’m going to describe is taken from KDE version 3.2. Versions prior to that lack the interface to KHotKeys that the latest one has.

Identify Your Keyboard to KDE

The first step is to make sure your keyboard is properly identified to KDE. Go to the KDE Control Center — you’ll find it listed in the «KMenu» (click the icon where the «start» button would be in Windows). Once the Control Center is up and running, click the «Regional & Accessibility» (or similar — it may be called «Accessibility» in other Linux distributions — Mandrake, for example) icon in the left-hand panel, the contents of which will change. From this new list, select «Keyboard Layout». Now on the right-hand panel, go to the «Layout» tab, and make sure the «Enable keyboard layouts» check box is checked. Pull-down the «Keyboard model» combo list box, and select your keyboard. It may originally say something like «Generic 101-key PC». You’ll find a lot of keyboards listed, from a lot of manufacturers, so hopefully yours will be in there. In my case, I selected «Microsoft Natural Keyboard Pro / Microsoft Internet Keyboard Pro».

Now comes the fun part. With your keyboard properly identified, KDE will now recognize those extra keyboard buttons when you press them. All you have to do is tell it how to translate them into the proper action. The technique I’m going to show you involves a KDE program called «KHotKeys». Some people recommend that an action like changing the audio volume is more properly done using the program «KMix» (a sound mixer). Unfortunately, this didn’t work in my case. Every time I raised and lowered the master volume in KMix, instead of controlling the volume on my Sound Blaster Live card, it made funky changes to the tone. YMMV. If KMix works fine for you, then use it for volume control. The other reason I did it my way, and ignored those recommendations, is that I wanted all of my changes in one place.

KHotKeys

You currently have «Keyboard Layout» selected in the KDE Control Center list on the left-hand side of the screen. Move the mouse to «KHotKeys» at the bottom of the list. If this isn’t anywhere in the list, make sure you are using KDE 3.2 or later (the version of KDE you’re running will appear in the right-hand panel of the Control Center when you first open it up). Click on «KHotKeys», and the right-hand panel will contain the KHotKeys configuration screen.

KHotKeys is a powerful program that allows you to define actions corresponding to certain keystrokes. It also allows you to assign actions to mouse gestures. We’re interested, however, in how to assign an action to a keypress — and, by extension, to the press of one of those media buttons.

Running a Program

We’ll do something simple first. Many keyboards have a button marked «Mail». We’re going to define an action for that button so that it launches Mozilla’s email module. First, click the button marked «New Action» at the bottom of the config screen. Under «Action Name» in the «General» tab, replace «New Action» with something easy to remember, like «Mail». Pull-down the «Action Type» list box, and select «Keyboard Shortcut -> Command/URL (simple)». Make sure the «Disable» checkbox is empty. Enter anything you want in the «Comment» box. Go to the «Keyboard Shortcut» tab, and click the mouse in the tab’s only button. You’ll see a dialog box. Press the «Mail» button on the keyboard, and the dialog box goes away. With my keyboard, this results in the button displaying «XF86Mail». Go to the «Command/URL Settings» tab. Enter the command line to be executed, including the full path, and any arguments. To run the mail module of Mozilla 1.6 on my machine, I used the following command:

Depending on what program (or shell script) you’re running, the command could be more or less complicated than this. If I just wanted to run the Mozilla browser (for the «Web/Home» button, for instance), I would have used:

Using DCOP to Control a Running Program

DCOP, or Desktop Communications Protocol, is a generic way for applications to communicate with one another. You have seen this sort of thing in Windows, which uses a technology called OLE Automation (a part of «COM», or «Common Object Model»). DCOP is the method we will use to send commands to an already-running program.

From the «General» tab of KHotKeys, create a new action, and set the «Action Type» to «Keyboard Shortcut -> DCOP Call (simple)». From the «Keyboard Shortcut» tab, identify the button you want to use, just as you did with the previous example. Next, the «DCOP Call Settings» tab may seem a bit confusing if you’ve never worked with DCOP before. At the bottom of the tab is a button labeled «Run KDCOP». Kdcop is a GUI application that allows you to browse the callable functions exposed by all running DCOP applications in a standard tree view. Click the button to start kdcop. Start the program you want to control, locate its name in kdcop, and click the plus sign icon next to the name to expand it.

Читайте также:  Как раздать wifi с ноутбука windows 10 без роутера

For this example, I’m going to use Jukebox (or «Juk»), an audio player that comes with many Linux distributions. When you expand the entry «juk» in kdcop, you see five entries. For this example, we want the one named «Player». Expanding this «Player» node, we see a long list of supported function calls. Now all we have to do is find the things we want to control. Let’s say we want the button to start juk playing music. Scroll down the list until you see «void play()». That looks like programmer stuff, doesn’t it? Don’t worry, you don’t have to know what it all means to make use of it. It’s easy.

Copy the top tree entry (in this case, type «juk») into the «Remote application» box. Then, copy the next node entry in the tree (in this case, type «Player») into the «Remote object» box. Finally, copy the command, without the «void», or the parenthesis (in this case, type «play») into the «Called function» box. Note that all of these are case-sensitive.

Both kdcop and the KDE Control Center support drag-and-drop, so you could also click and drag «void play()» to the KHotKeys window, and drop it on any of the edit boxes. This results in «dcop juk Player play » (note the trailing space) being pasted into the edit box. This is an easy way to get the three entries you need for the «DCOP Call Settings» tab. In this example, type «juk» into the «Remote application» box, «Player» into the «Remote object» box, and «play» into the «Called function» box. Now, if you did this the way I did, and dropped everything into «Called function», deleting everything up to the word «play», then you made the same mistake I made as well. For some reason, the system adds a space to the end of the text, so the system looks for a command called «play » instead of «play», and the button won’t work. Using drag-and-drop here is more trouble than it’s worth, in my opinion. It would be nice if you could just drop the entry onto the tab, and have it populate all the fields for you, but that’s not how it works right now.

Translating a Button into a Standard Keypress

If the application you’re trying to control doesn’t support DCOP, then you have to simulate the pressing of a specific key combination on a button press. For example, if you’re using Mozilla 1.6, you can’t use the DCOP method to control the browser. Fortunately, you can convert a button into a standard keypress that Mozilla understands. Once you have created a New Action for KHotKeys, select an «Action Type» of «Keyboard Shortcut -> Keyboard Input (simple)» from the pull-down list box in the «General» tab. From the «Keyboard Shortcut» tab, identify the button you want to use, just as you did with the examples above. On the «Keyboard Input Settings» tab, enter the keystrokes you want the button translated to. Special keys have to be spelled out. For example, to display your Home Page in Mozilla 1.6, you hold down the «Alt» key, while pressing the «Home» key. You type this into the «Keyboard input» field as (without the quotation marks, and without any spaces): «Alt+Home». Warning: this button-to-key translation doesn’t care what application you’re in. Think about what you’re doing before you assign the keyboard input to avoid unexpected results. Note that this isn’t limited to one keystroke. You could use «Hello World» if you wanted to.

Tom has been a software developer since the early days of the Commodore 64, with such commercial classics as Prototerm-64 and Colorez-128, and has seen lots of operating systems come and go. Every one he’s liked is either discontinued (OS/2) or out of business (Commodore Amiga). He currently likes Red Hat Linux, which won’t be supported after April ’04. As a result, we’ve been trying to get him to fall in love with Windows, but so far no luck.

Copyright © 2004, Tom Brown. Released under the Open Publication license unless otherwise noted in the body of the article. Linux Gazette is not produced, sponsored, or endorsed by its prior host, SSC, Inc.

Published in Issue 104 of Linux Gazette, July 2004

Источник

Оцените статью