Forum

> > Off Topic > Remapping Single Key to Mouse Button in Linux
ForenübersichtOff Topic-ÜbersichtEinloggen, um zu antworten

Englisch Remapping Single Key to Mouse Button in Linux

3 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Remapping Single Key to Mouse Button in Linux

MikuAuahDark
User Off Offline

Zitieren
TL;DR: Is there a way to somehow remap single key to mouse down and mouse up?

I want to use "Z" as my mouse click button (holding "Z" means holding mouse click) but I want it only if there are no key modifies, so Ctrl+Z is passed as-is, but "Z" alone acts as mouse click.

Background: I'm currently learning digital drawing. Since I don't have drawing tablet, I have no choice other than using mouse for movement. I'm using Krita for this and sadly adding keyboard shortcut to "Activate" it in Krita setting doesn't work (because it never meant for that). A solution would be using AutoHotkey which works in Windows like this:
1
2
3
4
5
6
7
8
#IfWinActive ahk_exe krita.exe
z::
	Click down
	Keywait z
	Click up
	return

#IfWinActive
However, I'm slowly moving my stuff from Windows to Arch Linux, so I can't use AutoHotkey. The equivalent, AutoKey sounds interesting but it lacks exactly feature that I want. I'm considering creating one myself using Xlib API (or XTEST) but I'm absolutely clueless on how to use the API to achieve what I want.

If anyone knows please let me know below or hit me up in UnrealSoftware Discord server at #off-topic channel, thanks.

EDIT: I've solved it. I had to write C++ code that interacts with X directly. See https://gist.github.com/MikuAuahDark/3e1a5b3946d8700e1a26769cc0f8e554
1× editiert, zuletzt 08.09.20 04:55:44

alt Re: Remapping Single Key to Mouse Button in Linux

VADemon
User Off Offline

Zitieren
Look towards defining a "custom keyboard layout". Maybe it's possible there (should be?..)
I did that, it's basically copying the existing config and refining the key mappings to fit your style. I did it to enhance en-US layout with German letters. It's a bit much to figure it out the first time (quite a few places (files) to touch), but not hard if you follow the guides.

alt Re: Remapping Single Key to Mouse Button in Linux

MikuAuahDark
User Off Offline

Zitieren
@user Cebra: I looked at xbindkeys and it looks like there's no way to do something like this
1
2
3
4
5
1. Check if "Z" is pressed down
2. If it was previously pressed down (handling key repeat), stop
3. Press left mouse button (easy with `xdotool mousedown 1`)
4. Wait until "Z" is released
5. Release left mouse button (`xdotool mouseup 1`)
The steps above must be done sequentally, and I can't find if that's possible to use xbindkeys for that.

@user VADemon: Custom keyboard layout sounds too overkill for me. I don't want it applies to all users, but just myself, and only to specific application (Krita in this case).
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antwortenOff Topic-ÜbersichtForenübersicht