7

I am trying to emulate left-mouse-down when Home key is down and left-mouse-up when Home key is released.

The reason behind that is my touchpad's buttons are terrible and I like to use the track-point (red nipple) with left mouse click for highlight (copy) text. Instead of using the touchpad's button I want to use the 'Home' key. I am able to emulate the mouse-down part but I don't know how to release the click when the 'Home' key is released.

Here is what I have so for. first I use the xbindkeys tool. I added this entry to the .xbindkeysrc:

"~/bin/mouse-click"
  m:0x0 + c:110

mouse-click is this bash script:

#!/bin/bash
xdotool mousedown 1

The problem is the click is never being released so I need to find a way to detect the release of the 'Home'. Here is the script I am trying to write. The comments describe what I am trying to do:

#!/bin/bash

# not sure how to do that:
exit if Home key is in a pressed state (to avoid more mousedown actions)

xdotool mousedown 1

# not sure how to do that: (if Home key is released, release the mouse click)
while xinput query-state <device name> | grep -Flq 'key[9]=up'
xdotool mouseup 1

So That's what I am trying to figure out:

  1. Query the state of 'Home' key (pressed or not).
  2. Listen to keyboard events and detect a release of 'Home' key.

If there are better approach to achieve that, I would love to hear about them. Thanks!

Edit: the solution is one line: xmodmap -e "keycode 115 = Pointer_Button2"
so now my Home key is doing left click and behave just as if I hit the mouse click and I can keep the key pressed and it highlights (copy) as expected.

I also mapped my End key to be middle click, so I can use it to paste: xmodmap -e "keycode 110 = Pointer_Button1"

user3538541
  • 153
  • 1
  • 8

3 Answers3

4

The solution is

xmodmap -e "keycode 115 = Pointer_Button2"

Now my Home key is doing left click and behaves just as if I hit the mouse click and I can keep the key pressed and it highlights (copies) as expected.

I also mapped my End key to be middle click, so I can use it to paste:

xmodmap -e "keycode 110 = Pointer_Button1"

Note that it is necessary to have "mousekeys" (mouse emulation using the numeric keypad) enabled for this to work. "mousekeys" can be toggled by pressing Shift+NumLock or set explicitly by running:

dconf write /org/gnome/desktop/a11y/keyboard/mousekeys-enable true
dconf write /org/gnome/desktop/a11y/keyboard/mousekeys-enable false
user3538541
  • 153
  • 1
  • 8
  • from some reason after hibernate and also restart it's the end and home keys still behave as end and home. xmodmap -e "keycode 115 = Pointer_Button2" doesn't do anything. any ideas? – user3538541 Nov 26 '14 at 08:35
  • i figure it out. i had to install xkbset and run 'xkbset m'. not sure if the last one is needed. – user3538541 Nov 26 '14 at 09:01
3

Most desktops have some accessibility settings that will control the mouse with the keyboard already built-in, like XFCE has them in it's All Settings -> Accessibility -> Mouse -> Mouse Emulation, that uses the keyboard number pad so the 5 key does exactly what you're trying to do.

If I recall, gnome, cinnamon and mate have similar features under something like "Accessibility" or assistive technology, etc. Or an installable program/package like mousetweaks ("mouse accessibility enhancements for the GNOME desktop") or keynav (but I couldn't get it to work on xfce).

Or, if your touchpad still works ok (just not the buttons) you could just do a tap for a single click, a tap & then hold for a click & drag, a double-tap = double click... and if they don't work there should be a line or two in the terminal that should get those to work (don't remember them offhand now). I wouldn't want to write my own script when there are a few other options that should work

Xen2050
  • 8,705
0

You should use for that an auto clicker program that emulate and automate your mouse clicks (left mouse button in your case).

I recommend for you to use Max Auto Clicker that is available for Ubuntu Linux and other debian like distros.

Available packages format: .deb, .AppImage, .zip

Alexif_47
  • 157
  • 3