6

I know how to map mouse click for F1, F2 and F3 (respectively left click, middle click, right click):

xkbset m   # required, but disable keypad
xmodmap -e "keycode 67 = Pointer_Button1 Pointer_Button1"
xmodmap -e "keycode 68 = Pointer_Button2"
xmodmap -e "keycode 69 = Pointer_Button3"

But this requires me to use xkbset m that use the slow keys mode :

If I press 4 from the keypad, it moves the cursor to the left. I don't need this feature, just the mapping above.

I tried to figure it out with xdotool, but I don't know how to handle key pressed/key released (for drag & drop) with

xdotool mousedown 1
xdotool mouseup 1

How can I not use this mode or how can I remap all keypad keys ?

What about the numeric and arithmetic signs from keypad please ?

Is there another solution ?

For information, needed for Debian (cinnamon) and Archlinux (xfce), and if possible, I would like a solution not based on the window manager.

EDIT:

Tried this solution but I can't drag and drop with F1.

In ~/.xbindkeysrc :

"xdotool mousedown 1"
    F1
"xdotool mouseup 1"
    F1 + Release

Or :

"xdotool mousedown 1"
    m:0x10 + c:67
"xdotool mouseup 1"
    m:0x10 + c:67 + Release

Then :

xset -r 67

EDIT2

Tried with actkbd

# actkbd configuration file
<keycode ("67")> :key : :xdotool mousedown 1
<keycode ("67")> :rel : :xdotool mouseup 1

No cigar :/

Adapted from here

  • Does xdotool do what you need? – joat Jan 30 at 11:59
  • The problem with xdotool is the key pressed, like drag and drop with left click. If you found a solution that is working with xdotool and drag&drop, I will accept it – Mévatlavé Kraspek Jan 30 at 12:23
  • Added solution that is not working for me with xdotool and xbindkeys – Mévatlavé Kraspek Jan 30 at 17:29
  • Added actkbd way with no luck :/ – Mévatlavé Kraspek Jan 31 at 16:42
3

W00T !

First : create a script click:

#!/bin/bash

id=$(
    xinput list |
        awk '/Dell USB Keyboard/{print gensub(/.*id=([0-9]+).*/, "\\1", "1")}'
)
xdotool mousedown $1
while IFS= read -r event; do
    if [[ $event == *release* ]]; then
        xdotool mouseup $1
        exit
    fi
done < <(xinput test $id)

Then add a new keyboard shortcut in your window manager and map F1 to run /path/to/mouse <1|3> (left OR right click).

Et voilà ;)

This can be ran with xbindkeys to be WM agnostic

Edit:

don't know why this doesn't work with archlinux + xfce 4.12 but on Debian9 + Cinnamon

Edit :

This solution works better :

In .bashrc :

xmodmap -e "keycode 67 = Pointer_Button1 Pointer_Button1"
xmodmap -e "keycode 68 = Pointer_Button2"
xmodmap -e "keycode 69 = Pointer_Button3"

As a keyboard shortcut :

#!/bin/bash

id=$(
    xinput list |
        awk '/Dell USB Keyboard/{print gensub(/.*id=([0-9]+).*/, "\\1", "1")}'
)


(
    while read event; do
        if [[ $event == *release* ]]; then
            xkbset -m
            exit
        fi
    done < <(xinput test $id)
) &
xkbset m
  • I think xkbset m is useless here. xdotool doesn't need it. – L. Levrel Feb 4 at 15:59
  • Fixed some minor bugs – Mévatlavé Kraspek Feb 4 at 16:21
0

You can implement a "mouse toggle" action with this command in .xbindkeysrc (there is a typo in your first edit, it is not .xbindkeys):

"if [ ! -e /tmp/mouse_token ] ; then touch /tmp/mouse_token ; xdotool mousedown 1 ; else rm -f /tmp/mouse_token ; xdotool mouseup 1 ; fi"
some_key

It will create an empty file /tmp/mouse_token to keep track of the mouse button state. For some_key you may use F1, which means you will have to press it twice to get a single click, or use another key (e.g. F4).

Note: on my system, for an unknown reason, the press event for F keys does not trigger the xbindkeys binding, only the release event does. If the same happens on yours, use release+F1 for some_key.

Note2: by default xbindkeys does not check NumLock, so you can drop the m:0x10 modifier if you did not set keystate_numlock = enable in the rc file.

  • I already have a solution like this, but I would like to be able to really have a F1 key like left click, with the same behavior. Because I need F1 to do simple clicks and drag and drop with the same key. Moreover, the solution doesn't work – Mévatlavé Kraspek Feb 4 at 12:08
  • @MévatlavéKraspek OK, I understand. I also want to make clear that I tested my solution and it does work on my system (in case that's why you downvoted). – L. Levrel Feb 4 at 12:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.